date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,685,040,610,000
While trying to learn about how ld-2.17.so works to change the permission of chmod executable itself, and thought if i can change the permission of ld-2.17.so itself. I ran chmod 666 ld-2.17.so in a test centos 7 machine and after it I can't run any command since most of the commands use ld-2.17.so. I have already read this answer, Recovering from removing execute permission from ld-linux.so It gives a very general answer but not a specific solution. Is there anywhere in Centos7 i can find ld-2.17.so cache to recover /lib64/ld-2.17.so permission back to normal? Edit: I have tried to scp this file, /lib64/ld-2.17.so from other machine to affected machine, but I get permission denied error. Thank you in advance
If you have an executable file you can write to, you could copy the contents of ld.so to that file using bash's read: while IFS= read -d '' -r line; do printf "%s\0" "$line"; done > executable-file < /lib64/ld-2.17.so Example: bash-4.2$ ll foo -rwxr-xr-x 1 muru muru 29K Aug 23 13:02 foo* bash-4.2$ while IFS= read -d '' -r line; do printf "%s\0" "$line"; done > foo < /lib64/ld-2.17.so bash-4.2$ ./foo Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...] You have invoked `ld.so', the helper program for shared library executables. ... Then you can use it to run chmod: bash-4.2$ ./foo /bin/chmod /bin/chmod: missing operand Try '/bin/chmod --help' for more information.
executed "chmod 666 ld-2.17.so" - how can i recover?
1,685,040,610,000
My question is I'd like to find out how I I centralise the user names, passwords and permissions? if I setup a new linux installation on a new system, how do I ensure it inherits all the same usernames as everyone else? Can this be centralised in some way? I'm starting to play with setting up multiple linux (CENTOS) systems and have shared home directories over the network with NFS, but I can't figure out how a new system can inherit all the users, groups, passwords, and existing home dir/permissions in the correct way.
This can be accomplished by running a central OpenLDAP server and configuring the machines to use the LDAP server to authenticate users rather than local /etc/passwd-based unix account authentication. I'd rate the level of skill required to get it working properly and troubleshoot the problems and issues that come up as "medium-high" to "high". If you are already an LDAP or MS ActiveDirectory wizard or guru, it will be straightforward. If not, be prepared to learn the underlying pre-requisites. A few pre-requisites to implementing multi-machine LDAP login: Must know how to install, manage, configure and use LDAP. Ability to troubleshoot linux systems, and isolate general symptoms back to root-cause(s), then integrating LDAP expertise to identify and make the fix. Word of Caution A single-server implementation of LDAP for unix authentication introduces a new single point of failure into the machines on the network: Anytime the LDAP server goes offline or becomes unavailable, it will not be possible to login to the linux machines. Additional Reading and Tutorials General enough to be useful for other linux distros: System Security Services Daemon: Introduction to SSSD Authentication Architecture pam_ldap- and nss_ldap- oriented resources: (NOTE: no longer best practices [see discussion below], but may still be informative) LDAP authentication using pam_ldap and nss_ldap FreeBSD LDAP Authentication Configuration Arch Linux LDAP authentication tutorial Linux distribution-agnostic tutorial
How can I centralise the user names passwords and permissions over a shared network? (CENTOS)
1,685,040,610,000
I have an embedded device (Nvidia Jetson TX2 running Ubuntu 16.04) in a carrier board and need to use the serial port. The serial port on the carrier board maps to ttyS0 which by default is owned by root and belongs to group tty: crw--w---- 1 root tty 4, 64 Aug 1 13:34 ttyS0 I've added user ubuntu to group tty (which is what I log in as) however by default the group doesn't have read access to ttyS0. sudo chmod g+r /dev/ttyS0 fixes it, but this doesn't persist through a reboot. I've tried creating various udev rules (99-z_setup.rules): KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP:="tty", MODE:="0660", OWNER:="ubuntu" or KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP:="tty", MODE:="0660" or KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP="tty", MODE="0660" these result in: lrwxrwxrwx 1 root root 5 Aug 1 13:34 my_tty -> ttyS0 crw--w---- 1 root tty 4, 64 Aug 1 13:34 ttyS0 so I still can't access it. I also tried KERNEL=="ttyS0", ACTION=="add", PROGRAM="/usr/bin/sudo /home/ubuntu/bin/setup_tty.sh" with setup_tty.sh containing #!/bin/bash chmod g+r /dev/ttyS0 echo "setup_tty ran" >> /home/ubuntu/bin/tty.log It echos to the tty.log file so I know the script runs, but the permissions are still crw--w---- 1 root tty 4, 64 Aug 1 13:44 ttyS0 It's like the group / owner / mode settings are being ignored or being overwritten. I've searched and there are a lot of similar questions, but the answer to them always seems to be to add the user to group tty or dialout. My user account is already a member of both of those but no dice since for some reason by default, the group doesn't have read permission. I checked the /etc/login.defs and found these lines: # TTYPERM Login tty will be set to this permission. # # If you have a "write" program which is "setgid" to a special group # which owns the terminals, define TTYGROUP to the group number and # TTYPERM to 0620. Otherwise leave TTYGROUP commented out and assign # TTYPERM to either 622 or 600. # # In Debian /usr/bin/bsd-write or similar programs are setgid tty # However, the default and recommended value for TTYPERM is still 0600 # to not allow anyone to write to anyone else console or terminal # Users can still allow other people to write them by issuing # the "mesg y" command. TTYGROUP tty TTYPERM 0600 I changed the TTYPERM value to 0660 and rebooted, but it made no difference. Any ideas how I can make this tty have a mode other than 640 after reboot? This will probably be the answer-I ran journalctl | grep tty and among other things found this output: Aug 02 11:05:45 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: [email protected]: Service hold-off time over, scheduling restart. Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: [email protected]: Service hold-off time over, scheduling restart. Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: [email protected]: Service hold-off time over, scheduling restart. Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0. Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0. Aug 02 11:05:48 TX2-JUDY systemd[1]: [email protected]: Service hold-off time over, scheduling restart. Aug 02 11:05:48 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0. Aug 02 11:05:48 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0. Aug 02 11:05:48 TX2-JUDY systemd[1]: [email protected]: Service hold-off time over, scheduling restart. Aug 02 11:05:48 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0. Aug 02 11:05:48 TX2-JUDY systemd[1]: [email protected]: Start request repeated too quickly. Aug 02 11:05:48 TX2-JUDY systemd[1]: Failed to start Serial Getty on ttyS0. so it appears some other service (not sure what Getty is) is trying to use ttyS0.
So it turns out that in my case, ttyS0 is the serial console for the TX2 so trying to use it the way I was going to would be more pain that it's worth. It appears ttyTHS2 is also available and already has the permissions required. Not a particularly satisfying answer, but the best way forward.
How to give a tty a mode other than 640 and have it persist through reboot
1,685,040,610,000
I know that deleting a file depends on the permissions I have on the enclosing directory, and not on the file itself, see e.g. here But what about a non-empty directory? Using rm -rf NON_EMPTY_DIR fails because the files within the directory cannot be deleted. Is keeping the directory non-empty and non-writable for others a safe way of preventing other users to delete the folder? Example: # Create write-all outer dir mkdir outer chmod 777 outer # Create two subdirectories, one of which is empty, one not, # and none are writable by anyone mkdir outer/{non-,}empty touch outer/non-empty/file chmod 555 outer/* ls -la outer ## drwxrwxrwx 4 user user 80 May 31 15:12 . ## [ .. does not matter here ] ## dr-xr-xr-x 2 user user 40 May 31 15:12 empty ## dr-xr-xr-x 2 user user 60 May 31 15:12 non-empty rm -rf outer/empty # Succeeds rm -rf outer/non-empty # rm: cannot remove outer/non-empty/file: Permission denied
Can someone delete my non-empty directory from a write-all directory without having write permissions on it? No. Is keeping the directory non-empty and non-writable for others a safe way of preventing other users to delete the folder? Yes. rmdir doesn't work on non-empty directories, and without write access, they have no way of making it empty.
Can someone delete my non-empty directory from a write-all directory without having write permissions on it?
1,685,040,610,000
I have a script which is called from php using the shell_exec command on a server running Ubuntu. The script runs properly when called from the command line via ssh, but not when called from php. I'm having a really hard time figuring out where it is going wrong and I was wondering if there was a way to run the script from the ssh command line but with the same user account and permissions that php shell_exec will call it with. Thank you.
Assuming the php user is www-data: sudo -u www-data /path/to/script The environment may be different but that probably does not matter.
How to run script as php user
1,685,040,610,000
I have a group called webdev and I want only the root and the memebers of the group webdev to have write access on the directory /web. Now, Here's the problem: # chmod -R u=rwX,go=rX /web # ls -l /web total 4 -rw-r--r--. 1 root root 165 Mar 8 12:29 index.html # ls -ld /web drwxr-xr-x. 2 root root 24 Mar 8 12:34 /web # setfacl -R -m g:webdev:rwX /web # ls -ld drwxrwxr-x+ 2 root root 24 Mar 8 12:34 . # getfacl /web getfacl: Removing leading '/' from absolute path names # file: web # owner: root # group: root user::rwx group::r-x group:webdev:rwx mask::rwx other::r-x So, the moment I allow the group webdev write permissions on the folder, ls -ld shows that my folder is now writable for group root. However, this is contradicted by the output of getfacl /web, where, group still has the (correct) permissions r-x. So, what's going on?
ls -ld shows that my folder is now writable for group root. Wrong. It shows, with the + symbol in that position, that the file has ACLs. Since the file has ACLs, the meaning of the middle three permissions letters displayed by ls is the mask, not the file-group permissions. Further reading View extended ACL for a file with '+' in ls -l output Winfried Trümper (1999-02-28). Summary about Posix.1e Portable Applications Standards Committee of the IEEE Computer Society (October 1997). Draft Standard for Information Technology—Portable Operating System Interface (POSIX)—Part 1: System Application Program Interface (API)— Amendment #: Protection, Audit and Control Interfaces [C Language] IEEE 1003.1e. Draft 17. Craig Rubin (1989-08-18). Rationale for Selecting Access Control List Features for the Unix System. NCSC-TG-020-A. DIANE Publishing. ISBN 9780788105548.
How to stop setfacl from making my directory writable for group?
1,685,040,610,000
If I create a file with sudo vim test and then open it up in my account (without sudo) why does the editor complain when I try to modify the file (i.e. read only option is set)? According to ls -l I am the owner, and the owner has rwx Why can't I write to the file?
If you create a file with sudo vim test the owner will be root, not you, so if later you want to edit the file you either need to change the owner from root to you or change the permissions. See: jordim@bucketlist-196008:~/test$ sudo vim test jordim@bucketlist-196008:~/test$ ls -l total 8 (...) -rw-r--r-- 1 root root 2 Feb 22 15:43 test (...) The created file belongs to root:root and only root has read and write permissions for it. Rest of the users of the group can only read, as well as any other user from other groups. The question is, why are you creating the file with "sudo" if you need to edit it later as a regular user?
If I own a file, why do I need to change permission to write to it?
1,685,040,610,000
I was just reading some articles about permissions in Linux and I found out that this was never mentioned there. I wonder how it works. Example situation: Binary file read_file.out that reads file ~/file.txt and prints its content to stdout is executed. This creates a process and the system decides whether it can or can not read ~/file.txt based on EUID and/or EGID of the user who created of the process. Where exactly are these values stored? Where does the system look in order to say "I see your EUID is 1002, so you can read this file." or "Your EUID is 1003 which means you can not read it and you are also member of no group that can access this file so I will not allow you to read it."? I found out that there are some files in the pseudo-filesystem /proc/<pid>/, especially /proc/<pid>/stat and /proc/<pid>/status (better readable version of stat). Are these the files according to which the system decides the permissions or are they just "informational" files that serve only as a source to commands like ps? Thank you for your answers.
In the kernel data structures. The virtual files in /proc/<pid>/ are just views into them. Now, I could dig up the source code, but I doubt it's really useful. There's probably just a simple C struct for each process, that contains fields for all of the UIDs and GIDs plus a table of secondary groups along other per-process data.
Where exactly is EUID, EGID etc. of a process stored?
1,685,040,610,000
I add permission to work on a directory as following: Udi> setfacl -R -m d:u:sami:rwx tmp Udi> getfacl tmp/ # file: tmp/ # owner: udi # group: udi # flags: -s- user::rwx group::r-x other::r-x default:user::rwx default:user:sami:rwx default:group::r-x default:mask::rwx default:other::r-x Udi> ls -ld tmp/ drwxr-sr-x+ 2 udi udi 6 2017-10-31 18:47 tmp// Now, when Sam try to write in the directory he gets an error message: Sami> cd ~udi/tmp Sami> mkdir abc mkdir: cannot create directory ‘abc’: Permission denied I tried to figure out the problem by looking at the logs of Selinux with out success, there is no avc about it and no sign in other logs. The OS is Centos 7 and the filesystem is xfs What can I do?
The problem is that -m d:u:sami:rwx changes the default permissions only i.e. the permissions for newly created objects in this directory. It does not affect the permissions of that directory at all. You need a second call: setfacl -R -m u:sami:rwx tmp
Unable to write on directory that allowed by setfacl
1,685,040,610,000
I'm trying to change permissions of a file that my user does not directly own, but my user is in a group that does have ownership of the file. Here are the current permissions of the file. I am logged in as user_a -rwxrwx---. 1 user_b mygroup 145 Sep 28 15:53 /filepath I run the command chmod +x /filepath and I am met with the error: chmod: changing permissions of '/filepath': Operation not permitted We have several users working on our linux computer, and we've all been added to mygroup. How can I make it so that we can change rwx permissions of each others files without using sudo?
Only root (i.e. UID 0) or a process with CAP_FOWNER can change the permissions of a file it does not own. The most suitable approach is probably sudo. Only root (i.e. UID 0) or a process with CAP_CHOWN can change the owner of a file.
Change permissions of file when group has ownership, but user does not
1,685,040,610,000
I've setup a local repo with reprepro, accessible via a local web server. Thus every file and dir in its file sub-tree owns to www-data:www-data. The problem is that every time I add a new package I need to use sudo, that makes all the permissions of the files involved to change, and every time I have to fix this by hand. Any clue how can I avoid this? Maybe using a sticky bit? Thanks in advance.
You can tell sudo you want to run commands as www-data instead of root: sudo -u www-data ... That way the ownership of your repository won’t change.
How to manage permissions correctly when adding a new package to a reprepro repo
1,685,040,610,000
I have the following directory structure: + public/ |-+ pics/ | |-- a | `-- b `-+ thumbs/ |-- a `-- b I would like all the files in the tree to be owned by gallery:http with ug=rwX,o= mode set. The script which happens to create directories within pics and thumbs runs as the gallery user. I set SUID/SGID bits on public, pics and thumbs. Now the problem is that the a directory will get created with owners gallery:http as it should, but it won't have the x permission for the group. If I call chmod, I'll clear the SGID bit. (Strange behavior, but that will really happen, likely because http is not the user-owner of the file.) I can't call chown as non-root user to set mode first and then the owners. The only solution seems to be to set umask to ug=rwx,o=, create all the directories and then either change the umask before I create any regular file, or create the regular files and then change their mode to ug=rw,o=. Is there a better, less ugly solution which I don't see?
If you can change the script it might be the easiest solution to change the mkdir calls to mkdir --mode=770. If you cannot change the script then ACLs might help: setfacl -m d:u::rwx,d:g::rwx,o::- pics thumbs umask does not set executable permission on files. It never sets any permissions; it just prevents permissions from being set on file creation.
How to call chmod and preserve the SGID bit?
1,685,040,610,000
When I was studying the manual page for command pmount I read the following: pmount ("policy mount") is a wrapper around the standard mount program which permits normal users to mount removable devices. And when I used pmount /dev/sdc1 (without sudo) as a normal user, it created a folder named /media/sdc1 folder, while the permissions for the system's /media folder are drwxr-xr-x and it is owned by root. This means that a normal user (currently, me) cannot create files and folders in /media folder. Doesn't this contradict the rules of permissions and ownership in Linux? Another question is that while mount requires superuser permissions, and pmount uses mount internally, how is it possible to use pmount without sudo?
/usr/bin/pmount is a setuid binary. When running a setuid executable, the uid or gid is changed to executable's owner. When executing pmount, the process will have root privileges and can therefore create root owned directories and mount filesystems. Same setuid mechanism also applies to sudo.
How does command "pmount" work without "sudo"
1,499,509,981,000
Trying to make a cheap CNC machine to work, I have to connect through a parallel port. Unfortunately, I do not manage to make the parallel port to work. It seem the PCI parallel port card is detected, but I do not achieve to transmit/connect anything to it. How to make the parallel port working? How to make the parallel port working with normal user privileges? EDITED The port seem to works only under root privileges. That is probably the issue. But how to make the parallel port to work for normal users? . Note: My machine is a Debian Linux with RT kernel 4.9. What I did tried: The PCI parallel card is plugged into my computer. Running $lsmod |grep ppdev return what seem a correct result: ppdev 20480 2 parport 49152 3 lp,parport_pc,ppdev Running $lspci -v Return information, that I don't fully understand: 03:01.0 Parallel controller: MosChip Semiconductor Technology Ltd. PCI 9865 Multi-I/O Controller (prog-if 03 [IEEE1284]) Subsystem: Device a000:2000 Flags: bus master, medium devsel, latency 32, IRQ 22 I/O ports at dc00 [size=8] I/O ports at d880 [size=8] Memory at fcfff000 (32-bit, non-prefetchable) [size=4K] Memory at fcffe000 (32-bit, non-prefetchable) [size=4K] Capabilities: <access denied> Kernel driver in use: parport_pc And more data: $dmesg |grep parport (note: I have on single parallel port) return [ 11.791907] parport_pc 00:02: reported by Plug and Play ACPI [ 11.791998] parport0: PC-style at 0x378 (0x778), irq 5 [PCSPP,TRISTATE,EPP] [ 11.888153] lp0: using parport0 (interrupt-driven). [ 11.888949] parport1: PC-style at 0xdc00, irq 22 [PCSPP,TRISTATE,EPP] [ 11.984195] lp1: using parport1 (interrupt-driven). I downloaded a test application from here, which I run from the command line WITHOUT root permissions. It shows all the out-pins in red and all the in-pins in green. When pressing on an out-pin, it switch to green, but I suspect it does not mean anything. Finally, the ultimate test: I connected to the parallel port a LED between GND and PIN_02 (with 1k ohm resistor). If I connect it to BUZY (by default on), the led turn on, but while connected to PIN_01, it never light, even while pressing the button from the test application. From all those test, I suspect the card is correctly installed, but due to some permission or other misconfiguration, it does not work. I tried to run the PortTest with root admin, but it seem not happy with it.
The issue is with the privileges of the parallel port: by default, it is accessible only by users of the group lp. The root user is obviously allowed to it, but normal users are not. Adding the user to the lp group make the parallel port accessible without sudo: adduser <user-name> lp After that, the parallel port is working and I could continue the configuration.
How to make the parallel port to work?
1,499,509,981,000
I've mounted an Amazon EBS volume on /media/scientist/data1. scientist is the username. However, once in scientist, I can't do an ls command on it. See as follows: scientist@ip-10-30-10-239:/media$ ls -l total 4 d-wx-wx--x 3 scientist scientist 4096 May 5 19:24 scientist scientist@ip-10-30-10-239:/media/scientist$ ls ls: cannot open directory '.': Permission denied However if I go in one directory further it works fine scientist@ip-10-30-10-239:/media/scientist/data1$ ls intex lost+found The command I ran was sudo chown -R scientist /media/scientist.
You do not have read privileges on this directory: d-wx-wx--x. Directory ownership does not give you privileges to read it's content. To fix that problem, run the following command: sudo chmod u+rwx media/scientist I encourage you to read: [chown manpage] [chmod manpage]
Linux permission on mounted drive
1,499,509,981,000
Preface: This is a digital ocean droplet setup using serverpilot. There are two users, root and serverpilot. When I SSH in as serverpilot I can see the files listed inside of apps/website/public/, but when I SSH in as root and cd into apps/website/public/ and ls -la there are a number of files and directories that are not listed. As an example, serverpilot can see style.css -rwxrwxr-x+ 1 serverpilot serverpilot 22322 Nov 17 22:05 style.css As another example, here are a few other files that root cannot see but serverpilot can. drwxr-xr-x+ 13 serverpilot serverpilot 4096 Apr 18 11:42 wp-content -rwxrwxr-x+ 1 serverpilot serverpilot 3286 May 24 2015 wp-cron.php drwxr-xr-x+ 18 serverpilot serverpilot 12288 Dec 7 17:35 wp-includes But when I SSH in as root and cd into apps/website/public and ls -la this is all thatI see. drwxrwxr-x 3 www-data www-data 4096 Apr 17 22:49 . drwxr-xr-x 3 root root 4096 Oct 14 2016 .. -rw-rw-r-- 1 www-data www-data 46 Oct 21 15:11 .user.ini Checking both root and severpilot groups displays: root : root www-data lxd sp-sysusers users serverpilot serverpilot : serverpilot lxd sp-sysusers I'm not sure what happened and why root user has lost access to the directories and files. I've tried resetting file permission, chown and chown with a group name, but am still unable to get the files to show up for root. Since I'm fairly new to linux server management, I feel like it may be something simple that I am overlooking. Edit: Some of the comments below recommended running getfacl to get more info on a file since it appears that ACLs is overriding the file permissions. The output of getfacl on style.css is as follows: # owner: serverpilot # group: serverpilot user::rwx user:www-data:r-x group::r-x group:serverpilot:rwx mask::rwx other::r-x Is it possible that the user should be serverpilot:r-x and not www-data:r-x?
Now I feel completely stupid, but I guess everyone has to start somewhere. The issue was indeed what @ilkkachu had mentioned in their comment. When I ssh in as root it was dropping me in a /root/ directory which lived elsewhere on the server. Not sure why I didn't check this. When I ssh in as serverpilot it was placing me in the correct directory where my files/folders should be. For some reason, some of these files were duplicated in the /root/ directory as well. Updating permissions on one of the parent directories, I was able to CD out of the directory and down into the proper directory where I needed to be. Now to investigate how to setup root user to be dropped in the proper folder. Thanks all.
Root user unable to see files/directories [closed]
1,499,509,981,000
I have added debian8 into group www-data with command . sudo usermod -G www-data debian8 It can be verified with command. cat /etc/group |grep 'www-data' www-data:x:33:debian8 The ownership properties: -rw-r--r-- 1 www-data www-data 418 Sep 25 2013 /var/www/html/wp/index.php sudo ls -al /var/www/html/wp total 200 drwxrwxr-- 5 www-data www-data 4096 Jan 5 10:16 . drwxrwxrwx 5 www-data www-data 4096 Jan 4 15:51 .. -rw-r--r-- 1 www-data www-data 418 Sep 25 2013 index.php Why debian8 as a member of group www-data can't cat it? debian8@hwy:/var/www/html/wp$ cat index.php cat: index.php: Permission denied sudo getfacl /var/www/html/wp/index.php getfacl: Removing leading '/' from absolute path names # file: var/www/html/wp/index.php # owner: www-data # group: www-data user::rw- group::r-- other::r-- Do as heemayl say,Logout and then login,the file /var/www/html/wp/index.php can be cated,why can't touch a new file in /var/www/html/wp/test.txt now? touch /var/www/html/wp/test.txt touch: cannot touch ‘/var/www/html/wp/test.txt’: Permission denied It is so strange that no problem for touch /var/www/html/wp/test1.txt no permission for touch /var/www/html/wp/test.txt
You are missing a crucial point that touch needs write access so in case of touch test.txt which have permission -rw-r--r-- which allows you to read and not modify. so write permission is missing for group if you do chmod g+w test.txt it will work fine. And you figured out that you need to re-login to see effect of changes made to system parameters.
Why can't cat the file?
1,499,509,981,000
I am trying to figure out how to manage ext4 formatted external hard drives and I have stumbled upon a behaviour that I do not understand. I noticed that if I change access permissions (or ownership) of mount points of automatically per-user mounted devices under /media, the change is persistent, even though the mount point disappears after unmounting the device. To help me understand the implications of this, could someone explain to me how it works? Here is an example of this behaviour with an ext4 formatted USB flash stick: § ls -l /media/alexey/ total 4 drwx------ 3 alexey alexey 4096 déc. 23 21:25 Corsair § chmod g+rwx /media/alexey/Corsair/ § ls -l /media/alexey/ total 4 drwxrwx--- 3 alexey alexey 4096 déc. 23 21:25 Corsair § umount /media/alexey/Corsair § ls -l /media/alexey/ total 0 § udisksctl mount -b /dev/sdc Mounted /dev/sdc at /media/alexey/Corsair. § ls -l /media/alexey/ total 4 drwxrwx--- 3 alexey alexey 4096 déc. 23 21:25 Corsair
You must separate between a directory and a (directory used as a) mountpoint. When you mount a file-system "on-top of" a directory, that directory (and all files and directory under it) becomes obscured - covered if you like - by the file-system you mounted "over" it. The changes you made, was done to the filesystem on your USB-pen, and thus remain between mounts - not on the (transient) directory used as just a mount-point for it (which is created anew - with default permission - each time it's needed). In essence, the top/root (/) of the filesystem on you USB-pen, "becomes" the mount-point! On your USB-pen, there is a separate filesystem with it's own root (/). When you plug-in your USB-pen, a directory called Corsair is created - with some default permission and ownership under /media/alexey. Then the root-filesystem on the USB-pen is mounted "on-top of" the /media/alexey/Corsair-directory - obscuring it. From now on when you do something (like changing permission or ownership) to the Corsair directory, you're actually changing things to the root-directory on your USB-pen. When you unmount the USB-pen, the Corsair directory is deleted. But the filesystem on the USB-pen - with any changes you made to it, including to the root of it - remains. When you plug-in the USB-pen again, a new Corsair directory is created with default permission - and no memory from what was done last time. However when the USB-pen's filesystem and it's root is mounted on top of the directory, the changes you made will still be there - because the changes was done on your USB-pen, not the transient directory.
How does Ubuntu keep persistent access permissions for mount points of automatically per-user mounted devices?
1,499,509,981,000
I've written a script that copies some files from one place to another and since I don't have permissions to the source folder, I tried running it with sudo. The problem is that now the creation of the destination folders fails. Here is a simple test case: In my home directory the following works: mkdir testDir But this fails due to permission denied error sudo mkdir testDir2 My home directory has 755 permissions and is own by me. I ran sudo groups and found that as expected the root group is there, but strangely, the users is not. Also running groups as myself reveals that I'm not in the sudo group. Any ideas what's going on? Why am I not able to write to my home folder when running with sudo?
This is due to "root squash" on the NFS server. From the exports(5) man page (emphasis mine): nfsd bases its access control to files on the server machine on the uid and gid provided in each NFS RPC request. The normal behavior a user would expect is that she can access her files on the server just as she would on a normal file system. This requires that the same uids and gids are used on the client and the server machine. This is not always true, nor is it always desirable. Very often, it is not desirable that the root user on a client machine is also treated as root when accessing files on the NFS server. To this end, uid 0 is normally mapped to a different id: the so-called anonymous or nobody uid. This mode of operation (called 'root squashing') is the default, and can be turned off with no_root_squash. To paraphrase, it's generally a security risk to allow root (e.g., when running sudo) on the NFS client to modify files and file attributes as if it were root on the NFS server. This would effectively make root on the client equivalent to root on the server, and allow a rogue client to take over the server. From the RHEL 6 security guide: If no_root_squash is used, remote root users are able to change any file on the shared file system and leave applications infected by Trojans for other users to inadvertently execute.
Sudo mkdir fails due to permission denied error
1,499,509,981,000
sudo date > output.txt bash: output.txt: Permission denied I want to write log message into file, but the permission denied even I add prefix sudo, But when I tried after making output.txt file and changing permission to 755, It works well. How can I write log meesage without making file and changing permission? simply like sudo date > output.txt --chmod 755 ?
date | sudo tee output.txt > /dev/null This works because tee opens the output.txt and it is running as root. The > /dev/null is just to throw away the extra copy that tee would send to stdout. The reason why sudo date > output.txt doesn't work is that the output redirection (the > output.txt) is done before the sudo date is started, and so runs with the current access rights. A different approach would be to change the permissions on the current directory to allow the current user to create files. Doing this would mean that date > output.txt could work without needing sudo.
Linux permission denied when make log message into file [duplicate]
1,499,509,981,000
I'm familiar with the 3 file mode 'bits' defining user, group, and other permissions as well as the setuid/setgid/sticky 'bit', but when I stat the root level directories on my MacOSX laptop I see 1 to 2 extra fields. What are these? [onlyanegg@macosx ~]$ stat -f '%p %N' /* 40775 /Applications 40755 /Library 40755 /Network 40755 /System 40755 /Users 41777 /Volumes 40755 /bin 41775 /cores 40555 /dev 120755 /etc 40555 /home 100644 /installer.failurerequests 40555 /mnt 40555 /net 40775 /opt 40755 /private 40755 /sbin 120755 /tmp 40755 /usr 120755 /var
stat(1) specifies that %p requests File type and permissions. (look for "datum" in the linked page). The value displayed is all of st_mode (see stat(2): #define S_IFMT 0170000 /* type of file */ #define S_IFIFO 0010000 /* named pipe (fifo) */ #define S_IFCHR 0020000 /* character special */ #define S_IFDIR 0040000 /* directory */ #define S_IFBLK 0060000 /* block special */ #define S_IFREG 0100000 /* regular */ #define S_IFLNK 0120000 /* symbolic link */ #define S_IFSOCK 0140000 /* socket */ #define S_IFWHT 0160000 /* whiteout */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #define S_ISVTX 0001000 /* save swapped text even after use */ #define S_IRUSR 0000400 /* read permission, owner */ #define S_IWUSR 0000200 /* write permission, owner */ #define S_IXUSR 0000100 /* execute/search permission, owner */ This explains the values you're getting: values starting with 4 are directories (/Applications, /Library...) values starting with 12 are symbolic links (/etc, /tmp, /var) values starting with 10 are regular files (/installer.failurerequests)
File mode on MacOSX
1,499,509,981,000
A user has been added with root access in the /etc/sudoers but, it seems that it can not run sudo commands. [root@compute-0-0 ~]# cat /etc/sudoers root ALL=(ALL) ALL hduser ALL=(ALL) ALL [root@compute-0-0 ~]# sudo usage: sudo -h | -K | -k | -L | -V usage: sudo -v [-AknS] [-g groupname|#gid] [-p prompt] [-u user name|#uid] usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U user name] [-u user name|#uid] [-g groupname|#gid] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ... [root@compute-0-0 ~]# su - hduser [hduser@compute-0-0 ~]$ ls bio hadoop-2.7.2 hadoop-2.7.2.tar.gz protobuf-2.5.0 protobuf-2.5.0.tar.gz [hduser@compute-0-0 ~]$ sudo ls [sudo] password for hduser: ls: cannot open directory .: Permission denied [hduser@compute-0-0 ~]$ What is the reason?
The problem you are having is not a sudo problem, but a root permission problem. The filesystem that has hduser's home directory is not local to the machine and doesn't grant root permission to it. So when you did su - hduser you automatically changed to that directory, so sudo ls tried to run the ls command as root and that is where the error came from. This may help you solve that problem: Sudo, no access to user files
Edited sudoers, but `sudo ls` fails
1,499,509,981,000
I would like to replace a directory with a symlink. For the directory itself I have full permissions (rwx), but for the parent directory I don't have write permissions (r-x). Is this possible? The man page for ln states that -f removes existing destination files, which sounds like it would first would delete the directory, then fail to create the symlink, leaving me with nothing.
If you don't have write permission in the parent directory, you can't make any changes in the parent directory; this includes deleting the target directory, and creating a symlink. In any case, ln won't overwrite a directory, even with -f.
Can I replace a directory with a symlink without write permissions in parent?
1,499,509,981,000
Files in /proc/ seem to be world-readable, but return permission denied: $ ls -lh /proc/5589/smaps -r--r--r-- 1 root root 0 Mar 18 13:11 /proc/5589/smaps $ cat /proc/5589/smaps cat: /proc/5589/smaps: Permission denied I want to avoid reading such files, but -r check passes: $ if [ -r /proc/5589/smaps ] ; then echo readable ; fi readable How do I check if the file is actually readable?
if cat /proc/5589/smaps 2>/dev/null 1>/dev/null; then echo readable ; fi or to read less if head -n 1 /proc/5589/smaps 2>/dev/null 1>/dev/null; then echo readable ; fi Update: I think you need to combine both checks in your script: 1) if [ -r /proc/5589/smaps ] 2) if cat /proc/5589/smaps 2>/dev/null 1>/dev/null; So that first you check file permissions and then check a result of reading a proc file. For example: filename="/proc/5589/smaps" if test -r "$filename" && cat "$filename" 2>/dev/null 1>/dev/null; then echo readable else echo not readable fi
How can I check read permission of /proc/*/* files?
1,499,509,981,000
I've been having problems with accessing files these days. In the course of solving this problem, I tried changing the ownership from root to ar.lnx and this is what I got [ar.lnx@host DATA] $ cd /mnt/DATA [ar.lnx@host DATA] $ ls -l total 832 drwxr-xr-x 7 root root 32768 Jan 10 09:52 1 drwxr-xr-x 14 root root 32768 Jan 22 14:36 Audio drwxr-xr-x 2 root root 32768 Jan 10 09:48 Compressed drwxr-xr-x 4 root root 32768 Jan 22 19:22 Dev Workshop drwxr-xr-x 3 root root 32768 Jan 10 11:40 ISO drwxr-xr-x 11 root root 32768 Jan 17 12:10 Knowledge drwxr-xr-x 3 root root 32768 Jan 11 01:30 Photos drwxr-xr-x 2 root root 32768 Dec 3 20:24 print -rwxr-xr-x 1 root root 40354 Jan 22 22:57 rpm-pack.catalog -rwxr-xr-x 1 root root 335462 Jan 11 23:11 Solarized (dark).kateschema drwxr-xr-x 4 root root 32768 Jan 11 00:53 Tattoo -rwxr-xr-x 1 root root 320 Dec 26 15:53 network-list -rwxr-xr-x 1 root root 2 Dec 26 15:53 network-list~ drwxr-xr-x 2 root root 32768 Jan 11 03:19 Windows(.exe) [ar.lnx@host DATA] $ su Password: [root@host DATA] # sudo chown ar.lnx:ar.lnx /mnt/DATA -R chown: changing ownership of ‘/mnt/DATA/1/PP1-CS6-start.pdf’: Operation not permitted chown: changing ownership of ‘/mnt/DATA/1/PP1-CS6-start1.odg’: Operation not permitted . . . chown: changing ownership of ‘/mnt/DATA/Audio’: Operation not permitted chown: changing ownership of ‘/mnt/DATA’: Operation not permitted [root@host DATA] # why do I get "Operation not permitted?" and what exactly is the problem?
/mnt/DATA is likely a FAT (i.e. windows or ms-dos) filesystem, and FAT doesn't support unix file permissions or ownership. If not FAT, then some other fs type that doesn't support unix ownership or perms, but FAT is most likely. You don't need to change the format unless ownership or perms are important to you - if you just want to transfer the files around using /mnt/DATA (presumably a USB stick) then you can just ignore the Operation not permitted error messages. If owner/perms are important, then reformat as, e.g., ext4. If you just want /mnt/DATA to be owned by a particular owner or group when mounted, then you can use the uid= and/or gid= mount options. You can also set the umask, dmask, and fmask values, which affect the default (faked/emulated) perms of created files and/or dirs. See man mount and search for Mount options for fat for details.
is it an access issue or a permissions issue?
1,499,509,981,000
My company has a web designer that's going to upload files to /var/www/html and edit them. I created an account and will give them ssh access. I added them to the apache group, but they can't access /var/www/html. Currently this is the set up of /var/www/html: drwxr--r-- 5 apache apache 4096 11月 4 17:56 html What would give them access to this directory but keep Apache limited? I can change it with chmod 664 apache:apache -R but what other suggestions do you have?
The usual way of addressing this is to put the ftp/sftp users in a chroot, so that they can see only the directory tree which included. The feature is described in several places. To start: Limit FTP access only to the /var/www with vsftpd chrooted sftp user with write permissions to /var/www How to Setup Chroot SFTP in Linux (Allow Only SFTP, not SSH) How to jail / chroot users in FTP / SFTP
Allow user access to their own dir, /var/www/html, nothing else
1,499,509,981,000
I want to put a bunch of files into an archive with tar. However, I don't have permission to access all of them, so I have to do sudo tar. However, now that root has run the tar, the resulting archive is also owned by root, and I must change permissions on the .tar.gz, which is a bit tedious. Isn't there a "partial sudo" of some sort to tell tar to access the files as root, but create the file as me?
You can take advantage of a fact that often annoys or surprises people, that redirection occurs in the shell and is unaffected by sudo. Use - (aka /dev/stdout) as the filename and then redirect the output to a filename of your choice. It will be owned by you, created with your default permissions (as defined by umask). sudo tar czf - [more options and file/dir names] > myfile.tar.gz The redirection happens as your UID, while the tar itself runs as root.
`sudo tar` but own the resulting file
1,499,509,981,000
I'm trying to execute a script located on an NTFS partition that I own. I own the mount point, which is ~/Migration. ls -l in the directory where the mount point is contained shows me drwxrwxrwx 1 technomage technomage 4096 Sep 30 18:04 Migration Despite being the owner of the entire structure, from the mount point and onwards, and having rwx privileges, it prevents me from executing this script, startup.sh. Bash gives me the following error: bash: ./startup.sh: Permission denied In the directory that contains the script, ls-la shows me: drwxrwxrwx 1 technomage technomage 4.0K Oct 1 12:51 . drwxrwxrwx 1 technomage technomage 4.0K Oct 1 12:51 .. -rwxrwxrwx 1 technomage technomage 1.9K Oct 1 12:51 startup.sh Still I cannot execute startup.sh. I know that permissions on NTFS partitions in linux can be somewhat finnicky, so I went into the /etc/fstab and set the privileges, owners and masks as best as I could: UUID=6F537BB96F6E0CBC /home/technomage/Migration ntfs-3g rw,exec,user,umask=000,uid=1000,gid=1000 0 0 I then proceeded to sudo umount Migration, followed by reloading the fstab file configuration with sudo mount -a. The remounting is successful. Despite all of this, I still cannot execute the script despite even using root. The mount | grep sda6 command shows me the following, which tells me somehow, that the partition isn't mounting properly or using the configurations I gave it: /dev/sda6 on /home/technomage/Migration type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,user) I'm running Debian Jessie, and even went into stretch's repository to get the latest version of the ntfs-3g driver, thinking it was some kind of bug.. no dice. I'm not quite sure what's wrong. Please show me how I misconfigured how I mount my NTFS partition? I need total access to it.
You have your options right in /etc/fstab, but the order matters; exec has to come after user because user imposes noexec (among others). So your /etc/fstab entry should look like this: UUID=6F537BB96F6E0CBC /home/technomage/Migration ntfs-3g rw,umask=000,uid=1000,gid=1000,user,exec 0 0 After the change to /etc/fstab, unmount the drive then sudo mount -a and try again. Also, make sure your uid and gid are correct (by executing the command id when logged in with your user).
NTFS Partition Not Mounting Properly, Cannot Execute Despite Ownership
1,499,509,981,000
I know there is a question like this already, but it was confusing question and answer, and I think this should be simple I am testing deleting a file and I have two users admin_ftpuser works, delebash does not. sudo delebash works fine. Here are the group user belongs to and file permissions via command groups: admin_ftpuser : admin delebash sudo admin File and Folder permissions via command ls -l drwxr-x--x 2 admin admin 4096 Aug 27 08:37 public_html then file underneath public_html called robots.txt -rw-rw-r-- 1 admin admin 65 Aug 26 23:35 robots.txt If I login via ftp with user admin_ftpuser and try to delete robots.txt it works If I login via ftp with user delebash and try to delete robots.tx it does not, delebash has access to the directory and can write to it but not delete I have also tried shell access via ssh with user delebash with the same results admin_ftpuser does not have a user directory nor shell access as ssh is limited to key authentication, but ftp login for both users work fine. I used VestaCP to setup the admin_ftpuser and I manually added delebash user, but I don't understand if they both are in admin group and admin group has rw on robots.txt why admin_ftp user can delete and delebash cannot. I know I can change ownership but I do not want to do that, I want users that belong to admin group to be able to do the same thing as admin_ftpuser I have logged out and in again and rebooted.
Deleting a file requires write permission on the directory. This is because you are actually modifying the directory when you delete the file (You don't even need permissions on the file to delete it if you can write in the directory, you'll just receive a warning about deleting a write-protected file). You just need to give the group write permissions on the directory. Your question is a duplicate of this https://superuser.com/questions/373115/why-cant-i-delete-a-file-where-i-have-group-write-permissions-on
Permission denied to file even though I am in that group
1,499,509,981,000
I'm in dual boot with Windows, and i've created a shared ntfs partition. I' ve cloned a project from github, use make to compile it but seems it isn't recognized as runnable. I've added the right permission and tried to change the owner of the directory. This is the output of ls -l: total 298 -rwxrw-rw- 1 federicop federicop 375 ago 13 00:37 CLOSE.c -rwxrw-rw- 1 federicop federicop 1015 ago 13 00:37 CommandsHandler.c -rwxrw-rw- 1 federicop federicop 296 ago 13 00:37 CONFIG -rwxrw-rw- 1 federicop federicop 5483 ago 13 00:37 Config.c -rwxrw-rw- 1 federicop federicop 430080 ago 13 00:37 core -rwxrw-rw- 1 federicop federicop 886 ago 13 00:37 Error.c -rwxrw-rw- 1 federicop federicop 1774 ago 13 00:37 Heartbeating.c drwxrw-rw- 1 federicop federicop 4096 ago 13 00:37 inc -rwxrw-rw- 1 federicop federicop 346 ago 13 00:37 makefile -rwxrw-rw- 1 federicop federicop 5530 ago 13 00:37 OPE.c -rwxrw-rw- 1 federicop federicop 0 ago 13 00:37 output.txt -rwxrw-rw- 1 federicop federicop 3157 ago 13 00:37 READ.c -rwxrw-rw- 1 federicop federicop 37 ago 13 00:37 Run.sh -rwxr-xr-x 1 federicop federicop 47486 ago 13 08:21 Server -rwxrw-rw- 1 federicop federicop 3323 ago 13 00:37 server.c -rwxrw-rw- 1 federicop federicop 7218 ago 13 00:37 StruttureDati.c drwxrw-rw- 1 federicop federicop 0 ago 13 00:37 TestDIR -rwxrw-rw- 1 federicop federicop 2186 ago 13 00:37 Utils.c I need to run Server, and my user is federicop. This directory is in /media/federicop/Data and i have this line in my fstab: UUID=82440D36440D2F0B /media/federicop/Data ntfs-3g auto,users,permissions 0 0 If i try to run it i get an error: ./Server bash: ./Server: Permission denied The code works in another machine. Also I think is worth mentioning that my files are listed with another color:
Probably your NTFS volume is mounted with option noexec, which is the default enforced by permissions. See man ntfs-3g for details. You could selectively enable exec option by adding it to fstab. UUID=82440D36440D2F0B /media/federicop/Data ntfs-3g auto,users,permissions,exec 0 0 Run grep /media/federicop/Data /proc/mounts to know mount options actually applied.
Can't run c program in other partition
1,499,509,981,000
I want to find those files which I cannot copy to another location such that I could do Rsync. I have an external HDD and my system´s HDD. The external HDD has files which my system is missing. I am thinking how to do this. I can find those files/directories with permission denied -messages by find / ! -perm /u+r where some permissions are drwx------ 1 501 root 6 Oct 22 2014 PortableCV_WebCruiter_20141022 The following command may work from commandlinefu.com, since remote data can be considered here as external HDD rsync --rsync-path 'sudo rsync' username@source:/folder/ /local/ which Rsync remote data as root using sudo If your user has sudo on the remote box, you can rsync data as root without needing to login as root. This is very helpful if the remote box does not allow root to login over SSH (which is a common security restriction). How can you rsync files with permission denied problems between external HDD and system HDD?
If you want to skip the unreadable files: find /external/hd/folder ! -readable -print >unreadable_files rsync -a --exclude-from=unreadable_files /external/hd/folder/ /local/folder This assumes that you're using GNU find, and that your filenames don't have embedded newlines. If you want to copy all files, regardless of whether they are readable or not on the external disk: sudo rsync -a /external/hd/folder/ /local/folder sudo chown -R masi:masi /local/folder This assumes you have enough privileges to run sudo rsync and sudo chown.
To Rsync files where permission denied
1,499,509,981,000
I accidentally moved my /bin directory to /usr/bin/bin, anyway, I managed to move it back to its place with # /usr/bin/bin/mkdir /bin # /usr/bin/bin/mv /usr/bin/bin / and then I was able to login as root, but I wasn't able to su from my user, it gave me an authentication error. I ran chmod +s /bin/su and chmod u+s /bin/su as root, and it fixed it. another thing I noticed is that I can't ping either; it gives me this error: $ ping 192.168.1.1 ping: icmp open socket: Operation not permitted and this is my ping file: -rwxr-xr-x 1 root root 44K Jun 30 20:38 /bin/ping I guess I messed up all the permissions and SGID on my /bin folder. Is there any way to fix this? (other than formatting) Just for the record, I'm using a 64 bit Debian 8.
I would debootstrap a base system to another directory. debootstrap --variant=minbase --arch=amd64 jessie /tmp/bootstrap http://ftp.us.debian.org/debian/ Then copy all files from /tmp/bootstrap/bin to /bin keeping the permissions. cp -a /tmp/bootstrap/bin/* /bin/ Now many (and the basic ones) of your files in /bin should be ok and you should be able to see which were not touched using the timestamp (old files can have wrong permissions). For the rest you can use apt-get install --reinstall PACKAGE to set the permissions back. You can find the package to a file with dpkg -S /path/to/file This is even scriptable... Good luck!
accidentally moved and fixed /bin/ directory, but now can't su
1,499,509,981,000
If a user does not have sudo privileges, can he/she create a file or modify any file outside of his/her home directory, and outside of any external media devices he/she might have connected to the system? Let's assume he/she has not been explicitly given access to any other directory. I'm trying to back up the files of someone who cannot be reached. The system is RHEL, but I'm interested in knowing the answer for Ubuntu (and CentOS too, but I assume the answer for CentOS would be similar to RHEL.)
Yes, he/she can write files on /tmp for instance. Regarding modification of files, that depends on the file's permissions. If all users are allowed to modify that file he/she will be able to modify that file or if he/she belongs to the other user's group and that group has permissions to do that. In the end it all depends on the permissions, so take a look at the file system, use ls -l or find and discover by yourself where he/she can or can not write or modify.
Can non-sudoer modify anything outside of home directory
1,499,509,981,000
I have a few users under the same group. However, when they all work on the same folder via winscp, whenever they open a new file, they open it with themselves, as the owner. Thus, when someone else is trying to save the file, if it's his own fine, but if not, it does save, and gives an error "Upload successful, error occurred while setting the permissions and/or timestamp". How can I set it in a way, that whoever is in a group (let's call it "web"), save new files and edit them under the web owner? or alternately, be able to change the file permissions as well as the file content?
You can assign the sticky bit to the working directory: chmod g+s ... That way whenever a file is created, it is assigned to that group. You can then edit the users' umask to allow group members to edit files by default.
User in the same group new/edit files permissions
1,499,509,981,000
Can some one explain what the meaning of these attributes: ---S--l---? When and why need to set this attribute? and for what? $ ls -ltr ---S--l--- 1 root root 0 Mar 10 04:25/opt/sm/OP/Tor/kur/ll3/tur_lock
I trust that you’re familiar with the basic -rwxrwxrwx notation.  You probably know that set-user-ID gets you -rwsrwxrwx and set-group-ID gets you -rwxrwsrwx.  But, without further clarification, these forms are ambiguous.  If you see -rws------, you might assume that the mode is 04700 (set-user-ID + user read + write + execute), but how do you know that the execute bit is on when x isn’t displayed?  The answer is that mode 04600 (set-user-ID + user read + write, but without execute) is shown as -rwS------.  Similarly, 02060 (set-group-ID + group read + write, but without execute) is shown as ---rwS---. Now, documentation on that l is proving to be hard to find.  Luckily, I’ve been around for a while, and I know where some of the bodies are buried.  I found this fcntl(2) page that says, (Non-POSIX.) … record locks may be either advisory or mandatory, and are advisory by default.  Advisory locks are not enforced and are useful only between cooperating processes. Mandatory locks are enforced for all processes.  If a process tries to perform an incompatible access (e.g., read(2) or write(2)) on a file region that has an incompatible mandatory lock, then the result depends upon whether the O_NONBLOCK flag is enabled for its open file description.  If the O_NONBLOCK flag is not enabled, then system call is blocked until the lock is removed or converted to a mode that is compatible with the access.  If the O_NONBLOCK flag is enabled, then the system call fails with the error EAGAIN. To make use of mandatory locks, mandatory locking must be enabled both on the file system that contains the file to be locked, and on the file itself.  Mandatory locking is enabled on a file system using the "-o mand" option to mount(8), or the MS_MANDLOCK flag for mount(2).  Mandatory locking is enabled on a file by disabling group execute permission on the file and enabling the set-group-ID permission bit (see chmod(1) and chmod(2)). The Linux implementation of mandatory locking is unreliable. See BUGS below. TL;DR On some (non-POSIX?) *nix systems, turning on the set-group-ID mode bit while leaving off the group execute bit enables mandatory locking on that file, if it is enabled in the filesystem.  And so the ls programs on some of these systems show an l (rather than S) in the seventh position of the textual representation of the mode to indicate that mandatory locking is enabled.  So, your tur_lock file has mode 06000. TL;DR2 An S in the fourth position indicates that the set-user-ID (04000) mode bit is set but the user (owner) execute permission (00100) mode bit is off. An S or an l in the seventh position indicates that the set-group-ID (02000) mode bit is set but the group execute permission (00010) mode bit is off. Whether ls displays an S or an l in the seventh position (when the set-group-ID mode bit is set but the group execute permission mode bit is off) is determined by rules that are not clearly documented; but it looks like you get the l if your operating system and filesystem support mandatory file locking.  The l then indicates that mandatory file locking is enabled for this file. You can see the numeric modes (or, at least, the mode bits that are under user control) for all the files and whatnot in a directory tree with a command like find directory -printf "%.5m %p\n" find’s -printf accepts format %m to report the mode numerically (in octal).  (Use %M to report the mode symbolically, as ls does.)  Of course you can specify multiple directories to find, or use options like -mindepth or -maxdepth, or tests like -mtime, -name, -iname, and/or -size to narrow the search, or modify the -printf format. You can see the numeric modes for selected files with a command like stat -c "%a %n" file … stat’s report format (specified with -c or --format) uses %a to report the mode (“access rights”) numerically (in octal).  (Use %A to report the mode symbolically, as ls does.) Both of the above show only the mode bits that are under user control.  To see all the mode bits (including the ones that specify file/inode type), use stat -c "%f %n" file … Unfortunately, this displays it in hex. … is there any option to identify files with ‘S’ …? You can find files that have an S in the fourth position with find directory -perm -4000 ! -perm -100 which is about as close to English as find syntax gets: find files where “permission” (mode) bit 04000 is set but mode bit 0100 is not set. Similarly, you can find files that have an S or an l in the seventh position with find directory -perm -2000 ! -perm -010 Finding files that meet either of the above conditions is a bit messier: find directory "(" "(" -perm -4000 ! -perm -100 ")" -o "(" -perm -2000 ! -perm -010 ")" ")"
File with permissions ---S--l---
1,499,509,981,000
I'm trying to set up a 'deploy' user on my VPS (running CentOS 6 and cPanel) which needs to have access to a specific folder from another home directory: /home/nazeem/public_html/staging. I've created the deploy user succesfully, but logically it didn't have access to the specific home folder of user nazeem. After some reading I discovered that I need to put both users in a group and give the staging folder group permissions. I've added both users to the group deploy, as is displayed in the /etc/group file: deploy:x:32012:nazeem,deploy I also changed the ownership of the folder: drwxrwxr-x 3 deploy deploy 4096 feb 21 20:07 staging/ However, when I cd to the folder as user deploy, I still get the following: -bash: cd: /home/nazeem/public_html/staging: Permission denied Does anybody have any idea how to fix this?
You should also ensure that you have the right to access (go through) the /home/nazeem/public_html and /home/nazeem folders. You can achieve this by doing a chgrp to group deploy on both folders, and setting the execution rights for the group on these folders (execution permission on a directory gives the right to go through it). chgrp deploy /home/nazeem/public_html /home/nazeem chmod g+x /home/nazeem/public_html /home/nazeem
How to give user access to specific folder in home directory
1,499,509,981,000
I'm using rsync to deploy some static HTML that is going to be served by nginx. The user that is running rysnc is "jenkins" nginx is using the www-data group to access the folder. jenkins is member of www-data I ssh onto the Ubuntu 14.04 server in question and run sudo chown -R jenkins:www-data /home/jenkins/thesite then from another machine I run rsync -rtzh --delete --omit-dir-times _site/ jenkins@the_server.com:/home/jenkins/thesite When that has finished some (but not all) of the files now have their group set to jenkins. So nginx can't access them. It doesn't seem to just be the files I've changed that have the permission issue but I'm generating the files using Jekyll which might impact or could just be a massive red herring. In the Windows world I'd set the permissions on the parent folder and tell it to make children inherit. Is there a Linux equivalent or am I doing something silly with rsync?
There are at least a couple of ways to solve this issue. But first let me try and explain how the Linux/Unix world of permissions corresponds to the Windows world. windows has inheritable permissions; Linux systems traditionally don't (but can with ACLs, which I'll ignore for now). Linux permissions are split in to three: owner, group, and everyone else ("other"). Each can have read, write, and execute (files) / search (folders). A file's owner is its creator. The group can be set by the owner to any group of which the owner is a member. With rsync, what you need to try and achieve is the following Owner is jenkins (I assume you can't change that) Group is www-data (so that we can ensure nginx can read the files) Permissions on the target for files are user:read+write, group:read, other:read, and for folders user:read+write+search ("execute"), group:read+search, other:read+search. We can remove other permisions if you prefer We will assume that existing files match the criteria, because you can fix those like this: chown -R jenkins:www-data /home/jenkins/thesite chmod -R u+rw,g=u,g+s,o=u /home/jenkins/thesite Now for the rsync command we need to ignore the Windows file permissions and apply our own criteria: rsync -rptzh --delete --omit-dir-times --chmod=u+rw,go=rX,Dg+s _site/ jenkins@the_server.com:/home/jenkins/thesite The chmod flags for rsync are as follows: u=rw - owner ("user") is to have (at least) read and write permissions go-rX - group and everyone else ("other") are to have write permission removed Dg+s - add the group-setgid bit to folders ("Directories") so that the group name is inherited from the root of the tree
rysnc files and folders into a location without altering permissions
1,499,509,981,000
I am told that the most basic security to set up in Linux is to change the superuser name from root to something obscure so I run these steps to add new user $ /usr/sbin/adduser new_username $ passwd new_usersname then went to give ssh access to new user $ /usr/sbin/visudo root ALL=(ALL) ALL // didn't modify this new_username ALL=(ALL) ALL //added this Now despite the above change, my new user new_username does not have superuser privileges. I am always forced to change to root using su use root privileges. So, what I want is to remove completely the root account, and give all root's power to my new_user How do I accomplish this task ?
Your new user new_username will not have root privileges after editing the sudoers file. This change only allows new_username to run sudo in order to run a task with superuser privileges: $touch testfile $chown new_username testfile chown: changing ownership of 'testfile': Operation not permitted $sudo chown new_username testfile [sudo] password for new_username: $ There are various debates about renaming the root account. It would probably be better to make it secure instead of renaming it.
Unable to get rid of root user and privileges
1,499,509,981,000
I cannot edit/move/delete the sources.list file, despite being root. When I do ls -la /etc/apt it reports this: root@nibelung:~# ls -la /etc/apt/ total 356 drwxr-xr-x 6 root root 4096 Feb 28 21:30 . drwxrwxr-x 100 root root 4096 Feb 28 01:29 .. -rw-r--r-- 1 root root 98 Aug 24 2013 apt.conf drwxr-xr-x 2 root root 4096 Feb 27 14:04 apt.conf.d -rw-r--r-- 1 root root 123 Feb 28 01:52 preferences drwxr-xr-x 2 root root 4096 Feb 27 21:01 preferences.d -rw------- 1 root root 0 Aug 24 2013 secring.gpg -rw-r--r-- 1 root root 878 Jan 24 19:30 sources.list -rw-r--r-- 1 root root 0 Sep 27 02:00 sources.list~ -rw-r--r-- 1 root root 878 Feb 28 21:30 sources.list.bk drwxr-xr-x 2 root root 4096 Feb 27 21:01 sources.list.d -rw------- 1 root root 1200 Jan 24 15:03 trustdb.gpg -rw------- 1 root root 158664 Jan 24 15:03 trusted.gpg -rw------- 1 root root 158664 Jan 24 15:03 trusted.gpg~ drwxr-xr-x 2 root root 4096 Apr 15 2011 trusted.gpg.d
When you try to edit it, what happens? What error do you get? Things to look at first: Is the filesystem mounted read-only? (check mount) Is the file immutable? (check lsattr sources.list; if it's set +i, chattr -i sources.list)
Can't edit sources.list as root
1,499,509,981,000
While loading the KDE UI Linux boots to kdm, then I get a "bad" sound and black screen. Logs reveal the line in the title. I can ctrl - alt - F4 just fine from there. Tried: chmod 755 on /,/home,/home/kellogs Verified I have no SElinux on the machine Removed samba from services that are launched at boot time What else? (logs show $HOME as equivalent to /home/kellogs, so it knows where to go...). Oh, and, it used to work fine until I screwed around with samba... https://i.sstatic.net/R3mGk.jpg
Looking at the screenshot you not only did a chmod 755 on /home/kellogs you also did a chown 755 thus making that directory not owned by user kellogs. So now you can't write to it. You can see this where it says '755' before kellogs. Fix it by running chown kellogs /home/kellogs.
No write access to $HOME directory
1,499,509,981,000
Ubuntu 13.10, Saucy Salamander here. I am trying to install wireshark in order to monitor USB activity with a certain device. The problem is that wireshark does not have access to the USB bus (or any bus, for that matter, no interfaces show up). Here they describe, that wireshark can be run either as root, or as an ordinary user. I tired executing dpkg-reconfigure wireshark-common but after the dialog, nothig happens, and I don't know why. Here an alternative procedure for other Linux users (non-Debian) is outlined. I haven't tried it, as the dpkg method is the recommended one for Ubuntu and I would like to know what is going wrong. Where should I look?
I have also run into this in the past (cant speak for SS specifically) This helped me out. http://ask.wireshark.org/questions/7523/ubuntu-machine-no-interfaces-listed Basically, this is what needs to be done. $ sudo apt-get install wireshark $ sudo dpkg-reconfigure wireshark-common $ sudo usermod -a -G wireshark $USER $ sudo reboot If there are problems, the linked answer provides more information and techniques.
How to set up wireshark with correct permissions [duplicate]
1,499,509,981,000
I have one machine which is machineA and I have a root access to that machine. Now I need to create these below two directories and give permissions to app user. Create ZooKeeper Data directory and give permissions to app : /opt/zookeeper/data Create ZooKeeper Log directory and give permissions to app : /opt/zookeeper/log I have already created those directories in /opt folder by logging as root - root@machineA:/opt# ls -lt drwxr-xr-x 4 root root 4096 Dec 17 13:46 zookeeper root@machineA:/opt/zookeeper# ls -lt drwxr-xr-x 2 root root 4096 Dec 17 13:46 log drwxr-xr-x 2 root root 4096 Dec 17 13:45 data Now I am not sure how to give permissions to app user as mentioned above? I believe this is pretty easy question but I am not sure how to do that?
Use chown to set user and group ownership of files and directories. For example: chown -R app /opt/zookeeper will recursively change ownership of that directory to user app.
How to give permissions to other user after logging as root in Linux?
1,499,509,981,000
I'm running a program (syslog-ng) that must read and write several files in a given path. It was failing at start, claiming that it is unable to open a file in that path. Please, assume this directory structure: /var/platform/program The platform directory has the permission set to 0655 (not execute permission to the owner user). If I change that permissions to 0755, syslog-ng works fine. On the other hand, I have written a small program in C that try to open and write into a file in the same directory, and it works without problem when running as root, but syslog-ng is failing... What can be the problem in this case?
syslog wants probably to chdir to the directory and needs therefore the execute bit set on the directory. See Execute vs Read bit. How do directory permissions in Linux work? for more information.
Process owned by root can't write files
1,499,509,981,000
I have mounted some ntfs drives. /etc/fstab looks like this: /dev/mapper/fedora-root / ext4 defaults 1 1 UUID=b6603ac8-e004-4cd6-b141-9bc95409e32a /boot ext4 defaults 1 2 /dev/mapper/fedora-home /home ext4 defaults 1 2 /dev/mapper/fedora-swap swap swap defaults 0 0 /dev/sda1 /mnt/media ntfs-3g defaults 0 0 /dev/sda5 /mnt/setups ntfs-3g defaults 0 0 /dev/sda6 /mnt/documents ntfs-3g defaults 0 0 I want to change the group of all files at path /mnt/setups/linux [root@localhost linux]# ll total 1075560 -rwxrwxrwx. 1 root root 4256 Sep 22 19:19 adobe-release-x86_64-1.0-1.noarch.rpm -rwxrwxrwx. 1 root root 5255423 Aug 25 07:21 node-v0.10.17-linux-x64.tar.gz -rwxrwxrwx. 1 root root 13637009 Aug 25 07:17 node-v0.10.17.tar.gz I executed the following command: [root@localhost linux]# chgrp -v admin * changed group of ‘adobe-release-x86_64-1.0-1.noarch.rpm’ from root to admin changed group of ‘node-v0.10.17-linux-x64.tar.gz’ from root to admin changed group of ‘node-v0.10.17.tar.gz’ from root to admin But, the group still remains as root [root@localhost linux]# ll total 1075560 -rwxrwxrwx. 1 root root 4256 Sep 22 19:19 adobe-release-x86_64-1.0-1.noarch.rpm -rwxrwxrwx. 1 root root 5255423 Aug 25 07:21 node-v0.10.17-linux-x64.tar.gz -rwxrwxrwx. 1 root root 13637009 Aug 25 07:17 node-v0.10.17.tar.gz
This resolved the problem perfectly: /dev/sda1 /mnt/media ntfs-3g gid=admin,umask=0022 0 0 /dev/sda5 /mnt/setups ntfs-3g gid=admin,umask=0022 0 0 /dev/sda6 /mnt/documents ntfs-3g gid=admin,umask=0022 0 0
Can't change group of files on mount point
1,499,509,981,000
We have build wireshark adding some functionality related to our use, in Scientific Linux 6 system. After this when I start this using normal user, it will not allow me to use the network interface. I have to login via root to do the same. Is there any way that when I click on wireshark, and before the application starts a GUI will appear asking for the password for root? The same as when we open Firewall. Can I do this using a shell script?
Please do NOT run Wireshark as root. Much/most of the large body of wireshark code does not need to (and should not) run as root. There's over 1M lines of code ! If a user is to be allowed to run Wireshark to do network captures, only the separate dumpcap program (which does the actual captures) needs special privileges. See: wiki.archlinux.org/index.php/Wireshark wiki.wireshark.org/CaptureSetup/CapturePrivileges wiki.wireshark.org/Security (Also: a simple google search may help).
How to have a pop-up window for password appear when opening application?
1,499,509,981,000
is it possible to list all the ".php" files located into a direcotry and their octal permissions? I would like to list them like this: 775 /folder/file.php 644 /folder/asd/file2.php etc...
find /folder -name '*.php' -type f -print0 | perl -0 -lne 'printf "%o %s\n", (lstat $_)[2]&07777, $_' See also this related question: Convert ls -l output format to chmod format. -print0 is a GNU extension also supported by BSDs like OS/X. GNU find also has a -printf predicate which could display the mode, but that one has not been added to BSD's find. (Tested on OS/X 10.8.4 and Debian 7 but should work on any system that has any version of perl and find -print0 which includes all GNU systems and all recent BSDs)
MacOsx - Shell - list all .php files and their octal permissions, inside a specifc folder
1,499,509,981,000
I am setting up a LAMP server in VirtualBox for personal development. This will be an Ubuntu Server 12.04 install, and I will be using Virtual Hosts for Drupal, Yii, and other small PHP apps. Ideally I'd like to avoid creating new Virtual Hosts in /var/www and instead opt for creating these under a public_html folder in my user's home directory. Is there any benefit in creating another user (non-root) that will "host" these apps in their home directory, or will the root user created in the setup process suffice? I realise I'm being a bit pedantic by asking this, but its based on a recommendation I saw on another site (can't remember the URL) for setting up a LAMP server for personal development. I imagine this is only critical in a production environment. I'm thinking in terms of permissions, security, etc. EDIT: Will I run into any issues using the root user to this end, or would I be safer creating a new non-root user? EDIT2: Please don't down-vote this post! I would really like some clarity on this as I'm still walking the Linux learning path :)
If this is going to accessible via the network, yes. In order for apache to access the public_html it's going to need some level of access to root's home directory (which could be catastrophic if they somehow found a way, via software vulnerability or unsafe configuration, to add something to root's .bash_profile or something). Run as little as humanly possible under non-root accounts. Running stuff under non-root accounts isn't a "high security" precaution it's a very basic precaution on a par with not setting all your passwords to equal their respective usernames. You're still going to run into attacks even on home systems. My personal public web server and sshd is constantly under attack from outside sources (I never even had to tell anyone it was there). The IP's usually end up in South America or China. Even if you're behind a NAT and firewall, the system can still be potentially targeted. If it's not accessible over the network, then the issue is largely moot, except that personal development should probably reflect the restrictions you're going to be running with in some sort of production scenario. Even if it's not going to ever be "production" it's still good to have the safety guards there so you don't accidentally develop your application so that it requires an unsafe configuration to run properly. EDIT: Another point: if you were to serve the VHost out of root's home directory, that would imply that you're logging in as root directly, which is another very basic security requirement. PermitRootLogin no in sshd_config should also be the effective configuration unless you have one hell of a reason to do otherwise.
LAMP Server setup for personal development
1,499,509,981,000
I've got a problem with UNIX permissions : I'm working under Debian Squeeze, and one of my scripts, run by www-data, needs to move a file, 23550.zip, placed in the home directory of another user, autodo, to a subdirectory in this user's home (/home/autodo/.processed) to mark it as already processed. I tried to change the group ownership of /home/autodo, /home/autodo/23550.zip and /home/autodo/.processed to the group www-data to allow the www-data user to move this file, but it still fails saying Permission denied, as you can see below (as I'm French, I translated french messages back to English, although I can't be sure the translation is the one displayed in English version of these commands) : sh-4.1$ ls -lah /home/autodo total 27M drwxr-xr-x 3 autodo www-data 4,0K 9 janv. 15:17 . drwxr-xr-x 88 root root 4,0K 8 janv. 15:21 .. -rwxr-xr-x 1 autodo ftpusers 4,8K 5 sept. 23:14 19236.zip -rwxr-xr-x 1 autodo www-data 26M 9 janv. 14:26 23550.zip -rwxr-xr-x 1 autodo ftpusers 2,3K 6 janv. 20:44 3194.zip -rwxr-xr-x 1 autodo ftpusers 1,1M 5 sept. 23:38 53274.zip -rwxr-xr-x 1 autodo ftpusers 585 6 sept. 00:50 70069.zip -rwxr-xr-x 1 autodo ftpusers 220 16 nov. 15:10 .bash_logout -rwxr-xr-x 1 autodo ftpusers 3,2K 16 nov. 15:10 .bashrc drwxr-xr-x 2 autodo www-data 4,0K 9 janv. 15:16 .processed -rwxr-xr-x 1 autodo ftpusers 675 16 nov. 15:10 .profile sh-4.1$ ls -lah /home/autodo/.processed total 66M drwxr-xr-x 2 autodo www-data 4,0K 9 janv. 15:16 . drwxr-xr-x 3 autodo www-data 4,0K 9 janv. 15:17 .. -rwxr-xr-x 1 autodo ftpusers 3,8K 8 janv. 22:42 100583.zip -rwxr-xr-x 1 autodo ftpusers 1,7K 9 janv. 02:48 12211.zip -rwxr-xr-x 1 autodo ftpusers 2,2K 8 janv. 22:43 166273.zip -rwxr-xr-x 1 autodo ftpusers 424K 8 janv. 22:52 193894.zip -rwxr-xr-x 1 autodo ftpusers 1,2M 9 janv. 01:13 20662.zip -rwxr-xr-x 1 autodo ftpusers 59M 9 janv. 00:43 22352.zip -rwxr-xr-x 1 autodo ftpusers 1,2M 8 janv. 22:42 23704.zip -rwxr-xr-x 1 autodo ftpusers 214K 9 janv. 02:34 24704.zip -rwxr-xr-x 1 autodo ftpusers 632 9 janv. 01:17 26360.zip -rwxr-xr-x 1 autodo ftpusers 2,8K 9 janv. 01:03 31795.zip -rwxr-xr-x 1 autodo ftpusers 106K 9 janv. 00:11 31797.zip -rwxr-xr-x 1 autodo ftpusers 413K 9 janv. 00:44 31799.zip -rwxr-xr-x 1 autodo ftpusers 4,4K 8 janv. 22:30 31803.zip -rwxr-xr-x 1 autodo ftpusers 2,3K 5 janv. 21:19 3194.zip -rwxr-xr-x 1 autodo ftpusers 13K 8 janv. 23:33 5705.zip -rwxr-xr-x 1 autodo ftpusers 2,8K 8 janv. 22:19 5858.zip -rwxr-xr-x 1 autodo ftpusers 86K 9 janv. 04:34 604.zip -rwxr-xr-x 1 autodo ftpusers 2,6M 9 janv. 03:34 7091.zip -rwxr-xr-x 1 autodo ftpusers 3,4K 8 janv. 21:25 7878.zip -rwxr-xr-x 1 autodo ftpusers 752K 9 janv. 03:37 8127.zip -rwxr-xr-x 1 autodo ftpusers 6,1K 8 janv. 22:01 84846.zip -rwxr-xr-x 1 autodo ftpusers 358K 9 janv. 02:42 989.zip sh-4.1$ id uid=33(www-data) gid=33(www-data) groups=33(www-data),2000(ftpusers) sh-4.1$ mv /home/autodo/23550.zip /home/autodo/.processed/ mv: unable to move « /home/autodo/23550.zip » to « /home/autodo/.processed/23550.zip »: Permission denied I also tried to setgid this user's directory, but it also failed with the same Permission denied, and to adduser www-data ftpusers, but it still failed with the same error. I have to admit that I'm lost; I always thought that the permissions of a group owning a file meant the same than the owner ones, but this problem contradicts this, and I can't think that there can be such a bug in the Linux kernel, so I have to had missed something, but where, dammit!
since a mv is modifying both the "to directory" and the "from directory" you need write permissions on the files you are moving as well as the directories you are moving to/from. chmod -R g+w /home/autodo/ this will recursively add write permissions for group for everything under /home/autodo
Group permissions ineffective, permission still denied
1,499,509,981,000
I have a cron job: #!/bin/bash fn=db.backup.$(date +%m-%d-%y).sql mysqldump -uMyUsr -pMyPass --add-drop-table dbName> $fn find ./ -name '*.Z' -type f -mtime +7 -exec rm -f {} \; I get an error: /backup.sh: line 3: db.backup.10-24-12.sql: Permission denied db.backup.10-24-12.sql: No such file or directory find: ./conf: Permission denied find: ./pd: Permission denied It looks like whatever process is running cron doesn't have permissions to create a file or to run 'find' command.
you should use: fn=/full/path/to/db.backup.$(date +%m-%d-%y).sql or cd /full/path/to/ before you export the database unless your cronjob looks like: * * * * * cd /full/path/to && backup.sh
Cron job - permission denied creating a file
1,350,821,028,000
I want to recursively copy a directory, preserving file attributes, which contains a directory tree including some files that have permission 200 (i.e. --w-------). The copy command cp -ar sourcedirectory targetdirectory skips those files, saying, for each one, something like this: cp: cannot open `sourcedirectory/foo/somefile.bar' for reading: Permission denied` My question: without altering their permissions, how can I prevent the copy command from skipping those files? If you think I ought to use a utility other than cp in my copy command, please explain why.
You must make the file readable in order to copy it. This is unrelated to the choice of tool: every program will fail to open the file for reading since you do not have the permission to read it. If ACLs are enabled (with ext2/ext3/ext4, this requires the mount option acl) and you aren't interested in copying them, add an ACL that allows the user doing the copy to read the file. setfacl -R -m u:username:rX sourcedirectory Otherwise, you'll have to either change the file permissions beforehand and restore them (on both sides) afterwards, or do the copy as root.
Copy files with permission 200
1,350,821,028,000
I am using MySQL v5.1 on Ubuntu machine. MySQL data directory is /var/lib/mysql/ I have a test.dat file located on /var/lib/mysql/tmp/test.dat I would like to load data from the test.dat file into my database table, so I execute the following SQL statement: LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat' INTO TABLE myapp.cars; But I got the following error: Mysql2::Error: Can't get stat of '/var/lib/mysql/tmp/test.dat' (Errcode: 2): LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat' What could be the reason?? P.S. one thing come to my mind is that /var/lib/mysql/ can only be accessed by root user, but I am not sure if it is the reason.
$ ls -ld /var/lib/mysql drwx------ 21 mysql mysql 4096 2011-11-18 14:07 /var/lib/mysql Yes, you have no permissions for that directory (it may be root:root depending on your setup). Use: sudo mysql -u mysqluser -e "LOAD DATA INFILE '/var/lib/mysql/tmp/test.dat' INTO TABLE myapp.cars;" Or just copy the file to your home directory (or wherever) and chown it to yourself.
MySql: LOAD DATA INFILE
1,350,821,028,000
On wikipedia I read the following: The read permission, which grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory (but not to find out any further information about them such as contents, file type, size, ownership, permissions, etc.) With this, is there any way to only let people in my group see (read) the names of a subset of the files/directories I have in a directory? E.g. if I have A ---- B | |----C | |----D can I modify permissions so that members of my groups can only see (read) the names C and D but not B? (if they ls A for example). If this is not possible, what is the rationale behind it? What if I want to completely hide some files I have in my folders? What would the "UNIX way" of dealing with this situation?
Short answer: No. You cannot make only some files in a directory "invisible" to those that do not belong to certain group. Have a look at the question Why do directories need the executable (X) permission to be opened? - the subject is nicely covered there, so I won't just replicate it here. The important thing to understand is that a directory is a separate entity - just as a file - so any permissions can only affect it as a whole.
Permissions for making some some (but not all) files visible directly under a directory
1,350,821,028,000
I'm trying to upgrade to the latest version of DokuWiki, and I'm finding that the easiest way to do this is to install the upgrade plugin and just click a few buttons. But there are permissions issues writing some of the files. How can I briefly change the permissions so that the plugin can work its magic without compromising security?
I don't know anything about DokuWiki, but I can give you some hints with permissions. DokuWiki is a PHP application thus running in a web server. This web server can be Apache, Lighttpd, ngingx and maybe another one. The webserver doesn't run as root. It runs either as the "nobody" user or on Debian servers for example the user is "www-data". It can also be "apache". Ubuntu and Debian use www-data as I said. You can also figure out the permissions in /var/www. Just "cd" to this directory, then type "ls -l" at prompt, and it will give you the list of files with the owner and the group. (there's a www-data group as well). Now that you know which system user the web server runs as, try that: Go to your mediawiki installation directory : cd /var/www/mediawiki Set permissions to the webserver user / group : chown www-data:www-data . -R (-R means "recursive" => all files and subfolders) Finally : chmod 775 . -R Then the webserver user and members of the group can read, write and execute files. As you were wondering for security, the permissions should not be 775 but weaker on most of the files except for some directories like "upload" or "temp" ones that could even be 777. But again, I don't know about mediawiki
Temporary Permissions when installing DokuWiki?
1,350,821,028,000
This doesn't work find / -type d -perm 1000 The problem is, that it matches only the exact permission (1000), but I only want to find out if the sticky bit is set or not. I don't care about the other permissions... My solution so far I feel that there must be a better way than this: find / -type d -perm 1001 -or -perm 1002 -or -perm 1003 -or -perm 1004 -or -perm 1005 -or -perm 1006 -or -perm 1007 -or -perm 1010 -or -perm 1011 -or -perm 1012 -or -perm 1013 -or -perm 1014 -or -perm 1015 -or -perm 1016 -or -perm 1017 -or -perm 1020 -or -perm 1021 -or -perm 1022 -or -perm 1023 -or -perm 1024 -or -perm 1025 -or -perm 1026 -or -perm 1027 -or -perm 1030 -or -perm 1031 -or -perm 1032 -or -perm 1033 -or -perm 1034 -or -perm 1035 -or -perm 1036 -or -perm 1037 -or -perm 1040 -or -perm 1041 -or -perm 1042 -or -perm 1043 -or -perm 1044 -or -perm 1045 -or -perm 1046 -or -perm 1047 -or -perm 1050 -or -perm 1051 -or -perm 1052 -or -perm 1053 -or -perm 1054 -or -perm 1055 -or -perm 1056 -or -perm 1057 -or -perm 1060 -or -perm 1061 -or -perm 1062 -or -perm 1063 -or -perm 1064 -or -perm 1065 -or -perm 1066 -or -perm 1067 -or -perm 1070 -or -perm 1071 -or -perm 1072 -or -perm 1073 -or -perm 1074 -or -perm 1075 -or -perm 1076 -or -perm 1077 -or -perm 1101 -or -perm 1102 -or -perm 1103 -or -perm 1104 -or -perm 1105 -or -perm 1106 -or -perm 1107 -or -perm 1110 -or -perm 1111 -or -perm 1112 -or -perm 1113 -or -perm 1114 -or -perm 1115 -or -perm 1116 -or -perm 1117 -or -perm 1120 -or -perm 1121 -or -perm 1122 -or -perm 1123 -or -perm 1124 -or -perm 1125 -or -perm 1126 -or -perm 1127 -or -perm 1130 -or -perm 1131 -or -perm 1132 -or -perm 1133 -or -perm 1134 -or -perm 1135 -or -perm 1136 -or -perm 1137 -or -perm 1140 -or -perm 1141 -or -perm 1142 -or -perm 1143 -or -perm 1144 -or -perm 1145 -or -perm 1146 -or -perm 1247 -or -perm 1350 -or -perm 1351 -or -perm 1352 -or -perm 1453 -or -perm 1454 -or -perm 1555 -or -perm 1556 -or -perm 1657 -or -perm 1660 -or -perm 1661 -or -perm 1662 -or -perm 1663 -or -perm 1764 -or -perm 1765 -or -perm 1766 -or -perm 1767 -or -perm 1770 -or -perm 1771 -or -perm 1772 -or -perm 1773 -or -perm 1774 -or -perm 1775 -or -perm 1776 -or -perm 1777
Since you are interested in only one specific mode bit, you should be able to use either the -perm -MODE or -perm /MODE syntax. From the man page: -perm -mode All of the permission bits mode are set for the file. Symbolic modes are accepted in this form, and this is usually the way in which you would want to use them. You must specify u, g or o if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. -perm /mode Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify u, g or o if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour of -perm -000). As a usage example, I created two directories and set the sticky bit on one: test$ mkdir sticky-bit-test sticky-bit-test$ mkdir dir-with-sticky sticky-bit-test$ chmod +t dir-with-sticky/ sticky-bit-test$ mkdir dir-without-sticky sticky-bit-test$ ls -l total 8 drwxr-xr-x 2 user group 4096 Jul 19 18:55 dir-without-sticky drwxr-xr-t 2 user group 4096 Jul 19 18:55 dir-with-sticky test$ find . -type d -perm -1000 ./sticky-bit-test/dir-with-sticky test$ find . -type d -perm /1000 ./sticky-bit-test/dir-with-sticky As you see, both options correctly single out the directory with sticky bit set. As noted by @ilkkachu, the distinction between these two is further elaborated in this question.
find command - list all directories with a set sticky bit
1,350,821,028,000
I'm trying to limit the CPU usage of a process using cgroups v2. The hierarchy is already created and the limits are set, I just need to write the pid into the cgroup.procs file. The path is /sys/fs/cgroup/system.slice/myfolder/myfolder/myfolder/cgroup.procs. All the myfolders' permissions are drwxr-xr-x myuser mygroup. The permissions of the cgroup.procs file are -rwxrwxrwx myuser mygroup. Yet, when trying to execute the following command: sudo -H -u myuser bash -c 'echo some_existing_pid > /sys/fs/cgroup/system.slice/myfolder/myfolder/myfolder/cgroup.procs' I get the following error: bash: line 1: echo: write error: Permission denied What can be a possible reason for that? OS: Ubuntu 22.04
My first guess is that you're not allowed to move processes out of their original cgroup. The rule used by the kernel is that in order to migrate a process from cgroup A to cgroup B, you must first have permissions to migrate it to the cgroup that is the common ancestor of both A and B. (I would probably recommend using systemd built-in cgroup hierarchy management, i.e. creating .slice units to define hierarchy and then moving processes into .scope units via systemd-run.)
Limit CPU usage with cgroup v2 as non-root user: permission denied
1,350,821,028,000
I have configured a samba share on my rasbpberry external hdd. [global] workgroup = WORKGROUP log file = /var/log/samba/log.%m max log size = 1000 logging = file panic action = /usr/share/samba/panic-action %d server role = standalone server obey pam restrictions = yes unix password sync = yes passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . pam password change = yes map to guest = bad user usershare allow guests = yes [share] comment = Share Directory path = /media/usbhdd1/Shared/ browseable = Yes writeable = Yes only guest = no create mask = 0644 directory mask = 0755 public = yes force user = pi When writing files from Windows, I get an access denied prompt but it lets me "confirm" the action and ends up writing the file. ls -ld /media/usbhdd1 /media/usbhdd1/Shared drwxr-xr-x 4 pi pi 4096 Jan 27 13:18 /media/usbhdd1/ drwxr-xr-x 3 pi pi 4096 Jan 27 14:05 /media/usbhdd1/Shared/ mount | grep /media/usbhdd1 /dev/sda on /media/usbhdd1 type ext4 (rw,relatime) Am I missing something? I don't think this is how it should behave. Thank you.
Replace the create mask and directory mask lines with, force create mode = 0644 force directory mode = 0755 Because you were using mask entries you've restricted the file permissions on the disk a little too much. These two instructions I've offered set the mode rather then modify it. The permissions should work fine because you've got force user = pi. Without that you'd probably want permission modes 0666 and 0777 respectively.
How to remove windows prompt when writing on a samba share?
1,350,821,028,000
I've noticed that it's possible to open(...) a file with O_CREAT|O_WRONLY flags, but with 0400 mode (that is without w), then write data to the file and close it. This is somewhat contradictory to me, but I can understand how it could work. However, I've recently run into problems with this approach in a CIFS mounted filesystem. Now I'm curious which of the following two statements is true: This is technically (POSIX) an "unsupported/undocumented" feature that just so happens to work on some filesystems. or The fact that it does not work on CIFS a shortcoming of how CIFS is implemented. I've search for an authoritative answer but can't find it. References to some official POSIX standard would be great.
I've noticed that it's possible to open(...) a file with O_CREAT|O_WRONLY flags, but with 0400 mode (that is without w), then write data to the file and close it. This is consistent with how changing the permission bits does not affect the access of already opened file descriptors. Conceptually, you could imagine creating the file with permissions 0600, then opening it in write-only mode, and then changing the permissions to 0400. Just that the system does all that atomically, without letting other processes also open it for writing in the middle. I can't see the description of the open() system call explicitly say that you can do that, but I think it's implied in how O_WRONLY controls the permissions the opened fd gets, and the distinct mode argument controls the permission bits set to the created file. Two different things, and it doesn't say they need to be related in any way. Also, the description of EACCES says: [EACCES] Search permission is denied on a component of the path prefix, or the file exists and the permissions specified by oflag are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created, or O_TRUNC is specified and write permission is denied. i.e. the permission bits only apply for a file that already exist. But I'm not sure how far one can sanely assume the listed standard error conditions could be the only possible error conditions. Insofar as CIFS comes from a somewhat different tradition, I wouldn't expect this to be the only way it differs from "traditional" Unixy filesystems, or the POSIX specifications.
Opening a file with O_WRONLY flag but without write permissions
1,350,821,028,000
I have the following code in a bash file: sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_submit sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_server sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_server_stop sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_server_start sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_status sudo setfacl -m g:jobq:x /usr/local/sbin/jobq_stop sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_submit sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_server sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_server_stop sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_server_start sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_status sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_stop sudo setfacl -x g:jobq:rw /usr/local/sbin/jobq_submit The lines with -m do not give an error message, but the lines with -x say setfacl: Option -x: Invalid argument near character 8 What is wrong here?
setfacl -x only takes a reference to the ACL to remove, not the permissions associated with the ACL: sudo setfacl -x g:jobq /usr/local/sbin/jobq_submit
setfacl -m works but setfacl -x does not work
1,350,821,028,000
I'm attempting to execute the ls command on a directory which has acl permissions for the owner and group of the directory (with no standard posix permissions set). This results in a Permission Denied even though getfacl says the user should be able to do so. Here's what I'm doing: Create a directory and a file inside it. mkdir /tmp/mydir && touch /tmp/mydir/myfile Check if I can execute ls on this directory. jgazula@gazula:/tmp$ ls -al /tmp/mydir/ total 896 drwxrwxr-x 2 jgazula jgazula 4096 Nov 1 11:57 . drwxrwxrwt 25 root root 909312 Nov 1 11:57 .. -rw-rw-r-- 1 jgazula jgazula 0 Nov 1 11:57 myfile Now, let's remove all the standard posix permissions on this directory. chmod 000 /tmp/mydir Verify the permissions. jgazula@gazula:/tmp$ ls -al /tmp | grep mydir d--------- 2 jgazula jgazula 4096 Nov 1 11:57 mydir We shouldn't be able to ls now. jgazula@gazula:/tmp$ ls -al /tmp/mydir/ ls: cannot open directory '/tmp/mydir/': Permission denied Set the acl permissions for the jgazula user and group. sudo setfacl --mask -Rm u:jgazula:rwx,g:jgazula:rwx /tmp/mydir/ Verify the acl permissions. jgazula@gazula:/tmp$ getfacl -ep /tmp/mydir/ # file: /tmp/mydir/ # owner: jgazula # group: jgazula user::--- user:jgazula:rwx #effective:rwx group::--- #effective:--- group:jgazula:rwx #effective:rwx mask::rwx other::--- Since the acl permissions (including the effective permissions) look good, I should be able to execute ls on the directory? jgazula@gazula:/tmp$ ls -al /tmp/mydir/ ls: cannot open directory '/tmp/mydir/': Permission denied But I can't and I don't understand why. Interestingly enough, when I check the standard posix permissions, the group permission bits have been set? Not sure I understand why only group permissions have been updated. jgazula@gazula:/tmp$ ls -al /tmp | grep mydir d---rwx---+ 2 jgazula jgazula 4096 Nov 1 12:13 mydir Let's set the acl permissions for the owner and group (i.e, omit the owner/group from the command). sudo setfacl --mask -Rm u::rwx,g::rwx /tmp/mydir/ Verify the acl permissions again. jgazula@gazula:/tmp$ getfacl -ep /tmp/mydir/ # file: /tmp/mydir/ # owner: jgazula # group: jgazula user::rwx user:jgazula:rwx #effective:rwx group::rwx #effective:rwx group:jgazula:rwx #effective:rwx mask::rwx other::--- Check if I can execute ls now. jgazula@gazula:/tmp$ ls -al /tmp/mydir/ total 896 drwxrwx---+ 2 jgazula jgazula 4096 Nov 1 11:57 . drwxrwxrwt 25 root root 909312 Nov 1 11:57 .. -rwxrwxr--+ 1 jgazula jgazula 0 Nov 1 11:57 myfile Why does step #6 not work by itself? I'm setting the acl permissions explicitly for a user and group. Why do I need to execute step #11?
When you run sudo setfacl --mask -Rm u:jgazula:rwx,g:jgazula:rwx /tmp/mydir/, you are creating an ACL_USER entry for user jgazula. But the ACL_USER_OBJ for the owner of the file is still ---. (You can see this in the getfacl output in step 7.) According to man ACL, the access check algorithm goes: 1. If the effective user ID of the process matches the user ID of the file object owner, then if the ACL_USER_OBJ entry contains the requested permissions, access is granted, else access is denied. 2. else if the effective user ID of the process matches the qualifier of any entry of type ACL_USER, then if the matching ACL_USER entry and the ACL_MASK entry contain the requested permissions, access is granted, else access is denied. So the ACL_USER entry is never even checked. There is essentially the same question on serverfault: ACL: giving - - - permissions for the owner of the file. (But it looks like the answer there got ACL_USER vs ACL_USER_OBJ reversed.)
Why do I get permission denied for a directory with acl set for the owner of the directory (after removing all standard posix permissions)?
1,350,821,028,000
Why does a file with a permission of 0664/-rw-rw-r-- become 0777/-rwxrwxrwx when copied onto an external hard drive? The external drive is NTFS-formatted - does this matter?
It does matter, because the set of attributes and metadata supported for a file vary widely across the various types of filesystems. Specifically, the file-system permissions (and ownership, for that) you are referring to here originate in the traditional Unix user management framework and are therefore a feature of the filesystems developed for/usually used in Unix/Linux operating systems, like the EXT family of filesystems. They are stored in the inode, a special low-level data block describing a filesystem data structure. NTFS comes from the Windows world where users and permissions are handled very differently; in particular, NTFS uses access-control lists to determine which user may do what with a certain file (1). So, when an NTFS drive is mounted on a Linux/Unix system, the file system driver has to "translate" the properties of that drive into something understandable to the Linux tools for handling filesystems, which sometimes can mean substituting data that simply isn't present on the actual fileystem with default values. So, since NTFS has no notion of your local users, and it doesn't control access via ownership/group membership when copying a file from a Unix/Linux-type file system to an NTFS filesystem will lead to a loss of metadata which is then substituted with a default "everyone can do everything". See also External drive chmod does nothing Will permission bits set on a directory on an external hard drive be respected under Windows? (1)and although filesystems used in the Linux world now also support them, they are added "on top" of the traditional permissions, which still form the basis for access handling
File permission change when copying to external hard drive
1,350,821,028,000
I'm doing some reverse engineering on Dell OS10 (Debian Stretch under the hood) for giggles because I think it's really cool how it works and I was looking at one of the files responsible for creating bridges. I wanted to play with it to test how I thought the command flow worked coming from above but even as root, it said it was read-only: "/alt/opt/dell/os10/lib/python/dn_base_br_tool.py" [readonly] 263 lines, 6785 characters Press ENTER or type command to continue So I went and checked the permissions for the mount: root@OS10:/alt/opt/dell/os10/bin# df -P /alt/opt/dell/os10/lib/python/dn_base_br_tool.py | tail -1 | cut -d' ' -f 1 /dev/mapper/OS10-SYSROOT root@OS10:/alt/opt/dell/os10/bin# root@OS10:/alt/opt/dell/os10/bin# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert LICENSE OS10 -wi-ao---- 32.00m SYSROOT OS10 -wi-ao---- 13.50g I went and looked up what -wi-ao means and based on this explanation. Based on that I see the following attribute 2 = writeable attribute 3 = inherited attribute 5 = active volume attribute 6 = open volume I thought maybe there could be an ACL but it doesn't seem like that's it either: root@OS10:/alt/opt/dell/os10/bin# ls -la /alt/opt/dell/os10/lib/python/dn_base_br_tool.py -rw-r--r-- 1 root root 6785 Jun 16 2020 /alt/opt/dell/os10/lib/python/dn_base_br_tool.py The question is - why is that file read only?
Check /proc/mounts to see the actual mount options for the filesystem. lvs only tells about the LVM layer: even when LV has been activated in writeable mode, it is still possible to mount the filesystem in read-only mode if so desired. The file might also be marked "immutable" within the filesystem - see lsattr /alt/opt/dell/os10/lib/python/dn_base_br_tool.py.
Understanding how to read LVM attributes and filesystem permissions
1,350,821,028,000
Background: I'm trying to share a folder between two users on the same machine . The normal way would be to have the two users in the same group set the parent folder to that group with rw and the s bit set. That works great. Except .... the folder I am trying to share is one used by Chromium. When Chromium launches it writes some session files with only owner rw (i.e 600) permission ignroing the s bit. I guess some misbehaved programs can do that. That means when the other user tries later to open that same chromimum profile they can't set those sessions files cause they already exist with the owner only rw of the other user. :( I gave bindfs a try but that requires sudo at login and thus I have to use a sudoers.d file if I want to get that set up non-interactive at login. Anway I gave ACL a try and am not grokking some aspect because it's not working like I think it should. # user1: syadmin # user2: david # directory: /opt/stest # user1 sysadmin is logged in. # sysadmin owns /opt/stest $ llag stest drwxrwsr-x+ 2 sysadmin users 4096 Feb 3 13:45 stest/ $getfacl stest # file: stest # owner: sysadmin # group: sysadmin user::rwx group::rwx other::r-x # now run setfacl -R -m u:david:rwX /opt/stest setfacl -dR -m u:david:rwX /opt/stest # gives user:david:rwx default:user:david:rwx #now create a file as other user $ su david -c "touch /opt/stest/test" -rw-rw-r--+ 1 david users 0 Feb 3 13:51 test #set with owner only rw like how chromium does -rw-------+ 1 david users 0 Feb 3 13:51 test $ getfacl test # file: test # owner: david # group: users user::rw- user:david:rwx #effective:--- group::rwx #effective:--- mask::--- other::--- So this is the part I'm not getting. Why is the "non-acl" owner of the file test david # file: test # owner: david instead of sysadmin given sysadmin owns the directory. Bascially I thought that setfacl would always give access to the directory owner. It seems as though even if the acl entry was made by sysadmin sysdamin must be manually added to any file created by another allowed user or it can get locked out of its own files. That was not intuitive for me. Is that what i need to do? Do I need to run inotify wait on the directory and then add sysamdin to the acl list if another user creates a file. What is the best solution to my situation ACL or otherwise. I am running ubuntu 20.04 with kernel 5.4.0-65- --two days later I tried another tack. I added both users to the file and default acl list using sudo. Then I logged out and into the other user. Then did a getfacl on one of the offending files. You see both users listed but under effective there is nothing instead of rw. Arrgh. Still the current user sysadmin can't access the file created by david. Why is effective not showing rw??? -rw-------+ 1 david david 125146 Feb 6 09:12 Preferences getfacl Preferences # file: Preferences # owner: david # group: david user::rw- user:sysadmin:rwx #effective:--- user:david:rwx #effective:--- group::rwx #effective:--- group:users:rwx #effective:--- mask::--- other::---
Ok, looking like I solved this. I can open chromium from either user with exact same user-dir/profile. The trick is add all users to the acl owners list both for existing files and as default. Then to get the mask set run some chmod commands and do that all recursively. To make this easy I wrote script and it's here. https://gist.github.com/dkebler/23c8651bd06769770773f07854e161fc I will keep it updated and with bug fixes but so far its working for me. If you are going to try it I strongly suggest experimenting on a test directory as you can easily mess things up. I did write in a bunch of confirmations to avoid this but still read the script and use at your own risk. That said here is output from the script showning the commands executed. david@giskard:[common/applications] $ share_dir -o root . sysadmin david share directory /mnt/AllData/users/common/applications/ with users: sysadmin david ? confirm y adding acl user sysadmin these are the acl commands that you will run ****************** sudo setfacl -R -m u:sysadmin:rwX /mnt/AllData/users/common/applications/ sudo setfacl -dR -m u:sysadmin:rwX /mnt/AllData/users/common/applications/ ****************** Double Check. Do you want to continue? y *** new acl entries *** user:sysadmin:rwx default:user:sysadmin:rwx adding acl user david these are the acl commands that you will run ****************** sudo setfacl -R -m u:david:rwX /mnt/AllData/users/common/applications/ sudo setfacl -dR -m u:david:rwX /mnt/AllData/users/common/applications/ ****************** Double Check. Do you want to continue? y *** new acl entries *** user:david:rwx default:user:david:rwx done adding acl users sysadmin david these are the chown/chmod commands that you will run ****************** sudo chown -R root:users /mnt/AllData/users/common/applications/ sudo chmod -R u+rwX /mnt/AllData/users/common/applications/ sudo chmod -R g+rwX /mnt/AllData/users/common/applications/ sudo find /mnt/AllData/users/common/applications/ -type d -exec chmod g+s {} + ****************** Double Check. Do you want to continue? y all done! total 24 drwxrwsr-x+ 2 root users 4096 Feb 6 13:05 ./ drwxrwsr-x+ 5 root users 4096 Feb 6 11:39 ../ -rwxrwxr-x+ 1 root users 169 Jan 30 11:01 'Hacking Chromium.desktop'* -rwxrwxr-x+ 1 root users 161 Jan 30 16:03 'Incognito Chromium.desktop'* # file: /mnt/AllData/users/common/applications/ # owner: root # group: users # flags: -s- user::rwx user:sysadmin:rwx user:david:rwx group::rwx mask::rwx other::r-x default:user::rwx default:user:sysadmin:rwx default:user:david:rwx default:group::rwx default:mask::rwx default:other::r-x here is script (as of 5/24) but I will not be updating this so see the gist for latest #!/bin/bash # Usage: # share_dir [ -o <owner> -g <group> ] <directory> <list of space delimited users names/uid> # use . for current directory # -o forces own for directory, default is $USER # -g forces group name for directory, default is "users" and if not available then $USER # Note: script operates recursively on given directory!, use with caution ## HELPERS adirname() { # passed entire path echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" } chmod_dirs() { # passed entire path local usesudo [[ $1 == -s ]] && usesudo="sudo" && shift 2 $usesudo find $1 -type f -exec chmod $2 {} + } function confirm() { echo -n "$@ " read -e answer for response in y Y yes YES Yes Sure sure SURE OK ok Ok do if [ "_$answer" == "_$response" ] then return 0 fi done # Any answer other than the list above is considered a "no" answer return 1 } # End Helpers # Usage: # adding: acladduserdir <user> <directory> # deleting: acladduserdir -d <user> <directory> # add -s flag to force run as sudo # Note: script operates recursively on given directory!, use with caution acladduserdir() { module_load confirm local uid local usesudo local del local spec local dir local cmd="-R -m " local cmdd="-dR -m" declare OPTION declare OPTARG declare OPTIND while getopts 'ds' OPTION; do # echo $OPTION $OPTARG case "$OPTION" in d) del=true ;; s) usesudo="sudo" ;; *) echo unknown option $OPTION ;; esac done shift $((OPTIND - 1)) if [[ $del ]]; then echo deleting an acl entries for $1 opts="-R -x" optsd="-dR -x" spec="u:$1" else opts="-R -m " optsd="-dR -m" spec="u:$1:rwX" fi [[ ! $2 ]] && echo acluserdir: both user and direcotory must be passed && return 1 dir=$2 uid=$(id -u $1 2>/dev/null) [[ $uid -lt 1000 ]] && echo no such regular user $1 && return 2 [[ ! -d $2 ]] && echo no such directory $2 && return 3 if [[ ! -w $2 ]]; then echo $2 not writable by current user $USER if [[ ! $(sudo -l -U $USER 2>/dev/null) ]]; then echo user does not have sudo privilges, aborting return 4 else confirm "do you want to elevate to root and continue?" || return 5 usesudo="sudo" fi fi echo these are the acl commands that you will run echo '******************' echo $usesudo setfacl $opts $spec $dir echo $usesudo setfacl $optsd $spec $dir echo '******************' confirm Double Check. Do you want to continue? || return 6 $usesudo setfacl $opts $spec $dir $usesudo setfacl $optsd $spec $dir echo '*** new acl entries ***' $usesudo getfacl -p --omit-header $2 | grep $1 } # Usage: # share_dir [ -o <owner> -g <group> ] <directory> <list of space delimited users names/uid> # -o forces own for directory, default is $USER # -g forces group name for directory, default is "users" and if not available then $USER # Note: script operates recursively on given directory!, use with caution share_dir() { [[ ! $(sudo -l -U $USER 2>/dev/null) ]] && echo current user does not have sudo privilges, aborting && return 4 local group local owner=$USER [[ $(getent group users) ]] && group=users || group=$USER declare OPTION declare OPTARG declare OPTIND while getopts 'g:o:' OPTION; do # echo $OPTION $OPTARG case "$OPTION" in o) owner=$OPTARG ;; g) group=$OPTARG ;; *) echo unknown option $OPTION ;; esac done shift $((OPTIND - 1)) local dir=$([[ ! $1 == /* ]] && echo $(adirname $1)/)$([[ $1 == . ]] && echo "" || echo $1) if [[ ! -d $dir ]]; then confirm no such directory $dir, create it? && sudo mkdir -p $dir || return 6 fi shift confirm share directory $dir with users: $@ ? confirm || return 6 for user in "$@"; do echo adding acl user $user acladduserdir -s $user $dir done echo done adding acl users $@ echo these are the chown/chmod commands that you will run echo '******************' echo sudo chown -R $owner:$group $dir echo sudo chmod -R u+rwX $dir echo sudo chmod -R g+rwX $dir echo sudo find $dir -type d -exec chmod g+s {} + echo '******************' confirm Double Check. Do you want to continue? || return 6 sudo chown -R $owner:$group $dir sudo chmod -R u+rwX $dir sudo find $dir -type d -exec chmod g+s {} + echo all done! ls -la $dir getfacl -p $dir }
Sharing a directory between users (using ACL) when some files are created with only owner rw (600) permissions
1,350,821,028,000
I have a file with a secret and a generator application that reads it and generates something similar to a license. There are users on that Linux machine who are allow to use that application. Because that app read that secret file, these users must have read permission to that file. Is there a way to remove the read permission from these users - just let the app read that file through that app only, when these users run it? I want to give only ones who run that app the ability to read that file, and through that file only. Not just cat it and watch its content. I saw a way solving it using chmod 400 secret_file chmod 110 generator chmod u+s generator This way users in the same group as generator can execute generator and can't read secret_file. But because generator is with setuid then generator can read secret_file. This is a nice solution, but I wanted to have the user's name in generator, and using that solution I always get the owner's name. This is how I get the user's name from c/cpp application: #include <pwd.h> uid_t uid = geteuid(); struct passwd *pw = getpwuid(uid); std::string user_name = pw->pw_name; Is there another way to solve this issue? Can somehow apparmor help? (I couldn't understand) A follow up question - is there way to make file executable only through a specific script? What I mean is that I don't want generator to be executed from a shell. I want it to be executed only from another script generator.sh which calls generator, because I do more stuff in generator.sh. I want user who runs bluntly generator to fail, and user who runs generator.sh to succeed.
Use getuid() instead of geteuid(). From the execve() man page: If the set-user-ID bit is set on the program file referred to by pathname, then the effective user ID of the calling process is changed to that of the owner of the program file. The "real" user ID, which getuid() returns is unchanged, that is, it's the UID of the user starting the process. The other thing: I don't want generator to be executed from a shell. I want it to be executed only from another script generator.sh which calls generator, because I do more stuff in generator.sh. is harder, since you can't have setuid scripts. But you could have a setuid wrapper that runs the script (and nothing else), and that script can then run the final binary. Or use sudo to run the script. You might have problems with the shell disliking being setuid, though, see Setuid bit seems to have no effect on bash and Allow setuid on shell scripts . Also note that including the shell may bring more possible issues security-wise, and that with any setuid program, you should be careful to make sure the execution environment is clean. That includes environment variables and file descriptors, but possibly other inheritable features too. One reason to use sudo is that it at least tries to deal with this sort of issues. Another, possibly better way would be to implement the privileged process as a network service instead, and have the users just run a simple dumb client program.
Allow file read only through application
1,350,821,028,000
I am totally new to the Linux world. If I create a new user, does it have read and write permission to its own home directory by default? Logically, it should, but I'm not sure.
Creating a new user means just adding a new entry to a relevant "database". In a most basic (e.g. home) setup the "database" is just text in /etc/passwd file. See man 5 passwd. One can add an entry manually, a relatively safe way is sudo vipw. "Relatively", because you really shouldn't do this manually, especially if you're "totally new in Linux world". Still it's totally possible. Simply adding an entry to the file does not create a home directory, does not alter existing directories, does not change their mode (permissions) or ownership. It's possible to specify a nonexistent directory. In my Debian there's nobody user with /noexistent home directory. This path does not exist. Still I (having root privileges) can start a process as nobody, the user is valid. "Real" users, who want to log in interactively, almost always need and want respective home directories with read and write permissions. Your intuition is quite right: usually they should have them. Basically it's the admin's job to create a setup that works for OS and its users. Here come programs that automate the task of creating users, at least to some degree. E.g. in Debian there is adduser. It can create a new user, create a home directory for the user, copy skeletal files to the directory, set sane ownership and permissions up. Desktop environment (if any) may provide a way to add users via GUI (graphical user interface, i.e. not in a text console) and also set additional things up. If available, such specialized program or functionality is usually the right way to add a new user. In general there may be ways to configure the program to skip some steps, but the default configuration should not surprise you much. To summarize: If I create a new user, does it have read and write permission to its own home directory by default? In general, by default – no, not necessarily, maybe by chance (e.g. if you specify a directory readable and writable for everyone) or if you (the admin) take care of this. In a common distro, by using a user-friendly tool designed to manage users and to create home directories anew – yes (unless explicitly (miss)configured otherwise).
By creating a new user, does it have read and write permission to its own home directory?
1,350,821,028,000
Usecase: I have a lot of production data and copying it for dev purposes would be unreal. I was thinking that OverlayFS could be a solution until a problem with permissions arised. Let's assume i have following folder structure: /data/prod - production data (files+subfolders) owned by prod:prod having 664 /data/prod-overlay/dev1/{overlay,upper,lower} - data for developers (user dev1:dev1 in this case) Dev users can read prod data but not modify. My question is: Is it possible to make files in /data/overlayfs/developer1/overlay writable even when permissions of original files do not allow it? Or is there any other (simple) way to achieve such behaviour while keeping prod data read-only for dev users? For example: There is a file /data/prod/subfolder/file (prod:prod, 664) and user dev1 wants to remove or change /data/prod-overlay/dev1/overlay/subfolder/file. Note: dev1 can remove file /data/prod-overlay/dev1/overlay/file (with rm -f) probably because he is the owner of the overlay folder.
Finally found the answer for my question. 🎉 The solution is to use overlayfs in combination with bindfs that allows mount one folder as another folder with different perms/owner/etc. # sudo bindfs --map=origOwner/newOwner:@origGroup/@newGroup /srcFolder /dstMountpoint mkdir /data/prod-overlay/dev1/prod # mountpoint sudo bindfs --map=prod/dev1:@prod/@dev1 /data/prod-overlay/dev1/overlay /data/prod-overlay/dev1/prod
OverlayFS - Is it possible to make overlay layer writable by anyone/specific user (different than original owner)?
1,350,821,028,000
I have a script that is executed by php so it runs as the www-data user. The script is pretty simple, it basically copies some pre-made files such as the hosts and interfaces files to the correct directories. Maybe update some permissions etc. I thought creating a new user and giving that access to the required commands only through visudo might work but that still requests the user executing the .sh for a password and it plainly does not give the test user permissions. visudo (all permission denied when running ./script.sh) test ALL=(ALL) NOPASSWD:ALL test ALL= NOPASSWD:ALL test ALL=(ALL) NOPASSWD:/bin/cp,/bin/mv,/bin/nano,/bin/chown,/bin/mv When I change the test user to the actual user I'm logged in with, it works. .sh executed by the logged in/www-data user trying to execute the commands as a different user with the required permissions. #!/bin/bash sudo -H -u test cp test.txt /etc/test.txt sudo -H -u test chown test /etc/test.txt echo "ok" What is the best way to enable the www-data user to execute a script that requires root permissions?
The sudoers part you have shown does not make sense. test ALL=(ALL) NOPASSWD:ALL test ALL= NOPASSWD:ALL test ALL=(ALL) NOPASSWD:/bin/cp,/bin/mv,/bin/nano,/bin/chown,/bin/mv You want just one of these lines, probably the last one. Executing echo "ok" with no respect to the exit code of the earlier commands doesn't make much sense either. As far as you have shown there are no sudo permissions for the user www-data. On a normal system sudo -H -u test cp test.txt /etc/test.txt doesn't make sense because the user test cannot create files in /etc. This would only work if the target file exists and has write permissions for the user `test. However, sudo -H -u test chown test /etc/test.txt never makes sense because the only user which can call chown that way successfully is root. solution I guess what you need is this. A script #!/bin/bash cp ~test/test.txt /etc/test.txt && chown test /etc/test.txt && echo 'ok' || echo 'failure' Put that script in a path that is writable only by root Create a sudo permission like this www-data ALL= NOPASSWD:/path/to/script.sh Call the script as www-data like sudo /path/to/script.sh
Best way to have non-root user execute script with commands that require root access?
1,350,821,028,000
I'm having a problem with chmod command. I have a directory with sgid, suid and sticky bit on. If I then run chmod u=rwx {dirname} or chmod g=rwx {dirname} sgid and suid are still on. But if I run chmod o=rwx sticky bit removes. Can anyone explain why it happens?
From man chmod on Debian 10: For directories chmod preserves set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s. To clear these bits for directories with a numeric mode requires an additional leading zero, or leading = like 00755 , or =755 No such explicit guarantee is made for the sticky bit. So the behavior matches the documentation. Why chmod is designed to behave that way is a more difficult question. It might be because set-user-ID or set-group-ID bits may grant additional privileges while the sticky bit on directories causes a further restriction: if the suid/sgid bits are accidentally removed from a directory, the user might or might not be able to put them back on (e.g. an user-owned directory with a group the user is not a member of), and might need to ask the system administrator to help; but in the case of the sticky bit, the user can simply toggle it back on as needed.
Why does chmod o=rwx removes sticky bit while chmod u=rwx and chmod g=rwx don't remove suid and sgid?
1,350,821,028,000
if i have /target mounted with suid and then make a bind-mount on /bound with mount -o bind,nosuid /target /bound, will nosuid take effect on /bound ? (imo it should take effect but i'd still like a definite answer, and nobody else had asked yet here or so it seems)
yes, bind is capable of enforcing nosuid even if the target has suid. here's a test i ran: C source code of a.out: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(){ uid_t uid=getuid(), euid=geteuid(); printf("uid: %u, euid: %u\n",uid,euid); return 0; } and then root@ratma:/# mount -o bind,nosuid /target /bound root@ratma:/# su hans hans@ratma:/$ stat /target/a.out File: /target/a.out Size: 16712 Blocks: 40 IO Block: 4096 regular file Device: 18h/24d Inode: 194454 Links: 1 Access: (6755/-rwsr-sr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2019-12-12 07:52:45.132465174 +0000 Modify: 2019-12-12 07:52:45.132465174 +0000 Change: 2019-12-12 07:53:24.720322010 +0000 Birth: - hans@ratma:/$ stat /bound/a.out File: /bound/a.out Size: 16712 Blocks: 40 IO Block: 4096 regular file Device: 18h/24d Inode: 194454 Links: 1 Access: (6755/-rwsr-sr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2019-12-12 07:52:45.132465174 +0000 Modify: 2019-12-12 07:52:45.132465174 +0000 Change: 2019-12-12 07:53:24.720322010 +0000 Birth: - hans@ratma:/$ id uid=1000(hans) gid=1000(hans) groups=1000(hans),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),109(netdev) hans@ratma:/$ /target/a.out uid: 1000, euid: 0 hans@ratma:/$ /bound/a.out uid: 1000, euid: 1000 success. if it didn't work, it would say "euid: 0" on /bound/a.out :)
does nosuid work on bind-mounts to suid partitions?
1,350,821,028,000
we can grant the permissions as hdfs user for hive as the following su hdfs $ hdfs dfs -chown hive:2098 but how to do the opposite way? in order to verify the owner of hive and hive group?
You can execute the sample command ls hdfs dfs -ls /path And from here this is expected result: For a file returns stat on the file with the following format: permissions number_of_replicas userid groupid filesize modification_date modification_time filename For a directory it returns list of its direct children as in Unix. A directory is listed as: permissions userid groupid modification_date modification_time dirname
how to find the owner of user and group from user HDFS
1,350,821,028,000
So I'm trying to setup a python project and for whatever reason i can't create a file called __init__.py... I've tried doing all the following: vim __init__.py // opens file but can't save sudo vim __init__.py // same as command above echo "" > __init__.py // outputs: bash: __init__.py: Permission denied sudo echo "" > __init__.py // same output as above The directory I'm trying to make these calls in is empty so there are no other conflicting files... Does anyone know what the issue here may be? Update: ls -ld returns drwxr-xr-x 2 root root 4096 Nov 27 09:47 . id returns uid=1000(quinn) gid=1000(quinn) groups=1000(quinn),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),130(lxd),131(sambashare)
The reason that you're unable to create the file in the current directory is that your user (quinn, which the id utility reports) has no write permission in the directory (which is owned by root, which is evident in the ls output). It's not clear whether the directory should be owned by the root user, or why it is owned by the root user, but this is the reason you can't create the file as the user quinn.
Can't create file __init__py, Permission Denied
1,350,821,028,000
I'm running Lamp and installing Wordpress. I used: chown -R personalusername:usergroup /var/www/html/wordpress chmod -R 755 /var/www/html/wordpress But the wordpress can't create the config file using the browser interface. But if I use: chmod -R 777 /var/www/html/wordpress ...it creates the configuration file without problem. Why does the second work and the first not. Why does it have to to be chmod -R 777?
/var/www/* works with www-data:www-data if you are on Ubuntu. So what you need to do is change the ownership to www-data and add yourself to that group using usermod: usermod -aG www-data $USER
Premissions to create files
1,350,821,028,000
I want to delete the folder under root writes an error /var/www ⌚ 16:35:54 $ ll drwxrwxrwx. 2 ftp_user ftp_user 6 апр 24 16:46 cgi-bin drwxrwxr-x 5 nginx nginx 4,0K июл 10 12:42 site.com drwxrwxrwx. 2 ftp_user ftp_user 6 апр 24 16:46 html Write to remove /var/www ⌚ 16:35:56 $ rm -rf site.com rm: it is impossible to remove «site.com/logs»: permissions denied rm: it is impossible to remove «site.com/public»: permissions denied rm: it is impossible to remove «site.com/ocStore-3.zip»: permissions denied Trying to change ownership /var/www ⌚ 16:36:49 $ chown -R root:root site.com chown: change owner "site.com": Operation not allowed Under whom I work /var/www ⌚ 16:42:17 $ whoami root I don't remember what I did or why it became like this. OS Oracle Linux 7.6 UEK Reply to comments $ df /var/www Filesystem 1K-blocks Used Available Used% Mounted in /dev/vda3 18338816 3295488 15043328 18% / $ ls -ld /var/www drwxr-xr-x. 5 ftp_user ftp_user 61 июл 11 19:36 /var/www $ id uid=0(root) gid=0(root) groups=0(root) I come through ssh under root "ssh [email protected] -p 22" Was my zsh(Oh my zsh plugin)
A number of things could be wrong here. From my own experience, I recommend checking the directory attributes with the lsattr utility. Often times I set the immutable bit on files to prevent accidental modification, and to slightly slow down any malicious person from messing with it. If the flag is indeed set, simply remove it: chattr -R -i /var/www
rm -rf root permissions denied
1,350,821,028,000
I have downloaded script called 'linkhandler' in my /bin/ folder, whose content is below. I have given the file permissions, this is the output from ls -lah: -rwxrwxrwx 1 root 861 Jul 8 13:12 linkhandler when I run linkhandler in the command line, I get /usr/bin/linkhandler: 10: /usr/bin/linkhandler: : Permission denied What could be happening? I checked the permissions on the file in the usr folder too. This is the content of the script, if it helps. 1 #!/bin/sh 2 3 # Feed script a url or file location. 4 # If an image, it will view in sxiv, 5 # if a video or gif, it will view in mpv 6 # if a music file or pdf, it will download, 7 # otherwise it opens link in browser. 8 9 # If no url given. Opens browser. For using script as $BROWSER. 10 [ -z "$1" ] && { "$BROWSER"; exit; } 11 12 case "$1" in 13 *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*) 14 setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" >/dev/null 2>&1 & ;; 15 *png|*jpg|*jpe|*jpeg|*gif) 16 curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && feh -a "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; 17 *mp3|*flac|*opus|*mp3?source*) 18 setsid tsp curl -LO "$1" >/dev/null 2>&1 & ;; 19 *) 20 if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR $1" 21 else setsid "$BROWSER" "$1" >/dev/null 2>&1 & fi ;; 22 esac
/usr/bin/linkhandler: 10: /usr/bin/linkhandler: : Permission denied This is an error message from the shell running the script. It's a bit awkward to read, but there's the 10 which might be a line number, and it's worth noting the weird double colon : : before the error message Permission denied. It's as if there should be another string before the second colon, but that string is empty. Your line 10 is [ -z "$1" ] && { "$BROWSER"; exit; } And a potential problem there is that $BROWSER might be empty. That still doesn't explain why the name of the script is there again, or if an empty value would cause that error. So let's try to replicate that: $ cat foo.sh #!/bin/dash unset FOO "$FOO" $ ./foo.sh ./foo.sh: 3: ./foo.sh: : Permission denied On Dash, Debian's and Ubuntu's /bin/sh, the error message for running a command with an empty message looks quite similar, and indeed the script name is duplicated in the error for some reason. (On Bash, the error message would be different.) So, it would appear that the problem is indeed in $BROWSER being empty. You could check for that with [ -z "$BROWSER" ] or supply a default value by using "${BROWSER-/usr/bin/sensible-browser}" with an appropriate path.
Permission Denied with running custom script that has correct permissions
1,350,821,028,000
Snippet of my yaml code: - name: 11|Copy sw-installer.jinja2 response file for unattended installation template: src: "{{ CNTRL_SERVER_RSP_FILE_DIR_LOCATION_FOR_INSTALL }}/sw-installer.jinja2" dest: "/opt/something/{{ ENV_CHOSEN }}/tempLocation/sw-installer.conf" owner: joker group: circus mode: 2777 backup: yes when: - ansible_facts['os_family'] == "CentOS" or ansible_facts['os_family'] == "RedHat" - ansible_distribution_version | int >= 6 - http_dir_path.stat.exists == true - http_dir_path.stat.isdir == true - ChangeDirPermission is defined - ChangeDirPermission is succeeded register: CopyRspFileResult - debug: var: CopyRspFileResult Runtime result: TASK [11|Copy sw-installer.jinja2 response file for unattended installation] ******************************************** changed: [rm-host.company.com] TASK [debug] *************************************************************************************************************** ok: [rm-host.company.com] => { "CopyRspFileResult": { "changed": true, "checksum": "b0f86be744b2b0c767b4861e7a36800708c47ff9", "dest": "/opt/something/unitc/tempLocation/sw-installer.conf", "diff": [], "failed": false, "gid": 4912, "group": "circus", "md5sum": null, "mode": "05331", "owner": "joker", "secontext": "system_u:object_r:usr_t:s0", "size": 8534, "src": "/u/joker/.ansible/tmp/ansible-tmp-1561211521.59-240308852971878/source", "state": "file", "uid": 1124558737 } } Running 2nd time: TASK [11|Copy sw-installer.jinja2 response file for unattended installation] ******************************************** fatal: [rm-host.company.com]: FAILED! => {"changed": false, "checksum": "b0f86be744b2b0c767b4861e7a36800708c47ff9", "msg": "Could not make backup of /opt/something/unitc/tempLocation/sw-installer.conf to /opt/something/unitc/tempLocation/sw-installer.conf.51030.2019-06-22@10:02:12~: [Errno 13] Permission denied: '/opt/something/unitc/tempLocation/sw-installer.conf'"} to retry, use: --limit @/u/sdbmiu/scripts/Ansible/playbooks/webagent/plays/WebAgent_Install.retry PLAY RECAP ***************************************************************************************************************** rm-host.company.com : ok=7 changed=2 unreachable=0 failed=1 Points to note: /opt/something/unitc/tempLocation has permission of 2775 Exact same error appears even if I use /tmp as remote location I'm running as user joker on remote node. So not running as root or sudo. I don't have permission to do that. ansible version ansible 2.7.10 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/company/sdbmiu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Mar 26 2019, 22:13:06) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] Questions: 1. Why does it fails to set appropriate permission when mode: 2777 is specified? But on remote node, permission appear as (5331/--ws-wx--t) 2. Why should backup fail?
As you can see from your debug output, when you set mode to 2777, it is interpreted as a decimal number, so the (octal) mode applied is 05331. You need to change mode: 2777 to mode: 02777 or mode: '2777' for ansible to recognize it as octal. From ansible template module: "You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777) or quote it (like '644' or '1777') so Ansible receives a string and can do its own conversion from string into number."
ansible template module permission error
1,561,054,774,000
I have a directory with the below permissions: drwxrwsr-x 3 john ro 20K Jun 20 14:48 logs I logged in as john and touched a new file inside logs: -rw-r--r-- 1 john ro 0 Jun 20 14:48 d From my understanding, in this scenario, only john should be able to delete the file d. Any other user with group ro should not be able to delete the file since it has only group read access. However when I try to delete using another account for which ro is the group, the file gets deleted! mathew@ip-10-0-0-148:/mnt/custom/ops/logs$ ls -lrth d -rw-r--r-- 1 john ro 0 Jun 20 14:48 d mathew@ip-10-0-0-148:/mnt/custom/ops/logs$ rm d rm: remove write-protected regular empty file 'd'? yes mathew@ip-10-0-0-148:/mnt/custom/ops/logs$ ls -lrth d ls: cannot access 'd': No such file or directory This seems strange!. I want group members to be able to read but not delete a file. What am I missing?
You don't delete files, you remove their entry from a directory. You need directory write permission to do this. (this permission exists in your example). You may want to look at the sticky bit. Apply it to the directory i.e. chmod +t …/logs/d. This will make it so that only the owner (and user with capability CAP_DAC_OVERRIDE e.g. root) can remove a file from a directory. When a file has no directory entries, and is no-longer open by any process, it will be deleted.
User for group able to delete file even though the user has only read access to the file through group
1,561,054,774,000
I'm working on a script for user Bob with the relevant parts shown below. Problem I'm having is if I put this cronjob under user Bob, zenity will work but shutdown wont. And if I put it under root shutdown will work but zenity won't be visible on console. #!/bin/bash eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u Bob gnome-session)/environ)"; someValue=`DISPLAY=:0.0 zenity --text="tell me your value" --entry` ... ... /sbin/shutdown -h "now" I also tried running under root and using su to Bob for zenity and exiting back to root to shutdown, but that didn't work. Is there a way to do this? Other info OS is Linux Mint and Bob is the only user of the machine
Non-privileged users cannot shutdown a machine from command line. If you absolutely need to send shutdown as Bob, you can add him to sudoers using visudo. sudo visudo Add the following line to is: bob ALL = (root) NOPASSWD: /sbin/shutdown -h "now" Save file. Then you can su as bob and test the command: sudo /sbin/shutdown -h "now"
Cron Job Console Connect and Root Permissions
1,561,054,774,000
I am having a really tough time understand user/group permissions. I have spent hours reading and trying things. Here is what I have: Directories Permissions Input 1: ls -lhd Output 1: /var/log: drwxrwxr-x 11 root syslog 4.0K May 10 01:59 . /var/log/mongosqld: drw-rw-r-- 2 mongosqld logstash 4.0K May 10 03:37 . Note: I set this up using chown and chgrp. File Permissions Input 2: ls -lh Output 2: /var/log/mongosqld: total 12K -rw-rw-r-- 1 mongosqld logstash 1.4K May 10 03:43 mongosqld.log Groups: Input: groups logstash mongosqld Output: logstash : logstash mongosqld : users logstash My Question When I try to open a file as the mongosqld user, it tells me open /var/log/mongosqld/mongosqld.log: permission denied. Where I am going wrong.
You can’t access anything in /var/log/mongosqld (unless you’re running as root) because it (the directory) doesn’t have any execute bits set.
Can't open file even though directory/file is owned by user and in group
1,561,054,774,000
I use VirtualBox 6.0.6 on Windows 10 to work in Linux Mint. I use a USB drive with a programming environment on it (Portacle). It contains an executable file (portacle.desktop). I found myself unable to run the file. A window always popped up: The application "portacle.desktop" has not been marked as trusted (executable). Clicking "Launch Anyway" or "Mark as Trusted" achieved nothing. It turned out that the file option "Allow executing file as program" was turned off. However, when I turned it on, it immediately turned itself off. Owner was "mint", changing it resulted in "The group could not be changed. You do not have the permissions necessary to change the group of 'portacle.desktop'", even when running as root. Many people have had similar problems and asked here, and they were told to change attributes/permissions. Changing permissions didn't solve the problem. Changing the owner (even as root) gave the error: chown: changing ownership of 'portacle.desktop': Operation not permitted Trying to see (or change) the file attributes resulted in: lsattr: Inappropriate ioctl for device while reading flags on portacle.desktop Searching that, I found several people with the same problem, but their solutions were specific workarounds not applicable to my case. I also tried moving the files from the USB drive to the main drive. Besides bizarre problems like a folder suddenly being seen as 140 TB in size, the ioctl problem did not go away and everything went more or less along the same lines. Full path of file: /media/mint/3424-9F51/real-lisp/portacle-linux/portacle.desktop Output of mount | grep /dev: root@mint:/media/mint/3424-9F51/real-lisp/portacle-linux# mount | grep /dev udev on /dev type devtmpfs (rw,nosuid,relatime,size=1998648k,nr_inodes=499662,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) /dev/sr0 on /cdrom type iso9660 (ro,noatime,nojoliet,check=s,map=n,blocksize=2048) /dev/loop0 on /rofs type squashfs (ro,noatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) mqueue on /dev/mqueue type mqueue (rw,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) /dev/sda1 on /media/mint/3424-9F51 type vfat (rw,nosuid,nodev,relatime,uid=999,gid=999,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2) Output of df: Filesystem 1K-blocks Used Available Use% Mounted on udev 1998648 0 1998648 0% /dev tmpfs 403956 1092 402864 1% /run /dev/sr0 1927648 1927648 0 100% /cdrom /dev/loop0 1845760 1845760 0 100% /rofs /cow 2019772 49900 1969872 3% / tmpfs 2019772 0 2019772 0% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 2019772 0 2019772 0% /sys/fs/cgroup tmpfs 2019772 4 2019768 1% /tmp tmpfs 403952 28 403924 1% /run/user/999 Output of free: total used free shared buff/cache available Mem: 4039548 1201060 1581880 158384 1256608 2445112 Swap: 0 0 0 Output of du -ks /media/mint/3424-9F51/real-lisp/portacle-linux: 2496752 /media/mint/3424-9F51/real-lisp/portacle-linux
The problem is that the executable on your USB drive cannot be executed with the current mount options (which are default options you did not set yourself). Also, your root/home file system within the virtual machine (VM) does not have enough space to copy over the files and execute them there. Your options are therefore: Remount your USB drive to allow execution of files; and Increase your hard disk space to be able to copy over the program and its files ad 1 - Your mount command shows that the USB drive is mounted at /media/mint/3424-9F51 and it includes the showexec option which prevents the execution. In this situation the command mount -o remount,exec /media/mint/3424-9F51 (run as root, e.g. prepend sudo) should bring the desired result. Please note that the file system is still not a Linux file system and you may run into other problems like filename case sensitivity. ad 2 - In order to resize the disk in the virtual machine you would need to (a) resize the simulated hard disk (often a "qcow2" file) using the appropriate command from the host machine while the VM is shut down, e.g. qemu-img resize /var/lib/libvirt/images/linux_mint.qcow2 +2GB (again run as root, substitute your file name) which would add 2 GB virtual hard disk space. You need at least 2496752k-1969872k which is a little over 514 MB just to copy over the files but then the hard disk would be full; use at least 1 GB more, perhaps much more like 10 GB if you want to work with the program, save files and update the system in the future. (b) resize the system partition of the simulated hard disk, again from outside the VM. Since I do not understand your unusual partitioning setup within the VM (with /cow as an overlay file system apparently on a simulated DVD) this would need more work to figure out. (c) resize the file system on the partition we just resized - again this depends on your setup (d) copy over the files to the newly increased root/home partition, e.g. rsync -uav /media/mint/3424-9F51/real-lisp/portacle-linux /home/mint/ then find your files in /home/mint/portacle-linux and try working from there. Alternatively to 2 (a) to (c) you could add an additional disk to your virtual machine and use this as a /home partition, thereby making space available to continue with (d). This would be easier to set up. Please let us know if you need instructions for that. (You would need to copy/move over all files from your previous /home unless it is OK to "start fresh".)
Can't run file on Linux Mint because of permissions/ownership issues
1,561,054,774,000
I have a simple script that checks if a file has write permission on it or No. If yes, then it allows the user to append some text data to end of file. If No, it kicks user back out. I am following a youtube series for learning Shell scripting by ProgrammingKnowledge. Specifically Video 7. Here is the script: echo -e "Enter file name: \c" read filename if [ -f $filename ] then if [ -w $filename ] then echo "Type some text data. To quit, press CTRL + d: " cat >> $filename else echo "File has no write permissions" fi else echo "$filename is not found" fi My script allows still allows the user to append to the file provided, even if it has no write permission. Other flags like -O or -s are working as expected. What is wrong here? Running ls -l on available files: -r--r--r-- 1 nobody nobody 0 Dec 6 12:25 Mane -r-xr-xr-x 1 root root 165 Dec 6 12:06 Ramy.txt -r--r--r-- 1 root root 0 Dec 6 12:24 Salah The output of running the script with Debug turned on: [root@Console2-4KMH2 scripts]# bash -x ./hello_FILE_TEST_OPERAT_APPEND_2_File.sh + echo -e 'Enter file name: \c' Enter file name: + read filename Salah + '[' -f Salah ']' + '[' -w Salah ']' + echo 'Type some text data. To quit, press CTRL + d: ' Type some text data. To quit, press CTRL + d: + cat My question got resolved. Thanks everyone for all the edits on my rookie post. Stephen Harris in the comments section spotted that I am running the script as a root user, and highlighted that root will write to a file even if said file has no write permissions on it. I created a sudo user, re-ran the script and found it to behave as expected (not writing to file that have no write permissions)
The answer to my question came from the comments section from Stephen Harris. He spotted that I am running the script as root, which will write to any file whether there are write permissions or not.
-w flag in bash if statement not working
1,561,054,774,000
I was reading the official documentation of find online here. And I came across the following part (and I'm bolding the bolded part): ‘-perm -444 -perm /222 ! -perm /111’ Match files that are readable for everybody, have at least one write bit set (i.e., somebody can write to them), but that cannot be executed/searched by anybody. Note that in some shells the ‘!’ must be escaped;. ‘-perm -a+r -perm /a+w ! -perm /a+x’ As above. ‘-perm -g+w,o+w’ As above. I think the last example isn't the same as the first two. It shouldn't be as above. It should go like "Match files that are writable by their group and everyone." Is this correct? Or am I missing something?
Yes, that's a misplaced example... it should be right above the stuff you quoted and below -perm -022 Match files that are writable by both their owner and their group. which, by the way, is the wrong description for 022 (per your comment above that has already been reported and fixed)... The final version should be something like -perm -022 Match files that are writable by both their group and everyone else. -perm -g+w,o+w As above.
'find' -perm example in doc
1,561,054,774,000
The directory won't delete. gentooserver ~ # rmdir /ceph rmdir: failed to remove '/ceph': Operation not permitted I am root. gentooserver ~ # whoami root The directory is owned by root and I have permission to write to it. gentooserver ~ # ls -la /ceph total 16 drwxrwx--x 1 root root 0 Jan 11 2018 . drwxr-xr-x 1 root root 176 Sep 28 16:51 .. There are no attributes set on the directory. gentooserver ~ # lsattr -d /ceph ------------------ /ceph No processes are using the directory. gentooserver ~ # fuser /ceph Nothing is mounted there. gentooserver ~ # umount /ceph umount: /ceph: not mounted. SELinux disabled. Mount command: gentooserver ~ # mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) none on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755) udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=2039250,mode=755) devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) /dev/sda3 on / type btrfs (rw,relatime,lazytime,compress=lzo,ssd,discard,space_cache,subvolid=5,subvol=/) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime) bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=1717) mqueue on /dev/mqueue type mqueue (rw,relatime) configfs on /sys/kernel/config type configfs (rw,relatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev) debugfs on /sys/kernel/debug type debugfs (rw,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime) nfsd on /proc/fs/nfsd type nfsd (rw,relatime) /dev/sda2 on /boot type vfat (rw,relatime,lazytime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/sdf on /mnt/store type btrfs (rw,noatime,space_cache,autodefrag,subvolid=5,subvol=/) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=1632152k,mode=700,uid=1000,gid=1000)
The directory is a btrfs subvolume. Prior to Linux kernel 4.18 (specifically, commit a79a464), these could only be removed via btrfs subvol del /ceph, not with rmdir. See https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs-subvolume for more details.
Mystery undeletable directory
1,561,054,774,000
I typed out the command chfn -o umask=002 souser and expected that souser user would create folders with 775 permission then but he did not. How to get that each new folder created by a certain user would have write permission for the group? Here you are my test: s@lokal:~$ sudo adduser souser Adding user `souser' ... Adding new group `souser' (1002) ... Adding new user `souser' (1002) with group `souser' ... The home directory `/home/souser' already exists. Not copying from `/etc/skel'. Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for souser Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y s@lokal:~$ sudo usermod -aG sudo souser s@lokal:~$ su souser Password: souser@lokal:/home/s$ cd souser@lokal:~$ mkdir test souser@lokal:~$ ls -ld test/ drwxr-xr-x 2 souser souser 4096 Sep 3 14:23 test/ souser@lokal:~$ chfn -o umask=002 chfn: Permission denied. souser@lokal:~$ sudo chfn -o umask=002 souser souser@lokal:~$ mkdir test2 souser@lokal:~$ ls -ld test2 drwxr-xr-x 2 souser souser 4096 Sep 3 14:24 test2 souser@lokal:~$ sudo cat /etc/passwd |grep souser souser:x:1002:1002:,,,,umask=002:/home/souser:/bin/bash souser@lokal:~$ Update #1 After relogin is the same: souser@lokal:~$ mkdir test3 souser@lokal:~$ ls -ld test3 drwxr-xr-x 2 souser souser 4096 Sep 3 14:42 test3 souser@lokal:~$ Update #2 This also did not help: s@lokal:~/Dropbox$ su - souser Password: souser@lokal:~$ mkdir test4 souser@lokal:~$ ls -ld test4 drwxr-xr-x 2 souser souser 4096 Sep 3 14:51 test4 souser@lokal:~$ NOTE: The distro is Debian 9.
The possibilities to set umask's strongly differ between Linux and Unix distro's. The way you are trying to do it (in the "gecos" field in /etc/passwd) depends on pam_umask being installed and configured. AFAIK this is at least the case by default on Debian and probably distro's based on Debian like Ubuntu, Mint, etc... Without pam_umask, you could put a line umask 002 in the shell's profile or rc-file in the users home directory (e.g.: .bashrc or .profile). Or something like this in the system-wide config file, e.g. /etc/profile (for sh, and bash) or /etc/bashrc (for bash only): if [ "$USER" = "souser" ] ; then umask 0002 else umask 0022 fi You can check if it was successful either way with just a plain umask command which will output the current effective umask. Note that it is still up to the application to actually set the permissions. If you use some other program or command which in its code hardwires to never set group write permissions on folder it creates, you'll either have to change the code of that program or set permissions manually afterwards. That is just the way UNIX/Linux is supposed to work.
Make user create 775 permission folders
1,561,054,774,000
I have checked many postings regarding 'Permission denied' error in using scp, but couldn't find the answer for my problem. There are two ubuntu servers (let's say server 'A' and 'B') on the same network in AWS, and when I tried to copy one file to another server, A to B is not working, but from B to A works. (Please see below) On Server 'A', ubuntu@server-a ~ $ ls -alt server* -rwxr-xr-x 1 ubuntu ubuntu 8152 Aug 9 14:26 server.xml.bak ubuntu@server-a ~ $ scp -P 443 server.xml.bak [email protected]:/home/ubuntu/ Permission denied (publickey). lost connection ubuntu@server-a ~ $ scp -P 443 /home/ubuntu/server.xml.bak [email protected]:/home/ubuntu/ Permission denied (publickey). lost connection Also I tried to copy the remote file to here, and it failed as well. ubuntu@server-a ~ $ scp -P 443 [email protected]:/home/ubuntu/sakila.sql . Permission denied (publickey). But from Server 'B', all worked. ubuntu@server-b ~ $ scp -P 443 [email protected]:/home/ubuntu/server.xml.bak . server.xml.bak 100% 8152 8.0KB/s 00:00 ubuntu@server-b ~ $ scp -P 443 sakila.sql [email protected]:/home/ubuntu/ sakila.sql 100% 3153KB 3.1MB/s 00:00 As you see, it is not the permission issue - all operations were done by 'ubuntu' on 'ubuntu' home and files are also owned by 'ubuntu' with 755 mode. So now I'm confused what is wrong.
As suggested, I move my original comment to the answer with more details in case anyone may have a similar issue. I got a hint from @lgeorget 's comment - I ran the command with scp -v and found it's due to missing private key. For security reason, I removed all private keys on servers and use Pageant instead for private key management. In this scenario, I connected to B (B is a bastion server) using PuTTY, opened another PuTTY terminal, connected to B again, and then connected to A via ssh. Therefore the Pageant can handle the private key for B but cannot for A directly (I couldn't recognize this) The result is, scp command from B to target server A works but scp from A to target server B doesn't work. I upload the private key to A for testing and then scp command from A also works fine. Since I can't keep private keys on servers, I think I should only use scp command on server B.
scp permission denied when a user does scp command for owned files on his home directory
1,561,054,774,000
I need to write a STIG rule that will check for all files within a user's home directory, and result in a 1 if any are found to be less permissive than 750. This is what i have made so far. egrep ":[0-9]{4}:" /etc/passwd | cut -d: -f6 | while read line; do if [ ! -e "${line}" ];then exit 1 else if [ `stat -c "%a" "${line}"` -gt 750 ];then exit 1 fi fi done However, this does not work when permissions are a number such as 557. I can't think of a way, at least with my skill level, to get this to work. How would i check all files within a home directory, and have it return 1 if it finds a file that is less permissive than 750? Example: 751,757, 551, 501, 001, 770, 570.. should all fail. My script does not capture all these. To Clarify: I need to ensure NONE of the files in the home directory have ANY "other" attributes. If they have ethier r,w, or x in the "other", it needs to fail. Additionally, in the "group", it needs to only not have w. As long as it cant find any files where the "group" has write or the "other" has read, write, or execute, then it should pass. If it finds theses, it needs to fail. If i could also modify this so that files owned from root are excluded, that would be helpful
if any are found to be less permissive than 750 If the permission bits are 0750, that corresponds to rwxr-x---. Anything that has e.g. bits set in the "other" group, is (basically by definition) more permissive. Similarly, something like 0700 is less permissive (it doesn't give any access to the group). However, something like 0644 / rw-r--r-- would be both more and less permissive, as it would allow read access to "others", but wouldn't allow execute access to anyone. To Clarify: I need to ensure NONE of the files in the home directory have ANY "other" attributes. This, of course, is different than the above definition. But it's also easier to search for files that have some of a set of permissions bits set, so let's do this, instead of looking for files that have only a subset of some set of permissions bits. Assuming you have GNU find, there's the condition -perm /mode, which means "Any of the permission bits mode are set for the file." (see man page). So find -type f -perm /027 would find any regular files that have any of the bits ----w-rwx set. The similar condition in e.g. FreeBSD find is -perm +027 (man page). So, perhaps something in this direction: x=$(find "$dir" -type f -perm /027 -print -quit) if [ "$x" != "" ]; then echo "some files were found" fi
Script to find files less permissive than 750?
1,561,054,774,000
How can I list all users and groups and change their permissions? I try to update Wordpress but my FTP user intranet_admin has not enough permissions and is unable to create a directory. Update WordPress Download the update from https://downloads.wordpress.org/release/en_US/wordpress-4.9.7.zip ... Unzip the updated version ... Directory could not be created. The installation was not successfull Edit: I found out that I can list all users with "cat /etc/passwd". I found this entry: intranet_admin:x:1002:1000::/srv/www/htdocs/wp-intranet:/bin/bash What do I have to change so that the user will have enough permissions for updating wordpress? OT: Wordpress Problem solved! I executed from within the Wordpress root directory: find -type d -exec chmod 755 {} \; find -type f -exec chmod 644 {} \; and then: chown -R wwwrun:ftp-users /path/to/my/wp-directory This solved the problem and I was able to upgrade!
The permission to create a particular directory is not tied to the user account as tightly as you seem to think it is. That is, it's not part of the account's entry in /etc/passwd. A user can create (or delete) a directory in another directory if that other directory is writable by the user or by a group that the user belongs to. This would also permit the user to create/delete files in that directory. Example: $ ls -ld . drwxr-xr-x 2 myself staff 512 May 4 16:29 . Here, only the user myself can create and delete files and directories while everyone is able to access the directory and list the directory content (the x and r permissions). $ ls -ld . drwxrwxr-x 2 myself staff 512 May 4 16:29 . In this case, the myself user as well as all users in the group staff can create and delete files and directories in the current directory.
Change permissions of users and groups? [closed]
1,561,054,774,000
I have a file named file.txt with some contents located in /home/myuser directory and I change the permissions of that file to root.root and 644. -rw-r--r-- 1 root root 1.4K Jan 15 07:09 file.txt Then I switched to myuser and opened it with vim(without sudo) and tried to edit and save it :wq! and I got output like: "file.txt" E949: File changed while writing Press ENTER or type command to continue Then I hit enter and then again :wq! and the output was : WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)? I hit y, the file got saved and exit from vim. The question is why a file with ROOT privileges and read-only access for a user changed by the way? PS: 1. myuser is a sudo user. The user permissions after saving the file changed to myuser.myuser as well. -rw-r--r-- 1 myuser myuser 1.4K Jun 27 18:57 file.txt
Since the file lives in a directory that is writable by the user, the user has permissions to delete and recreate the file. This is more or less what vim does when you force write to the file. $ ls -li file 3481899 -r--r--r-- 1 root wheel 6 Jun 27 15:48 file $ vim file $ ls -li file 3481905 -rw-r--r-- 1 myself myself 6 Jun 27 15:49 file As you can see in this example, the file has been recreated and has a new inode number. The user and group has been set to the user who wrote the file, and the permissions have been set according to the user's umask.
User is able to edit a file using vim
1,561,054,774,000
In Windows when I connect using test_reader account I can access with no problems. However when I use peter account it gives me Access Denied. I did some testing and if I change share folder ownership to peter I can access using peter account and then there's no acccess for test_reader. So only a folder owner can access the share. smb.conf: [share] comment = Venice path = /media/test_folder/share read only = yes create mask = 0650 directory mask = 0760 browsable = yes valid users = @mac write list = peter mac memebrs: mac:x:502:test_reader,peter Folder permissions: drwxrw-r-x 2 test_reader mac 2048 Jun 9 18:23 share I have set smbpasswd for each accounts. Why I cannot access the share using peter account that belongs to the same group as test_reader?
You've got valid users = @mac, so any member of this group can access the share as far as SAMBA is concerned. But you've got write list = peter so only peter can have a chance of writing to the share. However, you also need to overlay UNIX file permissions. You have got drwxrw-r-x 2 test_reader mac, which allows test_reader sufficient access. It does not give any useful access to group mac because you're missing the necessary x bit in the group directory permission. In general, if you're using SAMBA to manage access rights I would suggest that you set the filesystem permissions to be rwxrwxrwx (777). There are exceptions to this, of course, such as when you have users logging in to the server. But for a dedicated fileserver it's a good starting point.
Linux based SMB share: can access only using owner account from Windows [duplicate]
1,561,054,774,000
I ran sudo for qtcreator and now I can't do changes to my project_name.user.creator file. It says that it doesn't have permission. Also I ran ping command with sudo and now I can't use it without sudo. Do you know how to remove it? ls -l /bin/ping -rwxr-xr-x 1 root root 61240 Nov 10 2016 /bin/ping ls -ld /usr/share/applications/*creator* -rw-r--r-- 1 root root 354 Jul 21 2016 /usr/share/applications/qtcreator.desktop ping 8.8.8.8 ping: socket: Operation not permitted sudo ping 8.8.8.8 sudo ping 8.8.8.8 [sudo] password for default: PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=1.22 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=1.38 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=1.29 ms ^C --- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 1.229/1.301/1.380/0.074 ms default@martin-bogdanov:/home$
Explanation When you execute a command with sudo it just means that the user that is executing that command is root. Therefore if the command you are executing creates any files, those files will have the owner and group owner fileds set to root. Depending on the privileges of the files (also the executables), this may prevent other users to read/write/execute them. Example This is the output of ls -l /bin/ping on my computer: -rwxr-xr-x 1 root root 61168 Feb 11 2017 /bin/ping I will explain the -rwxr-xr-x and root root parts. First character (-) represents the type of the file. - Means a regular file. d Means a directory. and so on. Next 3 characters (rwx) represent the actions that are allowed for the owner. r Being able to read a file. w Being able to write to a file. x Being able to execute a file. Next 3 characters (r-x) represent the actions that are allowed for the member of group owner group. r Being able to read a file. - Not able to write to a file. x Being able to execute a file. The last 3 characters (r-x) represents the actions that are allowed for users that are neither the owner nor members of the group owner group. r Being able to read a file. - Not able to write to a file. x Being able to execute a file. root root Means that the owner is the root user and the group owner is the group root. General solution To change the owner and group owner to your user account, you can always use sudo chown username:groupname file_name (groupname is by default same as username if you haven't change it manually.) This will change the fields user to username and group owner to groupname for the file file_name. Solution for specific ping problem As both steeldriver and John WH Smith pointed out, you also need a setuid bit for the ping to work properly. Explanations can be found here and here. Therefore, this will solve problem with ping: sudo chmod u+s /bin/ping
Why is sudo required for every sudo executed executable?
1,561,054,774,000
I have a server where I have folders to be shared over local network (like Photos, Music etc.). I did the following: cd /volumes1/Family/Photos touch .chattrlock sudo chattr +i .chattrlock Now I cannot delete the folder "Photos" but I can still move it within the Family Share. Is there a way to prevent the Folder from being moved inside the share? The folder's permissions should stay rwx.
If a folder itself is not immutable but one or more files inside of it are then you can't delete it but you can, in fact, move or modify it. If you want to make it so that the Photos folder itself can't being moved or deleted but you still want to create files inside of it then you'll need the following command: chattr +a Photos That will make it so that the folder can't be renamed, moved, or deleted but will allow you to create and modify files inside of it unless the files themselves are immutable. If you want to delete files inside then you'll need to first chattr -a Photos and then chattr +a Photos after you're done.
Modify permissions / immovable folder w/o chattr
1,561,054,774,000
I have created a directory called newDir and changed the group it belongs to with mkdir newDir && chgrp test-group newDir. I was user me when I did this. Calling stat newDir produces expected output: File: newDir Size: 4096 Blocks: 8 IO Block: 4096 directory Device: 801h/2049d Inode: 10756102 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 1001/ me) Gid: ( 1003/test-group) Access: 2018-01-27 17:03:07.514864274 +0100 Modify: 2018-01-27 17:03:07.514864274 +0100 Change: 2018-01-27 17:05:08.317543163 +0100 Birth: - Later, logged in as user otherUser, I tried to set the group ID (setgid) permission bit on the directory using chmod g+s newDir. Disappointingly, I see with stat that the permissions haven't changed. I got no error on stderr, though, and the result of the chmod command is 0, as shown by echo $?. Why did chmod g+s newDir have no effect? I'm on Arch Linux 4.14.13.
The reason chmod g+s newDir didn't succeed when executed as user otherUser, was that otherUser wasn't part of group test-group, which is the group of newDir. Switching to a user that is part of test-group and doing chmod g+s newDir works just fine.
Can't set group ID bit on directory
1,561,054,774,000
Running Debian 9, I would like regular users to be able to run alsactl monitor as a trigger for repainting a status bar that shows the current volume - without having to resort to polling. However, alsactl lives in /usr/sbin/, in other words, needs superuser privileges. What is the best way to enable regular users to use this command? To define best: a good compromise between simple and restrictive. In other words, using tools that ship with Debian or are available in the repositories, as well as not having to perform deep changes in the system is a plus, as is keeping the additional rights for the users as limited as possible. Note: I found it incredibly hard to search for this issue, yet I'm almost certain very similar questions have been asked before. If you can point me to a suitable duplicate, I'll be more than happy to delete this.
It should be possible to execute a command from /usr/sbin by using the absolute path to the command. /usr/sbin/alsactl You receive the message "alsactl: command not found" because /usr/sbin is not in the PATH of your non-superuser.
How to allow a regular user to run a superuser command (from /usr/sbin)
1,561,054,774,000
I have a doubt concerning the permissions of folders in my operating system course. Imagine that an ubuntu OS has three users : Lee, Xon, Yugi. Lee creates a parent folder X, and gives full permissions (rwx) to Xon, but gives (---) permissions to Yugi. Xon goes in X and creates a new folder called Y ,and he gives full permissions (rwx) to Yugi on that folder. Since Yugi does not have permission on X would he be able to make use of his permission on Y ? (Knowing that a user must have permissions for the entire path to access a folder)
No Yugi would not as he can't even get past X to get to Y. The lack of execution permission on X for Yugi means he can't even do cd into X to access Y
Permissions folder/parent folder
1,561,054,774,000
dr‐x‐‐‐‐‐x. 3 joey joey 4096 Oct 12 2014 . drwxr‐xr‐x. 4 root root 4096 Oct 12 2014 .. ‐rw‐r‐‐r‐‐. 1 joey joey 18 May 22 2012 .bash_logout ‐rw‐r‐‐r‐‐. 1 joey joey 176 May 22 2012 .bashrc ‐‐w‐rw‐r‐‐. 1 joey ta 111 Feb 16 2014 ourGoal drwxrwx‐‐‐. 3 joey joey 4096 Nov 24 2014 project ‐rw‐r‐‐rw‐. 1 joey ta 492 Mar 11 2015 reportx peter is the member of wm group and John is the member of ta. if the guy(peter,joey,john) wants to read the file(reportx),the minimal permission is it .with x and file with r? or i don't need the x permission of . if (peter,joey,john) want to create a file and edit the file(ourGoal), is it i need .with x and (ourGoal) with w? if (peter,joey,john) want to delete the file(reportx), is it i need . whit x and . with w? This 3 parts i can't really understand, and thx for helping.
Creating and deleting files is based on directory permissions. Since only Joey has access to the directory no one else can create or delete files in that folder. To read the file you need to have r access to it. To write to the file you need to have w access to it. In your case, anyone can read reportx and everyone in the group ta can modify it. Also, anyone can write to ourGoal but only members of ta or joey can read it.
Linux Permission the different between delete and create a file [closed]
1,561,054,774,000
Each process has three user IDs: Real user ID (ruid). Effective user ID (euid). Saved user ID (suid). Similarly, a process has three group IDs: Real group ID (rgid). Effective group ID (egid). Saved group ID (sgid). Based on my understanding, the euid and egid (along with the supplementary group IDs) are used when dealing with permissions. But what about the ruid and suid and rgid and sgid, do they play any role when dealing with permissions?
Actually Linux uses the filesystem user id and group id (plus of course the supplementary group ids) to determine permissions for accessing files; see setfsuid(). Normally those are the same as the effective user ID and group ID. The real and saved user id and group id are never used for the purpose of determining access rights to files, shared memory etc. The real and saved user id are used to determine whether a process can send a signal to another process; see man 2 kill. See man 7 credentials for the complete discussion.
Does ruid and suid and rgid and sgid have anything to do with permissions?
1,561,054,774,000
Earlier versions of Android have at run-as executable with the setuid flag set so it runs as root, but more recent versions do away with that. What changed? How can the shell user effect a user change? I've taken a quick look at the source but my linux coding skills are pretty weak.
Which changed was that runas instead of switching to root user it runs with the SETUID and SETGID capabilities which are based on the executable files extended attributes. Those can be set with the setcap command.
How does android implement run-as without setuid
1,561,054,774,000
Recently I was learning SSH based authentication to connect to a web server.The post recommended certain file permissions.The .ssh folder of the local computer must have directory permission of 700 and the contents inside it for example the keys must have file permission of 640. What doesn't make sense is if I am setting rwx permission for the owner and nothing for the group and others for the directory, then it means the group and others can't list or cd into the directory.Then what's the point of further setting a permission of 640 (ie rw for the group and nothing for others) for the files inside of it?The group or others can't anyway read or move into the directory in the first place.
You are correct that the permissions inside are functionally irrelevant with the given directory structure and permissions, but there's one thing you're missing. Hard links share permissions. In your above example, if you create a hard link (not a symbolic link) pointing to ~/.ssh/id_rsa somewhere else, the resultant file will mirror the permissions from ~/.ssh/id_rsa, and thus people will be able to get to it if their user would have access either through your home directory, or through the new location. As a result, the SSH requirement is actually less stringent than it technically should be (Ideally, your private keys in that directory need to have permissions of 0600, not 0640), but most people don't know or care about hard links any more (they're not hugely useful compared to symbolic links (which can cross filesystem boundaries), or reflinks (which will properly split the link on all cases when one of the links gets written to). As for the other files, there is still some requirement for security there. In particular: The .ssh/authorized_keys file contains info on what other public keys you have access too. The .ssh/known_hosts file contains info on what systems you have connected to (OpenSSH actually provides functionality to protect this without permissions using a one-way hash on the host names and IP addresses). The public parts of your keys can be used to match with .ssh/authorized_keys on other systems to associate accounts, or in theory to attack your private key (though this second case is mostly theoretical unless you're dealing with a government-level adversary). All of those files can be used to figure out other potential locations to steal your information from, and thus should ideally be protected.
Difference between directory and file permissions in this particular scenario
1,561,054,774,000
The following folder has 777 permission however, it is owned by the root. [root@cluster tmp]# ls -la drwxrwxrwt 2 root root 4096 Oct 16 21:53 .X11-unix/ So, a user can not delete his file (vnc lock) in that folder. How can I grant that for all user. Then they will be able to remove their vnc lock without root permission.
The issue you have here is the sticky bit (t) Since you are looking at a directory in this case, the sticky bit stops anyone but the owner of the directory from removing or renaming files within the directory. To allow user to do what you require, you would need to remove the sticky bit from the folder attributes.
777 permission for root owned folder
1,561,054,774,000
When an encrypted directory is mounted using EncFS as a regular user, you cannot execute a script in it with sudo (as root): $ sudo /run/media/yeti/usbdrive/encfs/test.sh sudo: /run/media/yeti/usbdrive/encfs/test.sh: command not found This is a security feature, but how can I still grant root permissions to this mounted directory (without mounting as root)? More details I am using Arch Linux, and I have an encrypted directory using EncFS: sudo pacman -S encfs usbpath="/run/media/yeti/usbdrive" encfs "$usbpath/.encfs" "$usbpath/encfs" echo 'echo hello world' > "$usbpath/encfs/test.sh" sudo chmod +x "$usbpath/encfs/test.sh" Then this command works just like expected: $ /run/media/yeti/usbdrive/encfs/test.sh hello world But when I use sudo, I get an error: $ sudo /run/media/yeti/usbdrive/encfs/test.sh sudo: /run/media/yeti/usbdrive/encfs/test.sh: command not found Then I realized that this is a security feature of EncFS, which is actually quite good. When I do a directory listing as root (after su), I find the following: $ ls /run/media/yeti/usbdrive/encfs/ ls: cannot access '/run/media/yeti/usbdrive/encfs': Permission denied [...] d?????????? ? ? ? ? ? encfs drwxrwxrwx 1 yeti yeti 0 Sep 30 00:31 .encfs [...] But in my case, I am on a system where I am in fact root, and where sudo could be passwordless. Therefore, this security feature is only getting in the way. However, I do not want to mount the encrypted directory as root either (because then I'd need to run my filemanager and other applications as root too). What I did as a workaround to this problem is to copy the file outside of the encrypted directory (cp "$usbpath/encfs/test.sh" /tmp/test.sh), and then execute it as root (sudo /tmp/test.sh). Next to documenting this question for other people who may experience the same issue, the question I still have left is: Is there a better way to do this?
Encfs uses fuse under the hood. It includes an -o option to pass options to fuse. Adding -o allow_root will allow root to access the filesystem in addition to the user mounting (also note the similar but exclusive allow_others flag). To use this option, you will need to enable it in fuse config. In /etc/fuse.conf, add the user_allow_other directive See mount.fuse(8) and encfs(1)
Sudo says "command not found" for script in EncFS (no root access to EncFS mount?)
1,561,054,774,000
I've recently installed vsfptd on my server as I want to offer an ftp to several users. I've decided that everyone would use it as an "anonymous". Every file/folder created/uploaded would however be owned by my account. To do that, I added the following files in my vsftpd.conf chown_uploads=YES chown_username=frederic Problem #1 : However, I am encountering issues where when I create a folder, the owner is not modified and is still "ftp". Problem #2 : When I upload a file, the "chown" correctly works but the permissions are only set to the "user" (x-r) while it should be equal to rwxrwxr-x (as my anon_umask = 0002) For information, here is an extract of my vsftpd.conf file : anonymous_enable=YES anon_root=/home/frederic/Data anon_other_write_enable=YES anon_umask=0002 local_enable=YES write_enable=YES anon_upload_enable=YES anon_mkdir_write_enable=YES chown_uploads=YES chown_username=frederic
Well, After several hours of investigation/testing, I found the solution: Commenting/disabling the chown_uploads made it work and now any change that I make on file_open_mode, anon_umask, etc... work ! Is that a bug ? I don't know but it fixed my issue
Anonymous file and folder permission/owner
1,561,054,774,000
Hello I have tried to deploy django web server for a week and finally I did it, but now I have a permission denied problem with nginx /var/log/nginx/errors.log /2016-07-12_1.png HTTP/1.0", host: "ip" 2017/08/28 08:22:38 [error] 873#0: *122 open() "/srv/www/Best/media/Profile Pictures/1/2016-07-12_1.png" failed (13: Permission denied), client: 94.183.22.168, server: ip, request: "GET /media/Profile%20Pictures/1/2016-07-12_1.png HTTP/1.0", host: "ip" www folder permission drwxr-xr-x 4 root nginx 4096 Aug 27 15:05 www Best (project folder) permission drwxrw-r-- 9 uwsgi nginx 4096 Aug 27 21:27 Best media folder permission drw-rw-r-- 3 uwsgi nginx 4096 Aug 26 12:32 media static folder permission drwxrwxr-x 3 uwsgi nginx 4096 Aug 27 21:22 static
You have set drwxrw-r-- for directories. It should be at least one of the following: drwxrwxr-x - Read, write and execute by the group, all can see contents too. Not recommended unless you really need write access by the group. drwxr-xr-x - Read and execute by the group, all can see contents too. drwxr-x--- - Read and execute by the group. You have not shown the permissions for the files either. This could also be an issue. I have two options for you. Fix each folder and file individually or fix the lot in one go. Fixing the lot in one go may remove any special permissions (like write access) but that can be fixed later too if you know what you are doing. Option 1, set per directory and file: sudo chmod 750 /path/to/each/directory sudo chmod 640 /path/to/each/file Option 2, set for all: sudo find /path/to/www/root -type d -print0 | xargs -0 chmod 750 sudo find /path/to/www/root -type f -print0 | xargs -0 chmod 640 Personally, I would use 750 (drwxr-x---) for directories and 640 (-rw-r----) for files on a website but you may want to use 755 (drwxr-xr-x) and 644 (-rw-r--r--).
CentOS7 nginx permission denied for media and static