date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,433,196,238,000
So I thougt of # visudo but then the thing is I don't want to create a group and then add all users to this group like the following. %users ALL=(ALL) NOPASSWD: /usr/sbin/passwd But is there a way to just reference all users without having to create a group first ?
Just replace %users with ALL: ALL ALL=(ALL) NOPASSWD: /usr/sbin/iptables
How to give all users on the system permission to run the iptables command without a password
1,433,196,238,000
Specific USB Hardware is listed here: ls -l /dev/input/by-id/ The symbolic link: /dev/input/by-id/usb-Metrologic_Metrologic_Scanner-event-kbd resolves to: /dev/input/eventxx where xx is an integer number. In this example event19: ls -l /dev/input/by-id/usb-Metrologic_Metrologic_Scanner-event-kbd lrwxrwxrwx 1 root root 10 Nov 23 22:02 /dev/input/by-id/usb-Metrologic_Metrologic_Scanner-event-kbd -> ../event19 Is there a command that can act upon the symbolic link that will change permissions of the target file? i.e. chmod 666 /dev/input/eventXX Looking forward to the clever and elegant examples.
How about chmod 666 /dev/input/by-id/usb-Metrologic_Metrologic_Scanner-event-kbd I hope that's sufficiently elegant! From the GNU manual for chmod: chmod never changes the permissions of symbolic links, since the chmod system call cannot change their permissions. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. This might be GNU-specific, but since you're running a Linux distribution you've probably got GNU coreutils.
Changing file permissions given its symbolic link
1,433,196,238,000
WARNING: THE NEXT KEY COMBINATION WILL CRASH YOUR COMPUTER Ok, I get that this is an administrative tool and all, but I realized that any user can do ALT + SysRq + C. This link explains what I'm talking about. But only as root I can do something like echo c > /proc/sysrq-trigger and have it actually crash the system. If someone has physical access they can just plug in a keyboard and crash the computer (or server), but it would be even harder for them to get root privileges in a terminal, right? Is there a specific reason as to why it works as non-root from a keyboard but only as root from a console? This is not what I'm looking for. It is talking about an issue with the Fn part on keyboards. It doesn't even allow you to do it with sudo. You have to first su root.
Is there a specific reason as to why it works as non-root from a keyboard but only as root from a console? As far as I understand, the SysRQ magic sequence is handled at a very low level, which doesn't know whether the user on the console is root or not. In fact, it works even when no users are logged in and even while booting. If an intruder or someone that wants to do something nasty has physical access to your machine, you've lost anyway from a security point of view.
In Linux, why do you need to be root to write to /proc/sysrq-trigger?
1,433,196,238,000
I have two users : bob and sally, who resepctively own two files : bob100 and sally100: > ls -altrh /path/to/dir : -rw-r--r--. 1 bob test 0 Jan 7 12:59 bob100 -rw-r--r--. 1 sally test 0 Jan 7 13:06 sally100 drwxrwxrwx. 8 root root 4.1K Jan 7 13:06 . However, BOB can delete files in SALLY's account: > runuser -l bob -c 'rm -f /path/to/dir/sally100' Why is it that bob is allowed to delete a file which clearly only sally has write permissions on?
Because group/others have write permissions on a parent directory. File deletion is actually unlinking it from the directory. The directory is being modified, not the file.
Why can users delete each others files in this case
1,433,196,238,000
I create a file under my user esolve and then su root and use chown to change its user to root then I returned to user esolve I notice I can still delete the file with rm why?
Whether you can create, rename and delete a file does not depend on the ownership and access rights of the file but of those of the parent directory. If you have write access to the directory (in the normal case, it's more complicated with richacl) then you can do this. The exception are directories with the sticky bit (the "SUID"/"SGID" bit for "others", see man chmod) set like /tmp usually. In such directories only the directory owner or the file owner can do this, other users with write access cannot.
why am I able to delete file which belongs to `root` under a non-root user? [duplicate]
1,433,196,238,000
I'd previously used aufs2 in aufs-tools with some luck, but apparently this package has been "superseded" (this is strange term to use for a package which seems to have been removed only because it no longer compiles, but never mind). Okay, so I thought I would try to use unionfs-fuse. I can't for the life of me figure out how to make it work for users though. I'm using this command to make my unified mount: unionfs-fuse /mnt/disk1-pool=RW:/mnt/disk3-pool=RW /mnt/union-pool When I run this as root, I cannot access this share as joe user: $ ls -al /mnt ls: cannot access /mnt/union-pool: Permission denied ... d?????????? ? ? ? ? ? union-pool When I run it as joe user, I cannot access this share as root. I basically get the exact same output as above. This is a little weird to me, root being root. Both root (obviously) and joe user can access the /mnt/disk1-pool and /mnt/disk3-pool mounts. If anybody has any info about aufs-tools for natty I'd also be interested. I am quite fond of this package because it worked.
I suppose (but not tried) that the fuse option -o allow_other, also shown in the example in the unionfs-fuse's man page, could be of help. Edit Try this sudo mount -t aufs -o br:/mnt/disk1-pool=RW:/mnt/disk3-pool=RW \ none /mnt/union-pool that seems to work also without aufs-tools package.
How can I create a unionfs-fuse mount that is readable by all?
1,433,196,238,000
I am trying to use GNU tar to create a tarball from a directory stored on a network drive. This network drive defaults the mode of everything stored on it to 0700 (-rwx------) and cannot be changed prior to the tarball creation. I had used this command to change the permissions of my files stored inside the tarball: tar -c --mode=0644 -f project.tar ./project/ The issue is that everything in the tarball has its permissions changed to 0644 (-rw-r--r--). There are no executables in this ./project/ directory, so 0644 for all files is okay, but directories end up inheriting 0644 as well. Upon extraction on another system, directories cannot be entered until the execute bit is added. Is it possible to instruct GNU tar to change the modes of all files to 0644 and change the modes of all directories to 0755? Almost like -type f and -type d in the find command. OS is version Debian 11 Bullseye, GNU tar is version 1.34.
With GNU tar, you can do: tar --mode a=r,u+w,a+X -cf file.tar directory Which would get you rwxr-xr-x for files of type directory, and rw-r--r-- for every other type (including symlinks, even to directories). That's built as: a=r: resets permissions to r--r--r-- u+w: adds w to user, so rw-r--r-- a+X: adds x to all, but only on files of type directory so rwxr-xr-x for directories and rw-r--r-- for any other type of file. To get full flexibility, you can use star: star cf file.tar -find directory \ -type d -chmod 755 \ -o -type l -chmod 777 \ -o -chmod 644 Where we get rwxr-xr-x for files of type directory, rwxrwxrwx for files of type symlink, and rw-r--r-- for any other type of file. Or using the symbolic forms: star cf file.tar -find directory \ -type d -chmod a=rx,u+w \ -o -type l -chmod a=rwx \ -o -chmod a=r,u+w
specify different --mode values using GNU tar
1,433,196,238,000
I have a folder where files are continuously created from the user root. Some other tool tries to read these files, but it fails because it has no read permissions. How can I make it possible for the user user to read either all files from root, or all files from this directory? Even if new files are always generated.
If the created files have group-read permission, you could change directory group to one which user is member of (chgrp mygroup directory) and enable setgid bit for the directory (chmod g+s /directory). New files created to that directory inherit directory's group. If files have group-read permission but you don't want to use setgid bit you could alternatively use ACLs; set default ACL for directory and allow read permission for group mygroup with setfacl -d -m g:mygroup:rx directory. New files inherit the default ACL.
Allow user to read all files created by root
1,433,196,238,000
I've talked today about the file permissions and used the word octet to describe the rwx unit. Then I wondered if this is a valid name. An internet search shows that it's used here and there. But I wondered if it's not a misuse of the term for the byte. Is this opinion based or is there some valid well-based answer?
This is almost a question for French language… An octet is an 8-bit value, which can take 256 distinct values. An rwx unit is is a 3-bit value, which can take 8 distinct values. Using the word “octet” for an rwx unit would be misleading. The reason octet gets used in English at all is that byte has two meanings: it can mean an 8-bit value, or a value of the smallest addressable unit in the memory of a computer. The second definition is the original one. The first definition came about because most computers had 8-bit bytes. Octet was coined in English to express “8-bit unit” unambiguously: if you implement a typical data format or a network protocol on a computer with 6-bit or 9-bit or 16-bit bytes, you still need to use octets to encode data. Octet has several meanings in English, all of them fairly obscure. The oldest meaning is in music, where it means an orchestra consisting of 8 instruments. By this logic, a grouping of three bits would be a trio. Octet is also used in chemistry, mostly in the expression octet rule, to refer to a grouping of 8 electrons. I'm not aware of any similar word for 3, but there is a duet rule which is similar to the octet rule, so if there was a need for referring to a group of 3 electrons it would make sense to use trio too. Instead of trio, you could use triple or triplet, which are somewhat commonly used in computer programming to refer to a group of three things, a 3-element tuple. Presumably people use octet for a set of rwx bits because this set is commonly expressed with one octal digit. But it clashes with every other meaning of the word, so you shouldn't use it. Besides, Unix systems have file mode bits that don't fit in the rwx trios (e.g. setuid, setgid), and some have permission bits other than r, w and x (for example append-only, permission to delete). So it's better to use a term that doesn't depend on the number of bits. Just say “permission bits”.
Can file permission values be called octets?
1,433,196,238,000
From what I understand about the read permission on directories, it allows listing of which files are in a directory and that's about it. Given a directory with 0744 permissions, owned by userA: [userA@localhost ~]$ mkdir -m 0744 /tmp/semi-secret [userA@localhost ~]$ ls -ld /tmp/semi-secret/ drwxr--r--. 2 userA userA 6 Aug 29 10:15 /tmp/semi-secret/ [userA@localhost tmp]$ touch semi-secret/foobar.txt [userA@localhost tmp]$ chmod 0600 semi-secret/foobar.txt To userB, The existence of the file foobar.txt is apparent from the ls command. [userB@localhost ~]$ ls -l /tmp/semi-secret/ ls: cannot access /tmp/semi-secret/foobar.txt: Permission denied total 0 -????????? ? ? ? ? ? foobar.txt But why does the test -e command exit with a non-zero status?! Its only job is to confirm if a file exists or not, and directory permissions are supposed to allow that. [userB@localhost ~]$ test -e /tmp/semi-secret/foobar.txt || echo "The file doesn't exist." The file doesn't exist.
Since even the stat(2) system call cannot work for any file in a directory that misses the x bit in the permissions, anything that is based on the stat(2) system call will fail in such a directory. If your directory has the r bit set, you are indeed able to read the content of that directory usingreaddir(), but you cannot stat or open any file. In contrary, a directory that has the x bit set, allows you to stat(2) or open files if you know the related file names but you cannot use readdir() to retrieve the content of the related directory. test -e exits with a non-zero status in case that either the file does not exist (after symlink resolution, so that also applies to existing symlinks to non-existing or non-accessible files) or any error occurs while trying to stat(2) the related file.
Why does test -e fail on a file in a directory with only read permissions?
1,433,196,238,000
I wrote a python script to launch several java applications. I want their PIDs to be filed into /var/run/coma. Therefore I wrote the script and gave it 777 permissions just for testing first. -rwxrwxrwx 1 root root 3575 Feb 12 18:20 coma-startup.py When I launch this script as another user and it executes code to create a file into the mentioned dir I receive the following PermissionError: [Errno 13] Permission denied: '/var/run/coma/coma-system.pid' I don't understand this? The script should execute with root privileges in my opinion. What do I not understand here?
Setting the owner and group of a script to root doesn't mean it will be ran as root. When user joe runs an executable, the UID used to define the execution context permissions is the UID of joe, unless you have the set UID (suid) bit enabled. Executables that have suid enabled will run with the UID of the file owner. However, I think your approach has to be very carefully thought, since suid root executables are a security risk. A malicious user can try to escalate priviledges by exploiting them. If that's the only file you need to handle you should work on its permissions instead, or require the user to use sudo. suid root executables should be a last resort on very specific cases. Note: As @psusi remarked on the comments, suid won't work on scripts. This answer describes the issue with suid scripts very well, and why they don't work from kernel 3.x on. So for your particular situation you have only the options of changing permissions on the files/folders you need to work on, or using sudo (first option is more advised).
python script has 777 permission and owner root but still create file is denied
1,433,196,238,000
How do I setup a shared folder / common used folder under linux with standard linux permissions? My requirements are: Only specified users have write permissions. If a user writes a folder other write enabled users shall be able to edit them. (It shall be irrelevant who created a file - the other user shall be able to edit them.) My first try was a group named shared_data and one user and the group owns the directory with ls -l giving drwxrwxr-x 2 user shared_data 4096 Nov 8 18:11 shared_data but if user creates a folder it belongs to the group user and not to the group shared_data. user@shared_folder$ touch test user@shared_folder$ ls -l -rw-rw-r-- 1 user user 0 Nov 8 18:16 test
According to this, you want to set the setgid bit on the directory: $ chmod g+s shared_data All new files created in the directory will have the group set to the group of the directory.
How to create a shared folder
1,433,196,238,000
After setting up LAMP (on Debian) and then looking at /var/www/html's permissions, I was surprised that it is only writeable by root (drwxr-xr-x 1 root root). Presumably PHP scripts can create files in /var/www/html, but surely a PHP script (or it's interpreter) doesn't run in the name of root? Can anyone help me understand whatever I am misunderstanding? EDIT: I installed PHP with apt-get install php5-common libapache2-mod-php5 php5-mysql php5-cli
PHP scripts will run as either: The user running Apache as determined by the User directive in your Apache configuration (usually apache or nobody) if you are using mod_php The user running PHP-FPM if you are using php-fpm So the user a PHP script will execute as will vary. So it's up to you to set the owner and group of /var/www/html (or wherever your DocumentRoot is) accordingly. Furthermore, you may not wish for your PHP application to be able to write (or overwrite) files in your DocumentRoot at all, as this could allow a visitor to a compromised or insecure PHP web application to gain remote code execution privileges. So it's your responsibility to decide whether or not your PHP application is trustworthy enough to allow it to write to files that Apache can serve over the web or even execute. PHP will almost never (and should never!) be run as root for similar reasons to those mentioned above.
Why is /var/www/html writable only by root (by default)?
1,433,196,238,000
I'm setting up rsync to transfer files from ServerA to ServerB, and need to preserve timestamps and permissions. They key here is the files are owned by a different account than the one performing the file transfer. rsync transfers files using the example below: rsync -a /colorschemes/ [email protected]:/colorschemes/ --delete The -a flag yields the following types of errors: rsync: failed to set times on "/colorschemes/946/ex": Operation not permitted (1) rsync: failed to set permissions on "/colorschemes/946/ex/blue.pdf": Operation not permitted (1) On the remote system, the acoder account has a similar error when attempting to manually set permissions on a file: [acoder@bu ~]$ chown apache:codingteam /colorschemes/946 chown: changing ownership of ‘/colorschemes/946’: Operation not permitted This works OK, though: [acoder@bu ~]$ sudo chown apache:codingteam /colorschemes/946 Is there a way to make the remote rsync use sudo?
For using sudo with rsync in remote machine you can call it with --rsync-path="sudo rsync" but be aware of the require TTY, you skip it by removing Defaults requiretty from sudoers file. If you want to change the permission for anything you don't own, you have to use sudo if you were not root or there is a different way like setting a setuid on chmod, chown then any one can run the chmod, chown as a root, but that will be horrible.
forcing sudo on remote rsync server
1,433,196,238,000
So I have a permission problem with my sshfs mount: root@server01:/mnt# sshfs -o uid=$(id -u www-data) -o gid=$(id -g www-data) user@host:/path mountpoint root@server01:/mnt# ls -Zlah total 12K drwxr-xr-x 3 root root ? 4.0K Nov 29 20:00 . drwxr-xr-x 23 root 1001 ? 4.0K Nov 29 13:03 .. drwxrwxrwx 1 www-data www-data ? 4.0K Nov 29 18:53 mountpoint root@server01:/mnt# getfacl mountpoint/ # file: mountpoint/ # owner: www-data # group: www-data user::rwx group::rwx other::rwx root@server01:/mnt# sudo -u www-data ls -lah ls: cannot access mountpoint: Permission denied total 8.0K drwxr-xr-x 3 root root 4.0K Nov 29 20:00 . drwxr-xr-x 23 root 1001 4.0K Nov 29 13:03 .. d????????? ? ? ? ? ? mountpoint Maybe the problem lies here: root@server01:/mnt# mount # unrelated stuff skipped user@host:/path/ on /mnt/mountpoint type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0) Here it says the uid and gid of the mount are both 0, which is root. But on my mount command and when using ls as root, it tells me everything belongs to gid/uid 33 which is www-data.
sshfs = FUSE, you are mounting as root, then trying to access using another user. for a joke / test, you can sshfs as regular user, then switch to root, cd, ohh permission denied, how can root be denied, it's root... run sshfs as the user you want to access. update with example: **test**@mike-laptop4:/mnt$ sshfs [email protected]:/home/mike moo test@mike-laptop4:/mnt$ ls moo/ src mike@mike-laptop4:/mnt$ ls moo ls: cannot access 'moo': Permission denied mike@mike-laptop4:/mnt$ sudo su root@mike-laptop4:/mnt# ls moo ls: cannot access 'moo': Permission denied and vice versa: **mike**@mike-laptop4:/mnt$ sshfs [email protected]:/home/mike moo mike@mike-laptop4:/mnt$ ls moo src test@mike-laptop4:/mnt$ ls moo ls: cannot access 'moo': Permission denied mike@mike-laptop4:/mnt$ sudo su root@mike-laptop4:/mnt# ls moo ls: cannot access 'moo': Permission denied UPDATE, Expand on solutions: Solution 1: mount as the user required to access the data (security preference). $ sshfs [email protected]:/home/mike moo Using this option will allow only the mounting user to access the data. The following 2x solution require (unless mounting as root, root shouldn't be used for sshfs); /etc/fuse.conf user_allow_other Solution 2: allow any user on the box access $ sshfs -o allow_other [email protected]:/home/mike moo Literally any user on the source host can create,edit,delete files, this is a terrible idea in most circumstances, and I can't imaging would ever be allowed in a PCI environment. Not only do you risk all the data on the remote, but you risk a local user manipulating data that can be later used by another local user. Solution 3: allow any user on the box, but honor local filesystem perms. $ sshfs -o allow_other,default_permissions [email protected]:/home/mike moo This option is much more acceptable than the last owing to the fact that only users authorized by the local filesystem will be allowed to access / edit files in the mount. It would also be possible to setup group based permissions.
Owner of sshfs-mounted directory with 777 permission can't open it (no ACL, no SELinux)
1,433,196,238,000
I created the user nils on my Raspberry Pi and want it to be able to access /media/christoph. I tried everything and tried to rage-quit by setting the permissions of that folder recursively to 777 but even that doesn't work. christoph@christoph-pi:~$ su - nils Password: nils@christoph-pi:~$ cd /media/ nils@christoph-pi:/media$ cd christoph/ -su: cd: christoph/: Permission denied nils@christoph-pi:/media$ ll total 12 drwxr-xr-x 3 root root 4096 Mar 25 00:42 ./ drwxr-xr-x 22 root root 4096 Jul 13 16:27 ../ drwsrwsrwt+ 3 christoph git 4096 Aug 6 17:05 christoph/ nils@christoph-pi:/media$ id uid=1001(nils) gid=1001(nils) groups=1001(nils),1003(git) nils@christoph-pi:/media$ logout christoph@christoph-pi:~$ cd /media/ christoph@christoph-pi:/media$ sudo ls -alZ total 12 drwxr-xr-x 3 root root ? 4096 Mar 25 00:42 . drwxr-xr-x 22 root root ? 4096 Jul 13 16:27 .. drwsrwsrwt+ 3 christoph git ? 4096 Aug 6 17:05 christoph How to I grant the user nils permission to enter that folder?
The + is a sign of ACL (Access Control List), to remove all permissions from the user nils and make it available to use the target directory or file, you need to use: setfacl -x u:nils /media/christoph OR you should give permissions by using the command below, for instance if you want it to have read and right permissions you can do: setfacl -m u:nils:rw /media/christoph
User Can't Enter Directory Even Though Permissions are 777
1,433,196,238,000
rsync is not preserving permissions/ownesrship after file transfer. Here is the scenario Source host(192.168.2.14 from where files are copied): Source Path # ls -l "/shareddata/tesz/" total 4 drwxrwsr-x 2 root admin 4096 Sep 15 19:38 web # ls -l /shareddata/tesz/web/ total 0 -rw-rw-r-- 1 askar admin 0 Sep 15 19:38 test1 -rw-rw-r-- 1 dey admin 0 Sep 15 19:38 test2 Destination Path: # ls -ld /shareddata/ drwxrwxr-x. 4 root admin 4096 Sep 15 19:44 /shareddata/ The rsync command we tried to copy the files is . The script is running under fsync user $ id fsync uid=700(fsync) gid=502(admin) groups=502(admin) /usr/bin/rsync -rogp 192.168.2.14:/shareddata/tesz /shareddata/ /usr/bin/rsync -av 192.168.2.14:/shareddata/tesz /shareddata/ We are running the rsync command from the destination host where the files are copied to. But we can see that permissions/ownership not getting preserved after file transfer $ ls -l /shareddata/ total 8 drwxrwsr-x 3 fsync admin 4096 Sep 15 19:44 tesz $ ls -l /shareddata/tesz/ total 4 drwxrwsr-x 2 fsync admin 4096 Sep 15 20:29 web $ ls -l /shareddata/tesz/web/ total 0 -rw-rw-r-- 1 fsync admin 0 Sep 15 20:29 test1 -rw-rw-r-- 1 fsync admin 0 Sep 15 20:29 test2 What are the modifications I need in rsync command so that permissions are preserved.
As mentioned in the comments the remote rsync process needs to be run with superuser privileges to be able to preserve permissions. If you have sudo access on the remote server you can use the --rsync-path option to run rsync as root: rsync -av --rsync-path "sudo rsync" source/ server:/destination/
rsync command not preserving permissions
1,433,196,238,000
I have a directory of subdirectory and files, with the files' permissions set at 0664. The directory and subdirectories are set at 2775, so all new files made have the same group set as the directory. New files made in the directories have permissions set to 0644. Is there anything that can be done to make new files have the permissions set to 0664 instead, in a similar fashion to using setgid for the group owner of the files?
umask 002 Files (and directories) after this will be created with 0664 permissions.
How to make new files have 0664 permissions rather than 0644?
1,433,196,238,000
I want to find list of all suid binaries. I use the command find / -perm 4000 However this does not give me any output. I understand that the SUID file may be in 4xxx permission mode. But if I issue the command find / -perm -4000 (which all websites tell) or the command find / -perm +4000 both give me the same result. As far I understand it should always be +4000 (because if it is user suid binary then the first byte should be 4, if group suid binary then the first byte should be 2 and if a sticky bit turned on directory then the first byte should be 1). Then how come -4000 also give results?
The use of -perm +mode seems to be deprecated. Maybe the help from man find can help to resolve your doubt: -perm mode File's permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example -perm g=w will match only files which have mode 0020 (that is, ones for which group write permission is the only permission set). It is more likely that you will want to use the ‘/’ or ‘–’ forms, for example -perm -g=w, which matches any file with group write permission. See the EXAMPLES section for some illustrative examples. -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 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). -perm +mode Deprecated, old way of searching for files with any of the permission bits in mode set. You should use -perm /mode instead. Trying to use the ‘+’ syntax with symbolic modes will yield surprising results. For example, ‘+u+x’ is a valid symbolic mode (equivalent to +u,+x, i.e., 0111) and will therefore not be evaluated as -perm +mode but instead as the exact mode specifier -perm mode and so it matches files with exact permissions 0111 instead of files with any execute bit set. If you found this paragraph confusing, you're not alone – just use -perm /mode. This form of the -perm test is deprecated because the POSIX specification requires the interpretation of a leading ‘+’ as being part of a symbolic mode, and so we switched to using ‘/’ instead. Reference: find (GNU findutils) 4.4.2
Using find -perm to find setuid files
1,433,196,238,000
My apologies if this is the wrong Stack Exchange for this sort of question — it seems like the most appropriate. Which yum package should I install to get the setfacl command on my linux virtual server running Cent OS 6. Or is yum not the way to do this? Or does Cent OS 6 have a different way of setting up ACLs? Or something else? I'm a developer — I've setup a virtual server with a VPS hosting company. They're imaged a virtual machine with Cent OS for me. However, I don't have access to the setfacl command. I need this command to correctly setup directory access for my Symfony log and caching folders (per their instructions). My assumption is my VPS host set me up with a very bare installation and I need to have some security or access related package installed, but I can't seem to google up that package myself. I plan on asking their support — but 1. We know how awful support can be sometimes, and 2. I'd like to know from the experts what the "right" way to do this is in case support is as awful as I think they'll be. Any help is appreciated — (and don't worry, I only plan to use this VPS for IP restricted development)
To find out what package provides the setfacl command: sudo yum whatprovides "*/setfacl" Here is what I get from running this command: Loaded plugins: downloadonly, refresh-packagekit, rhnplugin This system is receiving updates from RHN Classic or RHN Satellite. acl-2.2.49-5.el6.x86_64 : Access control list utilities Repo : rhel-x86_64-workstation-6 Matched from: Filename : /usr/bin/setfacl acl-2.2.49-6.el6.x86_64 : Access control list utilities Repo : rhel-x86_64-workstation-6 Matched from: Filename : /usr/bin/setfacl acl-2.2.49-4.el6.x86_64 : Access control list utilities Repo : rhel-x86_64-workstation-6 Matched from: Filename : /usr/bin/setfacl acl-2.2.49-6.el6.x86_64 : Access control list utilities Repo : installed Matched from: Filename : /usr/bin/setfacl So, as you can see, if it weren't already installed, I would need to install the acl package in order to install the setfacl utility.
Installing `setfacl` on Cent OS 6
1,433,196,238,000
I want to change permissions of all 777 folders to 755 and also change all 777 php files to 644. How can I do this through shell? P.S: all files and directories are in www directory.
You can change the permissions of all 777 folders to 755 using find as below. find /var/www -type d -perm 777 -print -exec chmod 755 {} \; The above command will change all the directories inside /var/www to have the permission set as 755. To verify it, you can use the below command. stat -c "%a %n" /var/www/directory-name To change the permissions of all php files, you can use the below command. find /var/www/some-directory -type f -name "*.php" -perm 777 -print -exec chmod 644 {} \; Again, you can use the stat command to verify if the permissions had changed. Or you can even use, ls -ld /var/www/some-directory-name Both stat and ls -ld will display the octal permissions of the file.
Permission change to exclusively all folders (or .extension files)
1,433,196,238,000
I'd like to create a new partition and move the contents of the /var directory to it for the security reason of having /var/www and other subdirectories "mounted" with nosuid, noexec, and nodev permissions. How do I do it for /var or any other root directory?
Actually, a slight modification to warl0ck's plan (because I'm paranoid) create the new partition boot to single-user mode mount the new partition as /new_var or something, and rsync as described you might as well run aptitude autoclean before running rsync, to reduce the amount getting copied over (or even ... clean if you don't mind re-downloading your apt cache) move /var to /old_var so you don't lose it right away, and then mount the new partition as /var there may be live logs or pid files in old_var - if you don't mind losing whatever changed since re-starting, you can ignore those edit fstab so the new partition will mount as /var on future boots, and reboot to normal multi-user mode if all that went well, you can sudo rm -fr /old_var when you're sure it's working. If anything breaks, you still have old_var around
Moving a root directory to a separate partition
1,433,196,238,000
(this question possibly related to Linux: simulating/masking user ownership upon mount of 'external' partitions? - Stack Overflow) I typically use Ubuntu (currently 11.04) as my desktop OS; let's say there, I'm the user myself with uid=1000, part of the group myself with gid=1000; so basically the home directory permissions look like this: > stat ~ File: `/home/myself' ... Access: (0755/drwxr-xr-x) Uid: ( 1000/ myself) Gid: ( 1000/ myself) Now, on the same machine I sometimes need to boot OpenSuse (currently 11.2) through a LiveUSB (Live-CD). All of that works fine for me, except that the default user in a Live-CD environment is linux with uid=999, part of the group users with gid=100; so there the home directory permissions look like this: > stat ~ File: `/home/linux' ... Access: (0755/drwxr-xr-x) Uid: ( 999/ linux) Gid: ( 100/ myself)   So, basically, when I mount my Ubuntu drives (which are owned by 1000:1000) under the live OpenSUSE (whose default user is 999:100), I fail to access them as usual, i.e.: linux@linux:~> touch /media/extdrive/xxx touch: cannot touch `/media/extdrive/xxx': Permission denied   So, I thought I should try to change the default uid/gud for linux:users on the OpenSUSE machine, so I tried this: > sudo /usr/sbin/usermod -u 1000 linux usermod: Account `linux' is currently in use. > id linux uid=999(linux) gid=100(users) groups=100(users),33(video) # so if that fails.... change directly from /etc/passwd? > sudo nano /etc/passwd > id linux uid=1000(linux) gid=100(users) groups=100(users),33(video) ... and just having the uid changed, makes me access the Ubuntu drives fine - however, now I cannot access the OpenSUSE stuff previously owned by linux:users: > sudo nano /etc/fstab sudo: unknown uid: 999 ... so, it turns out, bad idea to change /etc/passwd directly :) The solution here seems to have been to drop to root shell first, do the usermod command, reboot - and now I have on from the OpenSUSE environment: linux@linux:~> stat ~ Access: (0755/drwxr-xr-x) Uid: ( 1000/ linux) Gid: ( 100/ users) This makes me - for the most part - have access to the Ubuntu filesystems/drives as usual; while also having usual access to whatever is owned by the default user in OpenSUSE.   However, to be on the safe side, I'd also like to change the group ID. What would be the recommended way of doing this ( and what would the recommended way be to change the uid, if I didn't do it right in the discussion above )? Many thanks in advance for any answers, Cheers!
If I understand your question correctly, you can use find's -gid condition: find /media/extdrive -gid 100 | sudo xargs chown myself:myself or if you prefer find's -exec: sudo find /media/extdrive -gid 100 -exec chown myself:myself {} + or, looking at chown's manpage, it has a --from option you may find useful: sudo chown -R myself:myself --from=:100 See the appropriate manpages for more information.
Changing user and group ID system wide (including file system attributes)?
1,433,196,238,000
I'm running into an odd issue on my Mac (macOS 10.14.3). I ran sudo du -xk / to get detailed data on my disk usage, and ran into several errors: du: /Users/brx/Library/Application Support/MobileSync: Operation not permitted du: /Users/brx/Library/Application Support/CallHistoryTransactions: Operation not permitted du: /Users/brx/Library/Application Support/com.apple.TCC: Operation not permitted du: /Users/brx/Library/Application Support/CallHistoryDB: Operation not permitted du: /Users/brx/Library/IdentityServices: Operation not permitted du: /Users/brx/Library/Messages: Operation not permitted du: /Users/brx/Library/HomeKit: Operation not permitted du: /Users/brx/Library/Mail: Operation not permitted du: /Users/brx/Library/Safari: Operation not permitted du: /Users/brx/Library/Suggestions: Operation not permitted du: /Users/brx/Library/Containers/com.apple.VoiceMemos: Operation not permitted du: /Users/brx/Library/Containers/com.apple.Home: Operation not permitted du: /Users/brx/Library/Containers/com.apple.Safari: Operation not permitted du: /Users/brx/Library/Containers/com.apple.iChat: Operation not permitted du: /Users/brx/Library/Containers/com.apple.mail: Operation not permitted du: /Users/brx/Library/Containers/com.apple.news: Operation not permitted du: /Users/brx/Library/Containers/com.apple.stocks: Operation not permitted du: /Users/brx/Library/PersonalizationPortrait: Operation not permitted du: /Users/brx/Library/Metadata/CoreSpotlight: Operation not permitted du: /Users/brx/Library/Metadata/com.apple.IntelligentSuggestions: Operation not permitted du: /Users/brx/Library/Cookies: Operation not permitted du: /Users/brx/Library/Caches/com.apple.safaridavclient: Operation not permitted du: /Users/brx/Library/Caches/com.apple.HomeKit.configurations: Operation not permitted du: /Users/brx/Library/Caches/CloudKit/com.apple.Safari: Operation not permitted du: /Users/brx/Library/Caches/com.apple.Safari: Operation not permitted du: /Users/brx/Library/Caches/com.apple.homed: Operation not permitted This is strange because I should have permissions to these directories even without sudo. If I open them in Finder, I can see the contents fine, but in Terminal: ~/Library/Caches$ ls -la com.apple.homed/ ls: : Operation not permitted ~/Library/Caches$ sudo ls -la com.apple.homed/ ls: : Operation not permitted ~/Library/Caches$ ls -lade@ com.apple.homed/ drwxr-xr-x 7 brx staff 224 Mar 18 14:36 com.apple.homed/ So there's no ACLs nor extended attributes. I own the directory so I should be able to list it! Yet if I do open /Users/brx/Library/Caches/com.apple.homed/, a Finder window pops up with the contents (three files Cache.db{,-shm,-wal} and a directory called fsCachedData). What's going on here?
I believe that it is macOS's SIP (System Integrity Protection) that stops the du and ls processes from accessing the files/directories, even when running as root. SIP appears to be, since macOS Mojave, active for a number of locations under ~/Library, which means that only trusted applications can access them. I added my terminal application (iTerm2) to the list of applications that should be granted "Full Disk Access", and I did that in the "Security & Privacy" Systems Preferences settings, under the "Privacy" tab. This seems to have solved it for me. I say "seems" as I'm no macOS expert, but I believe this is what made me able to access everything under ~/Library. Apple recommends not turning off SIP globally on the system, for obvious reasons, and I don't see a real reason to do so either.
Can't list directory even as root?
1,433,196,238,000
Is there a man page for the file permission numbers? I'm specifically talking about r = 4 w = 2 x = 1 I can never remember them and I have to google it every time I need to set permissions besides 755. I don't think I'm alone, either, since there's even a site that calculates the number for you. I just realized the man page for chmod doesn't have any description of the numbers and I can't figure out what other page would have them. I guess an info page would work as well, since apparently it comes pre-installed (I have arch; I'd have thought I'd have had to install that one myself--apparently not). It would be a lot easier for me if I could just refer to an 'on-line' man page (I use 'on-line' in the sense used in man man).
man chmod is likely to give you the command line tool. This may include some text that is easy to miss The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1) If you do man 2 chmod then you get the system call that actually does the work. This is harder to read, but does include the magic numbers: S_IRUSR (00400) read by owner S_IWUSR (00200) write by owner S_IXUSR (00100) execute/search by owner ("search" applies for direc- tories, and means that entries within the directory can be accessed) S_IRGRP (00040) read by group S_IWGRP (00020) write by group S_IXGRP (00010) execute/search by group S_IROTH (00004) read by others S_IWOTH (00002) write by others S_IXOTH (00001) execute/search by others It also provides some other magic values: S_ISUID (04000) set-user-ID (set process effective user ID on execve(2)) S_ISGID (02000) set-group-ID (set process effective group ID on execve(2); mandatory locking, as described in fcntl(2); take a new file's group from parent direc- tory, as described in chown(2) and mkdir(2)) S_ISVTX (01000) sticky bit (restricted deletion flag, as described in unlink(2))
Man page for file permission numbers
1,433,196,238,000
Please read this long intro to understand my concern for why we need the SUID permission for executable binary file. A process in Linux uses its EUID to know the effective User ID of itself. This user's permission is used to decide how this process interacts with other files (ex. whether this process can write to a file) Consider the scenario with changing password via /usr/bin/passwd Real life Linux Passwords are stored in /etc/shadow. This file belongs to root with permission (rw-------) If $passwd has permission rwx--x--x, this means only root can change the logic of passwd program. When userA runs the program, a passwd process starts with RUID = EUID = userA Result is: the program will run. A passwd process is started but it won't be able to change the password since its EUID is userA and userA can't write to /etc/shadow. This is when the need for SUID permission arrives. SUID allows setting EUID of a process upon execution of a binary to create that process. the EUID will be set to the owner of that binary file. Setting SUID permission for owner of /usr/bin/passwd makes EUID of any passwd process started by any user takes the EUID of root Since root can write to /etc/shadow, any user can use the passwd program to start a passwd process which can make changes to /etc/shadow There is SUID permission because in Linux, EUID of a process is not hard set to the owner of the executable binary file (which when run, will create that process) My ideal Linux No need for SUID permission. If executable file binA is created (and owned) by userA, any users who can execute binA will create a process with EUID = userA. In the context of the changing password scenario, the logic of this idea is as follows: root is the owner of /usr/bin/passwd and only root can change its logic. The logic inside /usr/bin/passwd lets a user change its password only and not others'. Other users can't modify /usr/bin/passwd, only root can. /etc/shadow can only be writen to by root Result is: An unprivileged user userA can execute $passwd. He will create a passwd process. This process has EUID = root so it can write to the shadow file. With this theory, we can achieve: everyone can change their own password (and only their own password) without SUID permission.
Both your examples explain how setuid works. However in your "ideal Linux" every executable would start with EUID of the owner of the executable, which would make every executable on your system a setuid executable. This would clearly cause a lot of problems, to mention a few: every root owned executable would need to do UID checks and call setuid() to set process' EUID back to non-root if the program shouldn't have any additional privileges; users can not make executables available to another users, as the process would run with wrong EUID; configuration errors and bad practices would have critical consequences (such as chmod 777 would now also allow access to any files owned by user). And these are more. Normal permissions without setuid binaries need some other mechanism to allow unprivileged users to do privileged operations. Setuid binaries allow such privilege elevation and access control is implemented in program logic.
why do we need the SUID permission? [closed]
1,433,196,238,000
gentoo /var/log/redis # ls -al total 8 drwxrwxr-x 2 root redis 4096 12月 3 16:05 . drw-rw-r-- 5 root root 4096 12月 3 15:57 .. -rwxrwxrwx 1 redis redis 0 12月 3 16:05 redis.log gentoo /var/log/redis # sudo -u redis redis-server /etc/redis.conf *** FATAL CONFIG FILE ERROR *** Reading the configuration file, at line 175 >>> 'logfile /var/log/redis/redis.log' Can't open the log file: Permission denied I can run redis-server with root user, but I need run it with redis user. And then it print this error log. OS & redis version: Linux gentoo 4.12.12-gentoo #1 SMP Wed Oct 4 09:05:50 CST 2017 x86_64 Virtual CPU a7769a6388d5 GenuineIntel GNU/Linux Redis server v=4.0.2 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=4504b17bcfd3837e
I add x permission into /var/log, and the problem has been solved.It seems that redis should have a x permission at parent dir. Now my /var/log is 701.
Redis logfile permission error, but the permission is already 777
1,433,196,238,000
I created a new user golden in linux by running adduser command. After that I am trying to generate ssh keys for that new user and every time I am getting permission denied error: golden@machineA:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/golden/.ssh/id_rsa): Could not create directory '/home/golden/.ssh': Permission denied Any thoughts what is wrong? Update: golden@machineA:~$ pwd /home/golden golden@machineA:~$ ls -l total 0 golden@machineA:~$ ls -lrth total 0 golden@machineA:~$ ls -lrtha total 20K -rw-r--r-- 1 10001 10001 675 May 10 11:54 .profile -rw-r--r-- 1 10001 10001 3.5K May 10 11:54 .bashrc drwxr-xr-x 2 10001 10001 4.0K May 10 11:54 . -rw-r--r-- 1 10001 10001 220 May 10 11:54 .bash_logout drwxr-xr-x 8 root root 4.0K May 10 15:44 .. Update2: golden@machineA:~$ ls -ld /home/golden drwxr-xr-x 2 10001 10001 4096 May 10 11:54 /home/golden golden@machineA:~$ id golden uid=1001(golden) gid=1002(golden) groups=1002(golden)
The owner of /home/golden is user 10001, not user golden. Normally, when you create an account, this creates a home directory for the user, and that home directory would of course belong to the user. The reason this didn't happen here is probably that /home/golden already existed. Depending on the options you passed to adduser, it may or may not have told you about this. The reason /home/golden existed is presumably because there used to be an account called golden with the user id 10001, then this account was removed without deleting the home directory. Now there is a user account called golden again, but with a different user ID. Assuming that this is what happened, and user 10001 no longer exists, you can change the ownership of /home/golden to the new account. Of course this allows the new user to see the files that the old user left behind, but in your case there are no interesting files anyway. sudo chown -R golden:golden /home/golden If you delete an account, you should either remove its home directory (deluser --remove-home) or rename it (mv /home/golden /home/golden.1001.archived).
New user cannot create files in its home directory
1,433,196,238,000
I'd like to know if I can create a file on a server that has all directories set to 777 permission, such that the no ordinary user (non-root) is able to delete the file. If so, do I have to be root user on the system, or can I do it as an ordinary user too? My initial thoughts are, I should just be able to use "chmod 0444" on the file and that should take care of it. I would have tried this out myself but I don't have access to a Linux server.
You may add the “sticky bit” (with chmod +t) to your directory. With this bit set, files in the directory can only be deleted by their owner. You may also give the file the “immutable” attribute (with chattr +i). With this attribute, nobody can modify or delete the file.
Is it possible to create a file that cannot be deleted by an ordinary user even if all directories have 777 permission?
1,433,196,238,000
In the standard library for ecliptic curve cryptography one of the C source files has the executable bit set, qv: As you can see there are multiple C files, but only the secp2561k1.c file is executable. This is just as I downloaded it. Why would just this one source code file have its execute bits set?
There is no reason for a C source file to be executable. This may sometimes happen if the file has been transferred from or through a non-Unix operating system. You may safely remove the execute bit if you wish: $ chmod a-x secp256k1.c
Why would a source file have the execute bit set?
1,433,196,238,000
I have 2 users on a system, user1 and user2. Here is the md5sum of authorized_keys for each: de092f77fb4a3be2cd8864c5f9961149 user1/.ssh/authorized_keys de092f77fb4a3be2cd8864c5f9961149 user2/.ssh/authorized_keys Here is a list of the .ssh folder for each: user1/.ssh/: total 8 drwx------. 2 user1 user1 28 Mar 16 12:11 . drwxrwx---. 5 user1 user1 4096 Mar 16 12:11 .. -rw-------. 1 user1 user1 412 Mar 16 12:11 authorized_keys user2/.ssh/: total 4 drwx------. 2 user2 user2 28 Mar 16 11:37 . drwx------. 3 user2 user2 90 Mar 16 11:38 .. -rw-------. 1 user2 user2 412 Mar 16 11:37 authorized_keys Here is authentication with each: user1: debug1: Next authentication method: publickey debug1: Offering RSA public key: /Users/me/.ssh/id_rsa debug3: send_pubkey_test debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password user2: debug1: Next authentication method: publickey debug1: Offering RSA public key: /Users/me/.ssh/id_rsa debug3: send_pubkey_test debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 60 debug1: Server accepts key: pkalg ssh-rsa blen 279 /etc/passwd: user1:x:1001:1001::/home/user1:/bin/bash user2:x:1004:1004::/home/user2:/bin/bash In other words, I can log in with public key using user2, but not user1. Logging in with password works fine for both. I have no clue why this works with one user and not the other. And I need to get public key authentication to work with user1 (because I need to run scripts with an sshagent using public key authentication) I am lost where to look for why this is not working. All guides online ask to check the key, the permissions, and regenerate. But all of the above looks correct. I find no mention of user1 in the /etc/ssh folder. And if I provide the password, the login works fine. Please note, I have edited the user names to anonymize the relevant data.
The issue was the permission on the home folder, it allowed group to write.
SSH public key not working for specific user [closed]
1,459,101,796,000
How do I change the permissions of an executable file to access the /etc/shadow file? So far I have the following bash script: #!/bin/bash gcc print.c -o print chmod +s print ./print exit 0 and the following c-code: #include <stdio.h> #include <stdlib.h> int main() { FILE *open = fopen("/etc/shadow", "r"); int tmp; do { tmp = fgetc (open); printf("%c", tmp); } while (tmp != EOF); fclose(open); return 0; } I can easily print the /etc/passwd file, but I get a dumped core once I try to access the /etc/shadow file.
To give a binary permission to run things as root, you need to set the "sticky bit" on the binary. Normally after compiling, you might see: # ls -l print -rwxr-xr-x 1 mark mark 111 24 Oct 17:32 print Setting the set-uid (sticky) bit can be done using and octal mode, or symbolically (note that you will need "root" privileges in order to change the ownership of a file): # chown root print # chmod o-x print # chmod u+s print # ls -l print -rwsr-xr-- 1 root mark 111 24 Oct 17:32 print In the first version, the s in the permissions, as you already figured out, indicates that this is both executable and "set-uid". But you have to changed the ownership of the file also, so that "set-uid" sets the uid of root rather than your own user. At this point, the "group" hasn't changed its value, but that's not important in this particular case. (Though it might be a factor for security.) The final line above shows permissions that can also be expressed as an octal number, so if this is the result you want, then you could replace the two chmod lines above with a single one: # chmod 4754 print Have a look at the man page for chmod for more details. If this isn't what you're looking for, please clarify your requirements in your question. IMPORTANT NOTE: the /etc/shadow file is kept private for a reason. If you expose it with something that can be run by other users, you may compromise the security of your system. Removing world executable permission is a "nod" towards security, but if you feel that you need to expose /etc/shadow in this way, you may be solving the wrong problem.
print the /etc/shadow file in the console
1,459,101,796,000
To make some item X world-readable, it is not enough for it to have the right permissions: each component of the absolute path leading to it must also have the right permissions. (My understanding, correct me if I'm wrong, is that X itself must have its world-readable (4) bit set, and every directory component in its path must have its world-executable (1) bit set.) What's the simplest way to do this? FWIW, my best guess would be something like: function _mkwr { chmod o+x $1 || return 0 parent=$( dirname $1 ) if [[ $parent = $1 ]]; then return 0; fi _mkwr $parent } function mkwr { chmod o+Xr $1 _mkwr $( dirname $1 ) }
You're right about permissions: each directory component must be world-executable, and the item itself must be world-readable (and probably world-executable as well if it's a directory). An additional wrinkle is that if the path involves symbolic links, you need to make every intermediate directory that is necessary to resolve the symbolic link world-executable as well. If you have a symlink-free path, a simple loop can do the job: make_directory_world_accessible () { dir=$1 case $dir in /*) :;; *) dir=$PWD/$dir;; esac while [ -n "$dir" ]; do chmod a+x "$dir" slashes=${dir##*[!/]}; dir=${dir%$slashes}; dir=${dir%/*} done } With symbolic links, you need to look up all symbolic links manually and recurse over each directory component. The kernel does that internally but does not expose the process. For example, given a symlink /foo/bar -> one/two/three, not only do you need to make /foo/one and /foo/two public, but you also need to check whether one and two are symlinks and recurse accordingly.
How to make a path world-readable?
1,459,101,796,000
Normally we know when we create one file in Linux, the file's owner and group will set with the creator. For example, I have one user, usera, after I execute usera@srv1:$touch 1.txt I will find the owner of this file will be usera, just like usera@srv1:$ll -rw-r--r-- 1 usera usera 0 2012-07-25 14:29 1.txt But now the result is: -rw-r--r-- 1 root usera 0 2012-07-25 14:29 1.txt It seems that not only the touch command, but also others are all have the same problem. For example, if I use vim to create a new file in usera's home, which means this user has permission to create file: usera@srv1:$ vim a.txt I can enter edit screen, but cannot save it. The error message is the same as we do not have write permission on that file. So what happens on our server, the server is Ubuntu 11.04 64bits. One extra but maybe useful information: Now all new created users have similar problem. usera is a sudoer, but after I create a new normal user (sudo createuser xxx), assign password and login with this new account, it's the same.
The only reason I can think of that would give such symptoms from the steps you have described, is that touch (and likely a whole slew of other tools) is setuid root, which it is not supposed to be. Try executing the command ls -lH "$(which touch)" in a terminal; is the first execute bit x or s? If it is s (for example, -rwsr-xr-x), then my gut feeling would be that you are looking at a rooted installation. Note that if your system has been compromised, you can't necessarily trust the output of ls (or for that matter any other tool) to be an accurate representation of reality. The $(which touch) will expand to whatever your shell thinks is the full path to the touch binary, so this will catch the case of a stray touch in a wrong place that happens to come before the real one in your $PATH, and -H makes ls dereference symbolic links (in the case of symlinks, it will show the name of the symlink, but the file properties will be from the symlink target). If that's not it, from the sounds of it, your system is very seriously broken permissions-wise. Also remember that vim doesn't actually create the file until you give a save command. If your system has indeed been compromised, the only real solution is to wipe it clean and rebuild, then carefully restore data and configuration from backups. (You do have backups, right?) In principle, it certainly is technically possible to repair a rooted system, but it tends to be a whole lot more trouble than it's worth, it's extremely easy to miss something, and it certainly is not easier than reinstalling. What that would involve is to boot from trusted, read-only media, mount the existing partitions in their usual places under some alternate root such as /mnt, and go through every single directory, file, permissions bit, etc etc, with a fine-toothed comb, looking for any anomalies and restoring anything even remotely suspicious-looking from a trusted copy. For this, you effectively need an identically set up trusted system to compare against; you cannot trust anything on a compromised host.
Strange file ownership with Ubuntu
1,459,101,796,000
I frequently find myself encountering problems (usually permissions) when trying to setup a local development server. Or creating a new site (alias). Very common problem is I need to allow www-data (Apache use on ubuntu) access to all directories leading to the working directory. Another problem is since I am logged in as my personal user jiewmeng, when I create new files, they are owned by me, and sometimes, Apache can't read/write to it. How is your local development setup like? I am using Ubuntu 11.10.
I frequently find myself encountering problems (usually permissions) That rather implies that you haven't got a permissions model in place. How is your local development setup like? I use the 'other' entity to allow access for the apache uid, the 'group' is for the people who need to deploy / edit files and the user is the user whom created the files. So my files look something like: drwxrwsr-x symcbean webdev webroot/ -rw-rw-r-- other webdev webroot/a.php -rw-rw-r-- symcbean webdev webroot/b.php drwxrwxrwx symcbean webdev webroot/data -rw-rw-rw- apache apache webroot/data/stuff.txt drwxrwsr-x symcbean webdev webroot/include/ -rw-rw-r-- symcbean webdev webroot/include/def.php
Setting up Apache 2 Local Development Environment & Permissions
1,459,101,796,000
I'm creating a hidden "Access Log" .txt file of employees accessing a program I've created and need to know how to make it so this file cannot be deleted. Reason being, this program helps to automate a lot of tasks that we perform on workstations, and it can do a lot of damage as well. So I need to track who accesses it just in case it becomes an issue. Reiterating the question, how do I keep anyone from deleting this file while still being able to write to it.
I guess that you have users that each time they start an application, this application keeps track of who started it by writing some information in a file located in the samba share accessible by all workstations. Since you're referring to "Access Log", I also guess that you only need to append to the file and not modify its contents. If the file is on an ext2/3/4 file-system on the server side, then make sure that samba users don't have write permissions to its directory. This will avoid accidental or intensional deletion. Then enable the append-only attribute with chattr +a <filename>, so information can only be added and not removed/modified/truncated. The file can still have write permissions to everyone, so the application can append to it even with the users' privileges. Note: chattr might work for other file-systems too, eg. xfs. I don't have an exact list.
SAMBA Share - Keep user from deleting a file
1,459,101,796,000
When I tried to change my password on an ssh key, I received the following error message: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '/Users/username/.ssh/id_rsa' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored. What does it mean? How can I fix this? Edit: This solved my problem sudo chmod 600 ~/.ssh/id_rsa
sudo ssh-keygen -f ~/.ssh/YOU_PRIVATE_SSH_KEY -p If the terminal displays the message Permissions 0644 then run the command as root If the terminal displays the message failed: Permission denied To fix permission issues, first you need to set the correct ownership and permissions for the home directory and directory .ssh:1 sudo chown -R user:user $HOME sudo chmod 750 $HOME sudo chmod -R 700 $HOME/.ssh This creates the permissions for all files in .ssh necessary to satisfy SSH requirements. SSH recommendations and requirements (underlined) for individual directory files.ssh are listed below (from the manual page): ~/.ssh/id_rsa (or any PRIV KEY — private, primary key) — These files contain sensitive data [namely your authentication secret] and should be readable by the user, but not accessible for others (read/write/execute) — e.g. 0600. The ssh program will simply ignore the private key file if it is accessible by others. sudo chmod 600 ~/.ssh/id_rsa ~/.ssh/config — due to the possibility of abuse, this file must have strict permissions: read/write for the user and not writable for others - it is enough to install 0644. sudo chmod 644 ~/.ssh/config ~ /.ssh/authorized_keys — This file is not highly sensitive, but the recommended read and write permissions for the user and are not writable for others are 0644.2 sudo chmod 644 ~/.ssh/authorized_keys ~ /.ssh/known_hosts — This file is not highly sensitive, but read and write permissions are recommended for the user and read-only for others, hence 0644. chmod 644 ~/.ssh/known_hosts ~/.ssh/ — There is no general requirement to keep all the contents of this directory secret, but the recommended read/write/execute permissions are for the user and inaccessible for others — 0700 is enough. sudo chmod 700 ~/.ssh ~ / .ssh /id_rsa.pub (OR ANY PUBLIC KEY) — These files are not confidential and can (but not necessarily) be readable by anyone. 1 Write permissions to a directory lets a user change the permissions of the files and directories it contains. .ssh contains the secret private key which must not be known by anybody except the owner. If a different user had write access to the containing directory (.ssh) they could change the permission of the secret key in that directory and read the file. This argument recursively applies all the way up to the file system root. 2 Even though authorized_keys does not contain strict secrets — all keys in it are public — it specifies who can log in: Anybody with the (unknown but verifiable) private keys associated with the public keys listed in the file. Therefore, write privilege to authorized_keys must be restricted to the account owner.
How to change password on ssh key
1,459,101,796,000
I want to clarify a few things I noticed regarding the file handling in linux (Ubuntu basically but I think this is applicable to every distribution). I noticed that when files are created by root in home directory they are considered write-protected regular files and a message is displayed when trying to remove them the usual way: $ sudo touch ~/test.txt $ ls -l ~/test.txt -rw-r--r-- 1 root root 0 Nov 24 10:27 /home/xxx/test.txt $ rm ~/test.txt rm: remove write-protected regular empty file '/home/gorfanidis/test.txt'? y $ ls -l ~/test.txt ls: cannot access '/home/gorfanidis/test.txt': No such file or directory If I do not confirm with y the file is not deleted also (I know I can use -f for example to skip this message but I am not asking for this). Anyway, I tried the same in another place where the folder owner is root (I guess this is the difference but not sure) as in /usr/ $ sudo touch /usr/test.txt $ rm /usr/test.txt rm: remove write-protected regular empty file '/usr/test.txt'? y rm: cannot remove '/usr/test.txt': Permission denied So, my questions are the following: What does exactly write-protected regular file mean? What file is non-regular for example? It's not clear to me. Write-protected in this case means root owner (privileges) as stated here for example. What's the point of asking for permission for removing write-protected file when you cannot actually remove it (case of root file in root folder)? What's the mechanism for the linux system to decide if a user has actually privileges to remove a file: is it the folder permissions the file resides in? Is it something more elaborated?
A regular file is any file which actually contains its own data, instead of being a file system representation of something else (see Understanding UNIX permissions and file types for details). From rm’s perspective, a write-protected file is any file which the current user can’t write to. In your case, the file is only writable by its owner, and the current user isn’t the owner. The fact that the file is owned by root doesn’t add anything to this. rm first checks whether the file itself is writable; if it isn’t, it prompts the user. Only then does it actually try to delete the file, and that’s when the operating system “tells” rm that the user doesn’t have permission to delete the file (the deletion fails with a “permission denied” error). rm doesn’t attempt to determine ahead of time whether the file deletion is allowed; even if it tried to, the detection would be racy and incomplete, and it would still have to deal with cases where it thought the deletion was allowed but the operating system decided otherwise. File deletion is subject to being allowed to write to the parent directory, yes.
How does deletion work with write-protected regular files?
1,459,101,796,000
For some reasons, I NEED the home directory of some particular user to be group-writable. However, when trying to login to that user with ssh key, sshd refuses the authentication, as it requires the home directory to be writable by noone else than owner. In case it is group- or world-writable, sshd rejects authentication with the (in)famous message "Authentication refused: bad ownership or modes for directory /home/user". Is there any way (except recompiling sshd) to force it to accept key authentication even when home directory is group-writable? Maybe place ssh keys in a different directory, outside of user's home dir, and tell sshd to use these keys?
Found a solution myself :) There are in fact two different possibilities. First is to set the option StrictModes to no (default is yes) in /etc/ssh/sshd_config file. With that setting, sshd does not enforce permissions on users home dir. The downside of this method is that it is global for all users. The second method is to use the AuthorizedKeysCommand option. We need to write a simple script, that for that particular user name (it is pased to the script as a first parameter) will output that user's authorized keys file - whenever it is located - and for other values of the first parameter it will simply do nothing. Something like: #!/bin/sh if [ "$1" = "user" ]; then cat /usr/local/etc/users_authorized_keys fi If the script is placed for example in /usr/local/libexec/listkeys, then we need to put the following line into /etc/ssh/sshd_config file: AuthorizedKeysCommand /usr/local/libexec/listkeys With that solution, /home/user directory can be group writable, while for other users the permissions for home directory are still enforced.
"Authentication refused: bad ownership or modes for directory /home/user" - how to force sshd accept auth despite "wrong" permissions?
1,459,101,796,000
Is it possible to give a single user without sudo access, the ability to run a sudo protected command like chmod?
sudo configuration files are stored in /etc/sudoers file and /etc/sudoers.d directory. It is preferable to add a file, with the same name as the user you want to set the sudo for, to /etc/sudoers.d although you can also edit /etc/sudoers. The basic syntax is who where = (as_whom) what For example: root ALL = (ALL:ALL) ALL menas allow user root to run on any host (ALL = ) as any user:group (ALL:ALL) any command (ALL) In your case, you need to do something like: echo "ltd_user ALL=NOPASSWD:/bin/cat, PASSWD:/bin/chmod" > /etc/sudoers.d/ltd_user This gives user ltd_user rights to run cat without typing password and chmod after typing password, on any host, as any user After making a file under /etc/sudoers.d you should set permission to 440 chmod 440 /etc/sudoers.d/ltd_user Also note that I gave a very basic example (and hence used echo and redirection) but it would be good practice to use visudo command to edit sudo configuration files, which ensures that only one person is editing the file at a time, has the proper permissions, and refuses to write out the file and exit if there are syntax errors in the changes made. visudo -f /etc/sudoers.d/ltd_user see man sudoers for more details and advanced examples
Can I give a single non-sudo user access to run a single command without sudo? [closed]
1,459,101,796,000
There are a lot of questions with similar titles. I believe I have checked them all before asking this question. My error is su: Permission denied and the user switch is not completed. Here are the details. ssh admin@remote-machine su --login myuser Password: su: Permission denied (the password is correct) RESULT: failed to switch users However, the following does work, even though it reports a minor error: su --preserve-environment myuser Password: bash: /home/admin/.bashrc: Permission denied RESULT: succeeds to switch users Also, plain su myuser without any parameters works. These variants also work: su -P myuser su -s /bin/sh myuser Even though I have a work-around, I want to understand this issue. Also, my preferred form of the command, su - user is the one that does not work. This issue only affects one remote device, even though I have several that appear to be configured identically. They all run Arch Linux. I'm not using SELinux. From reading the other questions, I checked a few things. user@remote-machine [/home/myuser] # ls total 13904 drwx--x---+ 1 myuser myuser 3210 Feb 18 16:00 . -rw-r--r-- 1 myuser myuser 396 Aug 13 2018 .bashrc # getfacl /home/myuser/ getfacl: Removing leading '/' from absolute path names # file: home/myuser/ # owner: myuser # group: myuser user::rwx user:sddm:--x group::--- mask::--x other::--- # ls /home/admin/.bashrc -rw-r--r-- 1 admin admin 624 Apr 17 17:08 /home/admin/.bashrc less /etc/passwd myuser:x:1000:1000:myuser myuser:/home/myuser:/bin/bash In /etc/pam.d/su the following line is commented out (which is the default): # auth required pam_wheel.so use_uid EDIT: added info as requested. First, I did a diff -rw on /etc/profile.d/ between this system and a similar system that does not have this su -l problem. There are no differences. Both contain only the standard Arch Linux scripts in /etc/profile.d/. There is one change in /etc/profile itself from the stock Arch Linux file. But this change is present in both the correctly working system and the one with the su -l problem. The only change in /etc/profile is umask 006. /etc/bash.bashrc # If not running interactively, don't do anything [[ $- != *i* ]] && return [[ $DISPLAY ]] && shopt -s checkwinsize HISTFILESIZE= HISTSIZE= HISTCONTROL=ignorespace case ${TERM} in xterm*|rxvt*|Eterm|aterm|kterm|gnome*) PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"' ;; screen*) PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"' ;; esac [ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion The files shown below are in the user account I issued the su command from. But this issue affects any user changing to any other user. I don't see any of the user accounts with modified files (for ~/.bash_profile, ~/.bash_login, and ~/.profile). There is no .bash_login in any account or in /etc. Both of the next files are bare-bones. ~/.bash_profile [[ -f ~/.bashrc ]] && . ~/.bashrc ~/.bashrc # If not running interactively, don't do anything [[ $- != *i* ]] && return In one account, ~/.bashrc has: if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi the aliases in .bash_aliases all look OK. The issue also affects users with no aliases defined. /etc/security/limits.conf - no lines (other than comments both working & non-working devices have the same empty file) /etc/securetty - stock Arch Linux (no changes to file & both working & non-working devices have the same lines) /etc/passwd - 644 perms /etc/ - 755 perms SOLUTION: /etc/pam.d/su-l (but not any of the other files in /etc/pam.d/) required pam_wheel.so use_uid. See accepted answer for more. Now that this is resolved, this question contains a comprehensive checklist for this issue. Hopefully it will be a good reference for others.
I did a diff -rw on /etc/pam.d/ between this system and a similar system that does not have this su -l problem. I found /etc/pam.d/su-l had this line uncommented: auth required pam_wheel.so use_uid It is normally commented so as to not impose this requirement. None of the other similar files in /etc/pam.d/ had this line uncommented, hence the inconsistent behavior of different variants of the command. I solved the issue by commenting that line: # auth required pam_wheel.so use_uid
su: Permission denied (credentials correct)
1,459,101,796,000
The error I installed Elasticsearch on CentOS using rpm and am encountering this error when I try to start it via systemctl start elasticsearch: Feb 20 21:08:34 server.cberdata.org systemd[1]: Started Elasticsearch. Feb 20 21:08:34 server.cberdata.org elasticsearch[4226]: OpenJDK 64-Bit Server VM warning: Cannot open file /var/log/elasticsearch/gc.log due to Permission denied Feb 20 21:08:51 server.cberdata.org systemd[1]: elasticsearch.service: main process exited, code=exited, status=78/n/a Feb 20 21:08:51 server.cberdata.org systemd[1]: Unit elasticsearch.service entered failed state. Feb 20 21:08:51 server.cberdata.org systemd[1]: elasticsearch.service failed. Notably: Cannot open file /var/log/elasticsearch/gc.log due to Permission denied Permissions Permissions for /var: drwxr-xr-x 21 root root 4096 Feb 11 19:10 var Permissions for /var/log: drwxrwxr-- 12 root root 4096 Feb 20 21:00 log Permissions for /var/log/elasticsearch: drwxrwxrwx 2 elasticsearch elasticsearch 4096 Feb 20 20:56 elasticsearch Permissions for /var/log/elasticsearch/gc.log (which I manually created to see if that would help, but doing so had no effect on the error): -rwxrwxrwx 1 elasticsearch elasticsearch 0 Feb 20 20:56 gc.log Setting /var/log permissions to drwxrwxrwx appears to fix the problem, but I'm hesitant to do that because it seems insecure and it results in these new errors: /etc/cron.daily/logrotate: error: skipping "/var/log/exim_mainlog" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation. Am I correct that systemctl / systemd is running this service as the elasticsearch user? If it's doing that, how can the owner of the file and its directory, with apparent read/write/execute permissions, not have permission to open that file?
The directory /var/log has 774 permissions. As the execute bit isn't set, the elasticsearch user can't traverse the directory to get the elasticsearch directory and the gc.log file contained therein. Normally, the /var/log directory has 755 permissions or else no services or applications running as anyone other than root would be able to write to it. You can fix it by using: chmod 755 /var/log You also don't need to have 777 permissions on the elasticsearch directory and the log file. The can use a variation of the above command to set the permissions: chmod -R 755 /var/log/elasticsearch
Elasticsearch cannot open log file: Permission denied
1,459,101,796,000
I am trying to manually install a USB hard drive from the command line on my Raspberry Pi. I am following the usual steps: Create a directory in /media, mount the drive,... However I can not access the drive as a regular user and since the root account is disabled... pi@raspi:/media/pi $ ls -hal total 113K drwxr-x---+ 5 root root 4.0K Oct 1 22:57 . drwxr-xr-x 4 root root 4.0K Oct 1 21:41 .. drwxr-xr-x 6 pi pi 32K Jan 1 1970 342F-8BF2 drwxr-xr-x 5 root root 1.0K Sep 1 11:29 SETTINGS drwx------ 1 root root 72K Sep 24 23:18 toshiba 342F-8BF2 is a pendrive automatically mounted when starting the desktop environmnent, meanwhile toshiba is the directory that I have created with mkdir and where the HD is mounted. How can the desktop create a directory as user pi with all the permissions that allow me to access/modify the pen drive but I can't? EDIT: In order to mount the HD I am using the following command sudo mount /dev/sdb1 /media/pi/toshiba and these are the permissions for the /media/pi directory pi@raspi:/media $ ls -hal total 16K drwxr-xr-x 4 root root 4.0K Oct 1 21:41 . drwxr-xr-x 22 root root 4.0K Jun 27 03:09 .. drwxr-x---+ 2 root root 4.0K Sep 22 00:32 peter drwxr-x---+ 5 root root 4.0K Oct 1 22:57 pi
What is the filesystem type on the disk you’re mounting manually? Filesystems that have no real support for Unix-style file ownership will usually need mount options to determine who can access them. If you specify no options, the default is to allow root access only. Use the id command to identify the UID and GID numbers of your user account. I believe the pi user on a RasPi is usually UID 1000, GID 1000, so this might work for you: sudo mount -o uid=1000,gid=1000 /dev/sdb1 /media/pi/toshiba The desktop will most likely use udisks2 or similar D-Bus service to actually handle the mounting; see man udisksctl to see how you can use the same service from the command line. It will automatically apply some mount options to assign the permissions for you if applicable. If the disk/partition has a filesystem that can persistently store Unix-style file ownerships and permissions, then you can use the chown and chmod commands as an one-time action to set the permissions for the root directory of the filesystem: <mount the filesystem> sudo chown pi:pi /media/pi/toshiba Note that changing the permissions of the /media/pi/toshiba directory while the filesystem is unmounted will have no effect on the permissions of the root directory of the filesystem on /dev/sdb1. They are two separate entities, although one covers the other when the filesystem is mounted.
Can not access manually mounted hard drive from command line
1,459,101,796,000
I have a windows machine locally connected to my linux machine. There is a shared folder on the windows machine, which I mounted on my linux machine using sudo mount -t cifs -o username=myuser //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/ and it's mounted successfully and I can see the files and folders. The problem now is that I'm trying to create a folder inside the mounted share but I can't. I've checked the permissions of the mounted folder and it says "You are not the owner, so you cannot change these permissions" as shown below: I've tried running sudo chmod -R 777 /mnt/windowshare and sudo chown -R isa /mnt/windowshare but it says chmod: changing permissions of '/mnt/windowshare/.?00000002202011111110e5(and many other chars)': No such file or directory then I stop the command using ctrl+c Any advice how I can have control access over this folder on my linux machine?
It is not possible to change permissions on a windows share when it's already mounted, but it is possible to change them during the mount. first unmount your share with: sudo umount /mnt/windowshare/ then mount the share again with these new arguments: sudo mount.cifs -o username=myuser,uid=youruser,gid=yourgroup //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/ quoting from the mount.cifs man uid=arg sets the uid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a username or a numeric uid. When not specified, the default is uid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the uid in non-numeric form. gid=arg sets the gid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a groupname or a numeric gid. When not specified, the default is gid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the gid in non-numeric form. link to the mount.cifs man to find your user open a terminal and run this command: whoami to find your group run this command: ( in this case the right group will be the first from the left ) groups
Change ownership of a share drive
1,459,101,796,000
Using pipes, one can create files with simple shell built-ins. { echo "#!/bin/bash" \ echo "echo Hello, World!" \ } > helloworld.sh With chmod these can then be made executable. $ chmod 755 helloworld.sh $ ./helloworld.sh Hello, World! I wonder whether it is possible to save the chmod step. Already, I found that umask cannot do the job. But perhaps someone knows an environment variable, bash trick, program to pipe through or other neat way to do it. Is it possible to have the file created with the executable bit already set?
It is not possible to create an executable file solely with a shell redirection operator. There is no portable way, and there is no way in bash either (in the source code, you can see that redirection calls do_redirection_internal which calls redir_open with the parameter mode set to 0666, and this in turn calls open with this mode). You're calling a shell command anyway, so add ; chmod +x … somewhere in it. There's absolutely nothing wrong with that. One more line of code is not a problem. You need to do three things (create a file with some given content, make the file executable, execute it), so write three lines. There is a relatively obscure shell command that can create an executable file with some specified content: uudecode. But I would not recommend using it: it requires the input to be passed in a non-readable format, it bypasses the user's umask, and it's obscure. A sane alternative is to call bash /the/script instead of chmod +x /the/script && chmod +x, if you know what interpreter to execute the file with.
create executable files via piping
1,459,101,796,000
I just transferred files and folders from my local machine to my web server using SFTP. Doing ls -l on both machines indicates file and folder permissions seems to have changed. Why would this happen?
New files copied over are generally given a filter through the umask when written to a new location. To preserve the permissions as at the source, use scp -p (see also cp -p; rsync -p).
File permissions changed after SFTP
1,459,101,796,000
So I have a script infinite.sh that is in the /root directory. I want to give the user Bob permission to run this script. So what I did is that setfacl -m u:Bob:rwx infinite.sh and setfacl -m d:Bob:rwx /root However, when I switch to the user Bob, I still can't even cd into the /root directory of run the infinite script -- that doesn't make sense to me.
The line setfacl -m d:Bob:rwx /root will set a "default" for new directories created inside /root but doesn't change that directory itself. You may have meant setfacl -m u:Bob:rwx /root Note that this is insecure; Bob can now modify files (eg mv .profile .profile.old and create a new .profile) to gain full root access. Better might be setfacl -m d:Bob:rx /root so Bob can read stuff but not change it. Similarly: setfacl -m u:Bob:rx infinite.sh
Access control lists and permission on directory
1,459,101,796,000
For a school assignment our team has been provided a VM from the school. We were handed the VM with our user accounts added to the sudo group, and I also have access to the "root" and "sysadm" accounts that already exist on the machine, presumably from the sysadmin that did the setup. I noticed an issue: I am unable to create any directories or files in the home directory. 411blackf16:/> ls -lashr total 93K 0 lrwxrwxrwx 1 root root 29 Sep 8 07:43 vmlinuz.old -> boot/vmlinuz-4.4.0-21-generic 0 lrwxrwxrwx 1 root root 29 Sep 8 18:35 vmlinuz -> boot/vmlinuz-4.4.0-36-generic 4.0K drwxr-xr-x 14 root root 4.0K Sep 12 18:16 var 4.0K drwxr-xr-x 10 root root 4.0K Sep 8 07:42 usr 4.0K drwxrwxrwt 10 root root 4.0K Sep 12 18:44 tmp 4.0K drwx------ 2 sysadm sysadm 4.0K Sep 12 18:44 sysadm 0 dr-xr-xr-x 13 root root 0 Sep 12 18:30 sys 4.0K drwxr-xr-x 2 root root 4.0K Apr 20 18:08 srv 4.0K drwxr-xr-x 2 root root 4.0K Apr 19 10:31 snap 12K drwxr-xr-x 2 root root 12K Sep 12 13:18 sbin 0 drwxr-xr-x 36 root root 1.4K Sep 12 18:32 run 4.0K drwx------ 3 root root 4.0K Sep 12 18:34 root 0 dr-xr-xr-x 219 root root 0 Sep 8 23:42 proc 4.0K drwxr-xr-x 2 root root 4.0K Sep 12 12:20 opt 4.0K drwxr-xr-x 2 root root 4.0K Apr 20 18:08 mnt 4.0K drwxr-xr-x 4 root root 4.0K Sep 8 07:42 media 16K drwx------ 2 root root 16K Sep 8 07:42 lost+found 4.0K drwxr-xr-x 2 root root 4.0K Sep 8 07:42 lib64 4.0K drwxr-xr-x 22 root root 4.0K Sep 12 18:22 lib 0 lrwxrwxrwx 1 root root 32 Sep 8 07:43 initrd.img.old -> boot/initrd.img-4.4.0-21-generic 0 lrwxrwxrwx 1 root root 32 Sep 8 18:35 initrd.img -> boot/initrd.img-4.4.0-36-generic 0 drwxrwxrwx 2 root root 0 Sep 12 19:03 home 4.0K drwxr-xr-x 106 root root 4.0K Sep 12 18:56 etc 0 drwxr-xr-x 19 root root 4.2K Sep 8 23:43 dev 1.0K drwxr-xr-x 4 root root 1.0K Sep 12 13:19 boot 4.0K drwxr-xr-x 2 root root 4.0K Sep 12 13:18 bin 4.0K drwxr-xr-x 24 root root 4.0K Sep 12 18:51 .. 4.0K drwxr-xr-x 24 root root 4.0K Sep 12 18:51 . The owner is root:root. 411blackf16:/> sudo mkdir /home/test mkdir: cannot create directory ‘/home/test’: Permission denied 411blackf16:/> sudo su root root@411blackf16:/# sudo mkdir /home/test mkdir: cannot create directory ‘/home/test’: Permission denied Using my sudo user account or the root account still doesn't allow creation of directory or files. root@411blackf16:/# chmod -R 777 /home/ && touch /home/test touch: cannot touch '/home/test': Permission denied Even opening up the permissions doesn't help. Does anyone have some any idea on what is going on here? Thanks.
A couple of possibilities: /home could be a filesystem which is mounted readonly (the mount command would show you this) as an exercise, your instructor could have set some interesting ACL (but then ls should have shown a . or other punctuation character after the permissions) the VM (underlying file) permissions are readonly, and the machine cannot write-through its changes (so for instance, journalling might have died). In a followup, OP showed the results from mount: 411blackf16:/> mount | grep home ldap:CN=auto.home,OU=Unix Autofs,DC=cs,DC=odu,DC=edu on /home type autofs (rw,relatime,fd=6,pgrp=1415,timeout=300,minproto=5,maxproto=‌​5,indirect) and MikeA pointed out that the type is "autofs", which shows that the filesystem is mounted, and the string "ldap:CN=auto.home,OU=Unix Autofs,DC=cs,DC=odu,DC=edu" indicates that it is mounted using LDAP credentials. all of this implies that the actual /home is on another machine that OP cannot modify (aside from files in his/her home-directory). The root user on the VM would not have any permissions on this filesystem (it would be treated as nobody). If you want to create local user accounts in the VM, with a local home directory, you can put their home directory in a different location. /home is a very common convention, but not an absolute rule. Further reading: 13.2.7. Configuring Services: autofs
Unable to create home directories
1,459,101,796,000
I'm familiar with how Linux permissions work on a single machine, but what happens when a directory is shared (specifically via NFS)? Also, what happens when two users are seemingly the same (same name, UID etc), and is there some way of convincing NFS that two users on different systems are actually the same and should have identical privileges?
You can use NFSv3 to map on user and group IDs. If you don't want to map on IDs use NFSv4 instead which maps on user- and groupnames. So if you have two different clients who have a user called user-host-a and user-host-b who both have UID 500 they both have access to the files when NFSv3 is used. When you have two different clients who have a user called myuser with different IDs, 500 on host-a, 501 on host-b, the user will have access on the NFS files when NFSv4 is used. In short, no you can not convince NFS that two different users are actually the same other than by keeping the IDs or names the same. Another approach might be to use NFSv4 and use ACLs to grant access to both user accounts. On NFSv3 you can create a common group for both accounts and change the group ID on the files on the NFS server.
How does file system permission behave on different systems sharing an NFS export?
1,459,101,796,000
Assume I have groups G1, and G2, and user U. User U is a member of both groups, but G1 is it's primary group. In my file system there is a folder F which is accessible by G2. Now if U wants to access F the only way for it is to do newgrp G2, and then access, which is not what I want my users do all the time. What should I do? Concrete example: ajalali@ws47lx:/projects/gchrupala$ stat . File: `.' Size: 17 Blocks: 0 IO Block: 1048576 directory Device: 15h/21d Inode: 150 Links: 3 Access: (0775/drwxrwxr-x) Uid: ( 6052/gchrupala) Gid: ( 6000/nis_users) Access: 2015-03-05 15:34:46.260662858 +0100 Modify: 2013-03-05 16:35:16.000000000 +0100 Change: 2013-06-10 20:40:25.418034444 +0200 Birth: - ajalali@ws47lx:/projects/gchrupala$ id uid=1004(ajalali) gid=1001(ajalali) groups=1001(ajalali),6000(nis_users),6060(admin),6061(sudo),1625200000(admins),1625200001(lsv_local),1625200035(compute_server_users),1625200036(contact_server_users) ajalali@ws47lx:/projects/gchrupala$ mkdir tmp mkdir: cannot create directory `tmp': Permission denied The user (ajalali) is a member of the group that owns the current folder (6000), but can not make anything there, cause it's primary group (1001) is not the group that owns current folder. It will only work if the user does newgrp nis_users first, and then try to make a folder there.
This looks like an NFS issue. Is NFS involved? NFS servers running on Debian-based systems, and possibly others, are configured to ignore supplementary groups unless told specifically otherwise. Ensure that --manage-gids has been supplied to the rpc.mountd program. On Debian systems that is done by editing /etc/default/nfs-kernel-server and ensuring that RPCMOUNTDOPTS=--manage-gids is present.
Linux user groups and file system permissions
1,459,101,796,000
I actually started learning Unix and while doing so I stuck here. Though It may seem silly question I'm actually unclear with it so please help me. I've a file as somefile.txt and a symbolic link which refers to somefile.txt, and I found default permissions for both are rw-r--r--. When I change permissions of somefile.txt (chmod ugo=rwx somefile.txt), I found a change in both files as rwxrwxrwx. But again when I try to change permissions by giving chmod u-rx somefile.txt, I found change only in somefile.txt but not in symbolic link. I wonder why? I'm using RedHat cygwin.
You have mistaken the output of at least one command. The permissions of a symbolic link are always rwxrwxrwx, or rather they don't have permissions at all: $ touch file $ ls -l total 0 -rw-rw-r-- 1 muru muru 0 Dec 5 20:53 file $ ln -s file link $ ls -l total 0 -rw-rw-r-- 1 muru muru 0 Dec 5 20:53 file lrwxrwxrwx 1 muru muru 4 Dec 5 20:53 link -> file $ chmod a+x file $ ls -l total 0 -rwxrwxr-x 1 muru muru 0 Dec 5 20:53 file lrwxrwxrwx 1 muru muru 4 Dec 5 20:53 link -> file See this FreeBSD FAQ for more information. And since you're on Linux, man chmod says: chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. In contrast, chmod ignores symbolic links encountered during recursive directory traversals.
doesn't symbolic link changes it's permissions if I remove permissions in actual file?
1,459,101,796,000
I want to set the default permissions for newly created directories to have r-x for others and those of newly created files (non-directory files) to have ---. If I set the umask to 2, directory permissions get r-x but files' get r--. I couldn't find any way to achieve what I want with umask. Ultimately, I want others to be able to traverse the directories but not to read the content of the files. I think that is a very reasonable demand but eventually there seems to be no such setting.
If you only create directories with the mkdir command at the shell prompt, you could have: umask 7 mkdir() (umask 2 && command mkdir "$@") In your shell customisation file (~/.zshrc for zsh, ~/.bashrc for bash...). That is set the umask to 7, but redefine mkdir to a function where the real mkdir is called (with the same arguments ("$@")) with a umask of 2. (note that the (...) create a subshell, so the umask 2 is only applied within that function).
How to set umask so that directories to be `r-x` and files to be `---`
1,459,101,796,000
Say I have a directory with these permissions: drwxrwx--- Inside this directory, a file with these permissions: -rw-rw-rw- Is the file readable/writable by everyone or not ? If not, how secure is this access restriction? What if a random user makes a link to my file inside his home directory? Could he access the file then? Or could he access the file by guessing its inode number and using some system calls on inodes?
Yes, a file in a directory is only accessible to users who have the execute permission on the directory. It's like leaving jewelry in an unlocked drawer inside a locked house: the jewelry is under lock. A random user cannot create a hard link to a file, only the owner file. If the file has multiple hard links, some of which are in a publicly accessible directory, then the file will be publicly accessible. But that has to be set up by the owner of the file. Anyone can create symbolic links that happen to point to a file, but that doesn't allow them to access the file. Symbolic links do not bypass permissions. If the directory is world-executable at some point and there are processes that have the file or a parent directory opened at the time you restrict the permissions on the directory, then those processes still have the file open afterwards. However if they close it (or move out to another directory) they won't be able to reopen it (or change directory back in). Similarly, a setuid or setgid process may open the file or change to the directory, then drop its permissions. All of this requires the cooperation of the file or directory owner. There is no way to open a file via its inode. The fact that this would allow to bypass restrictive permissions such as this case is the main reason why this feature doesn't exist.
Is a -rw-rw-rw- file really inaccessible inside a drwxrwx--- directory?
1,459,101,796,000
When I mount blank btrfs partition in Dolphin, I get "Permission denied" on write. You can see that it's mounted on /run/media/%username% dir which is correct, but owner is root. [doctor@doctoror doctor]$ pwd /run/media/doctor [doctor@doctoror doctor]$ ls -l total 4 dr-xr-xr-x 1 root root 0 січ 1 1970 Home [doctor@doctoror doctor]$ mkdir Home/tmp mkdir: cannot create directory ‘Home/tmp’: Permission denied
When you create a filesystem that supports file ownership, its root directory starts owned by root (with all the mkfs that I remember seeing). The ownership of the mount point and the user who did the mounting are irrelevant to the ownership of the root directory (or any other file) on that filesystem. It would be problematic after all if mounting a filesystem in a different place changed the privileges required to access each file on it. If you want to create files as a non-root user, you'll have to give that user write permission to some directory on that filesystem.
udisks2: permission denied
1,459,101,796,000
Background After a recent HDD crash I did a clean install of Linux Mint 15 on a new disk. Seeing the potential problems with having backups of my documents and eclipse workspace, I realized that a smarter backup solution would be to take the entire home folder. Thus I partitioned my new HDD with /, /home, and /opt as separate partitions. My intention with this scheme was to use / for the system, /home for documents etc that will be backed up, and /opt for stuff that are sort of self-contained and do not require a backup, such as Virtual Windows installations that sometimes need. Questions: I noticed today when I was setting up the VM that it uses a folder in /home to store the vdi files, by default. When I changed the location of that folder to /opt I came to realize and remember that /opt has 755 permissions. Does it make sense to put a folder e.g. /opt/vm and try to put the vdi files there? I assume that Virtualbox will run with my normal user permissions and thus won't be able to write there anyways. Does giving such a folder 777 permissions solve the problem? My feeling is that the writing bit would be OK, but I am worried that this might cause more trouble later on. If the above scheme is really error-prone, what options do I have? It would be a pity to leave /opt as is (120 GB) only to create another partition. I could,in theory, resize /opt/ and create another partition /vm, right?
I will try to answer you question one by one: Does it make sense to put a folder e.g. /opt/vm and try to put the vdi files there? I assume that Virtualbox will run with my normal user permissions and thus won't be able to write there anyways. I would say it makes more sense to put the virtual machines in your home folder, since the virtual machine is data that is associated with your user, and configure your backup program to exclude that directory. But there is no problem in setting up some other directory, such as /opt/vm and set your user as the owner of that directory. Only thing I can think of if SELinux or something like that would try to interfere, but that seems really unlikely. Does giving such a folder 777 permissions solve the problem? My feeling is that the writing bit would be OK, but I am worried that this might cause more trouble later on. A better solution would be to change the owner of that directory: posdef@linux$ sudo mkdir -p /opt/vm posdef@linux$ sudo chown -R posdef:posdef /opt/vm But /opt is more meant for applications and so on, so I think it would make more sense to create a folder such as /data/vm/ and use that instead. But this is entirely aesthetics. If the above scheme is really error-prone, what options do I have? It would be a pity to leave /opt as is (120 GB) only to create another partition. I could,in theory, resize /opt/ and create another partition /vm, right? There is not any real problem with your setup, more than it might be a bit unusual. I think that a better solution would be to configure your backup program to exclude some folders that you know contain a lot of data. So this seems a bit like a complicated solution to a not that complicated problem. And there is no need to create new partitions, you can just change the mount point of your partition from /opt/vm to something else. /opt is not the partition, it is only the mount point. You can configure this in either /etc/fstab or perhaps in some GUI application (I haven't used mint myself).
Having Virtualbox disk images on /opt
1,459,101,796,000
I have a script running under my own user account that takes care of all sorts of wireless interfaces. It (more or less) intelligently switches wireless LAN off and on and so forth. However, it does so by calling on tools such as iwconfig and hciconfig to bring the devices up and down. But since these require super user privileges I decided to create a copy of these binaries in my personal script folder and set the suid flag (I am the only one who can read and execute that directory). So the permissions on these binaries look like -rwsr-x--- and they belong to root and my own primary group. However, the suid bit appears to be completely ignored because I get the following result when executing that binary: me@host:~/scripts/suid$ stat iwconfig File: `iwconfig' Size: 26968 Blocks: 72 IO Block: 4096 regular file Device: 15h/21d Inode: 4194732 Links: 1 Access: (4750/-rwsr-x---) Uid: ( 0/ root) Gid: ( 1000/ me) Access: 2011-08-24 04:15:39.008148182 +0200 Modify: 2013-02-09 21:25:47.777488386 +0100 Change: 2013-03-12 15:55:20.765681857 +0100 Birth: - me@host:~/scripts/suid$ ./iwconfig wlan0 txpower off Error for wireless request "Set Tx Power" (8B26) : SET failed on device wlan0 ; Operation not permitted. I also tried setting the group to root, the guid bit and making the binaries world executable and readable. With the same outcome. So, why is that and how can I fix it?
Your home directory is probably mounted with the nosuid flag. You can check by looking in /proc/mounts. If you're not sure which filesystem contains your home directory, df ~ will tell you (and then you can use grep to find it easily in /proc/mounts). A better alternative, though, is to use sudo with the NOPASSWD flag. For example, run (as root) visudo -f /etc/sudoers.d/local-iwconfig and add a line like: your-user-name ALL=(root) NOPASSWD: /sbin/iwconfig You can also lock things down more with sudo. For example, you could specify the full command line to be run, including arguments (and then have multiple entries, one per command line). For full details, check the sudoers(5) manual page.
How to suid iwconfig on Debian wheezy?
1,459,101,796,000
I'm fairly new to Unix and I have written a script: SERVER="/usr/local/abc/.../somefile.txt" OPTION="$1" if [ x$OPTION = "xtitle" ] then grep $OPTION $SERVER exit fi As far as I understand, when I call the script with arg "title" as ".../script title" it should return what line grep found in that file consisting string "title". I've placed 0777 permissions on the script (I know that's an overkill, but security isn't important right now). I've also put 0777 permissions on somefile.txt. I put this script to run as a part of another program, it has it's own user. But in the logs of this other program I keep seeing : grep: /usr/local/abc/..../somefile.txt: Permission denied Is it possible that something can't be accessed even if it has 777 permissions? Is it possible that another user just can't see that folder?
As you already suggested, if the user can not see the folder containing the file, s/he won't be able to access the file. In order to access the file, the folder needs to have read and execute bits set for the current user or group s/he is part of or for all others.
File with 777 permission can't be read
1,459,101,796,000
Possible Duplicate: can't change file permission On my hard drive everything is fine, but when I go onto my external drive I can't chmod. I get no error message but the changing simply doesn't take place. I have tested it and it works fine when I'm on my laptops hard drive. The same goes for creating symbolic links, I can create symbolic links on my hard drive but when I try to do it on my external drive I get: failed to create symbolic link, Operation not permitted What is the problem?
What file system is on your external drive? Are you sure it supports concepts like owner, permissions and symbolic links? FAT32, for example, doesn't support these things, so you won't be able to use utilities like chmod, and Windows "shortcuts" are not the same as UNIX symlinks.
No permission on external drive [duplicate]
1,459,101,796,000
I need to create a directory that is RW to all users using chown. what arguments should I pass chown to get a file with those permissions? Or maybe there is an even better way to do it......
chown is used to change ownership; you're looking for chmod to change the mode. You want to add (+) read and write (rw) for all users (a), so it's: $ chmod a+rw dirname You can also do it directly when you make the directory by passing mkdir the -m flag; it takes the same syntax as chmod: $ mkdir -m a+rw dirname
Creating Directories: with Permissions
1,459,101,796,000
[adela@zen ~]$ dir-open / bash: /home/adela/.toolbox/bin/dir-open: Permission denied The weird thing is, that both directory and binaries has 777 permisions, and binaries cannot be executed - permission denied. There is a ~/.toolbox/bin directory, ls -la: drwxrwxrwx 3 adela adela 4,0K 14. zář 18.34 ./ drwxr-xr-x 10 adela adela 4,0K 5. zář 19.38 ../ -rwxrwxrwx 1 adela adela 302 22. čen 16.13 checksum* -rwxrwxrwx 1 adela adela 1,3K 18. čec 17.21 dir-open* -rwxrwxrwx 1 adela adela 937 4. zář 21.05 nas-open* -rwxrwxrwx 1 adela adela 300 1. úno 2021 po-to-xls* -rwxrwxrwx 1 adela adela 565 8. zář 16.18 run* drwxrwxrwx 2 adela adela 4,0K 5. zář 19.03 .stfolder/ -rwxrwxrwx 1 adela adela 1,8K 1. úno 2021 subtitles-renamer* -rwxrwxrwx 1 adela adela 104 31. říj 2021 terminal* -rwxrwxrwx 1 adela adela 300 1. úno 2021 xls-to-po* bin directory is also present in $PATH: /home/adela/.toolbox/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin The contents of one of script: #!/bin/bash # This script makes file manager open just right. # called from ~/.toolbox/bin/dir-open APP="pcmanfm" DESKTOP=$(wmctrl -d | grep \* | awk '{print $1}') # number of active desktop APPSINDESKTOP=$(wmctrl -l -x | awk -v var="$DESKTOP" '($2 == var)' | grep -ic "$APP") # windows in active desktop WIN=$(wmctrl -l -x | awk -v var="$DESKTOP" '($2 == var)' | grep -i "$APP" | awk '{print $1}' | sed -n "1p") window=$(printf "%d\n" $WIN) if [[ $APPSINDESKTOP -ge 1 ]]; then ACTIVE=$(xdotool getwindowfocus) if [[ $ACTIVE = $window ]]; then if [ -z "$1" ]; then xdotool windowminimize $window # Minimize else $APP "$1" # New tab fi else if [ -z "$1" ]; then wmctrl -ia $WIN # Focus window else $APP "$1" # New tab wmctrl -ia $WIN # Focus window fi fi else echo "no app on active desktop" if [ -z "$1" ]; then $APP "/mnt/DATA" -n & # add -n for pcmanfm else $APP "$1" -n & # add -n for pcmanfm fi sleep 0.3 WIN=$(wmctrl -l -x | awk -v var="$DESKTOP" '($2 == var)' | grep -i "$APP" | awk '{print $1}' | sed -n "1p") wmctrl -i -R $WIN -e 0,$POSX,$POSY,$WIDTH,$HEIGHT # Resize existing window # wmctrl -ia $WIN # Focus window fi echo -e "Debug info: \n\nDesktop: $DESKTOP \nWindow: $WIN \nAppsInDesktop: $APPSINDESKTOP\n" exit 0 None of the binaries can be run. Same result when run with sudo. Arco Linux Directory is also shared with another computer (Arch), where binaries are used with no problem. Any idea what might be potentially wrong?
worth mentioning is selinux, any time I have a problem that I do not quickly understand or scratch my head on I do a setenforce 0 to temporarily put selinux into permissive mode to see if that's what is causing the problem. but permission denied on executing a binary what comes to mind is noexec as the mount option. Although I am not sure if that results in a permission denied message or if it results in just nothing ever happening. type mount and see if the mount option of noexec is present for where the binary is located. And then copy the binary from that mounted device to some other folder location which does not have the noexec mount option and see if the binary works.
Binary returns permission denied even with 777 rights
1,459,101,796,000
I want to use sshfs to mount filesystem folder on my machine (let's say ~/home). I would like to be able to edit files inside the / folder that got mounted using any editor (for example, edit /etc/sysctl.conf). In a nutshell, I want to use sshfs to mount my entire server file system in my Desktop with r+w+x permissions for every file I tried looking for answers around here, but got nowhere and only could mount with "read-only" permissions. The command was: sshfs [email protected]:/ ~/Desktop -o max_conns=8,transform_symlinks,dir_cache=yes,idmap=user,uid=$(id -u),gid=$(id -g),reconnect -d -v -C
sshfs [email protected]:/ … acts on the server side as the same user you would log in with ssh [email protected], so most likely hostname (kinda misleading name, it's a user). If hostname is not equivalent to root on the server then it's normal you cannot edit arbitrary files. The SSH server (daemon) like sshd runs and listens as root. It forks to serve your request. After you authenticate as hostname you eventually are served by sshd that dropped its privileges and runs as hostname. This way you can only do on the server what hostname can do. This works regardless of what you see locally. The options idmap, uid and gid cannot overcome the fact sshd on the server works as hostname for you. These options are meant to make the local mount look sane in the local environment. To be able to edit the remote /etc/sysctl.conf file locally, you need to authenticate to the server as a user who can edit /etc/sysctl.conf on the server. This applies to any file. Two basic options: You can mess with permissions on the server. Dangerous. E.g. if you make /etc/sudoers too open on the server then sudo will refuse to work there. Allow yourself to do sshfs [email protected]:/ …. Not recommended. One way or another, what you want to do is not really a safe idea.
Mount root filesystem with user permission using sshfs
1,459,101,796,000
I'm looking to write a .sh script to assign execute permission to all .sh files that have not been assigned execute permission in the current directory and subdirectories. I can easily assign execute permission to all .sh files contained in the current directory and its subdirectories with just one command: find -type f -iname '*.sh' -exec chmod +x {} \; The above command will assign execute permission to all .sh files located in the current directory and subdirectories. But I just need the conditional statement to check if this .sh file has been assigned execute permission or not? If not, then execute the assign execute permission command for that file. Your answer will be very helpful, I will appreciate your answer.
I think you are looking for the -executable option, negating it with -not $ ls -l -rwxrwxr-x ... cmd.sh -rw-rw-r-- ... foo.txt $ find . -not -executable ./foo.txt So in your case, you could do: find -type f -iname '*.sh' -not -executable -exec chmod +x {} \;
How to check and assign execute permission to the shell script files?
1,459,101,796,000
I have two directories on two different hard drives and want to check if the content is really exactly the same. From what I read I can use diff -rq dir1 dir2 to check if files are missing or differ. -q,--brief report only when files differ -r,--recursive recursively compare any subdirectories found However as far as I see diff does not check if the permissions or timestamps differ. Is there another parameter for diff or other tool where it is possible to check that as well?
mtree(8) is an excellent tool for this: The command: $ mtree -cp path/on/hostA -K sha256 | ssh hostB mtree -p path/on/hostB will report differences between the heirarchy in hostA:path/on/hostA and the heirarchy in hostB:path/on/hostB in terms of type, size, timestamp, permissions, and content. Additionally, missing entries (not found on hostB) or extraneous entries (found only on hostB) are reported. If the heirarcies are identical, mtree will issue no output and return an exit code of 0: $ mtree -cp path/on/hostA -K sha256 | ssh hostB mtree -p path/on/hostB && echo match match Otherwise, mtree will return a non-zero exit code, and itemize the entries that differ: # create some differences on hostB: $ ssh hostB 'rmdir path/on/hostB/d' $ ssh hostB 'mkdir path/on/hostB/e' $ ssh hostB 'date > path/on/hostB/b/B' $ ssh hostB 'touch path/on/hostB/b/BB' $ ssh hostB 'chmod 644 path/on/hostB/c/C' # and then compare: $ mtree -cp path/on/hostA -K sha256 | ssh hostB mtree -p path/on/hostB || echo fail .: modification time (Tue May 18 13:27:20 2021, Tue May 18 13:45:06 2021) extra: e b/BB: modification time (Tue May 18 13:27:28 2021, Tue May 18 13:50:01 2021) b/B: modification time (Tue May 18 13:27:03 2021, Tue May 18 13:46:04 2021) sha256 (0x4f7986b5a925296c575043e73e76b59b6eb84da37c50f2e86baaafc75e2fcdca, 0x46f3f4e748cfef2a4cd679d6c9723cb44eb0526b760854fcef33bb97ca27fae2) c/C: permissions (0600, 0644) missing: ./d fail Line by line, mtree tells you that: the path root directories themselves (.) have different timestamps there is an extra entry e on hostB that does not appear on hostA the modification time of entry b/BB differs between the two hosts (but the content does not) the modification time AND the content (SHA256 hash) of entry b/B differ between the two hosts the permissions of entry c/C differ between the two hosts hostB is missing the entry ./d
Compare content of two folders/disks (including timestamps,permissions)
1,459,101,796,000
In a multiple-container Docker application deployed with docker-compose I have a container built from alpine running PHP-FPM. That container is used both for providing PHP to the Nginx container, but also to run PHP scripts on the container from a CLI command on the host. Files created by PHP when run from CLI commands on the host are owned by root (UID 0), and have the root group (GID 0), even though FPM is configured to use the user www-data (UID 1000) and group www-data (GID 1000). Here are the relevant parts of the Dockerfile: FROM php:7.4-fpm-alpine RUN echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories RUN apk --no-cache add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data RUN chown -R www-data:www-data /var/www/html Here is the configuration: $ docker-compose exec php grep -E "user|group" /usr/local/etc/php-fpm.d/www.conf user = www-data group = www-data $ docker-compose exec php grep www-data /etc/passwd www-data:x:1000:1000:Linux User,,,:/home/www-data:/sbin/nologin And here is a demonstration of the fine problem: $ docker-compose exec php ./artisan make:model Foo -m Model created successfully. Created Migration: 2020_09_25_051836_create_foos_table $ docker-compose exec php ls -ln /var/www/html/database/migrations/2020_09_25_051836_create_foos_table.php -rw-r--r-- 1 0 0 571 Sep 25 05:18 /var/www/html/database/migrations/2020_09_25_051836_create_foos_table.php I had also tried prefixing the run command with env UID=1000 GID=1000 as suggested in some forums, however that had no effect. Thinking that maybe the CLI interpreter (/usr/local/bin/php) might not use FPM behind the scenes, I tried checking for PHP config that may be relevant but found none: $ docker-compose exec php grep -rvE "^; " /etc/php7/ | grep "user\|group" /etc/php7/php.ini:;user_ini.filename = ".user.ini" /etc/php7/php.ini:;user_ini.filename = /etc/php7/php.ini:;user_ini.cache_ttl = 300 /etc/php7/php.ini:;ignore_user_abort = On /etc/php7/php.ini:;syslog.facility = user /etc/php7/php.ini:user_dir = /etc/php7/php.ini:;user_agent="PHP" /etc/php7/php.ini:;odbc.default_user = Not yet implemented /etc/php7/php.ini:;ibase.default_user = /etc/php7/php.ini:mysqli.default_user = How can I configure PHP to write files as user www-data, i.e. UID 1000?
You can use "user" in the docker compose yml file and specify the userid:groupid user: "1000:1000"
PHP-FPM creating files as root when configured as www-data
1,459,101,796,000
I'm trying to recursively delete a directory with rm -rf, but this fails because some inner directories don't have the w permission set. I know how to fix this with chmod. However, this requires to iterate over the whole directory twice, which can be slow. Is there a way to remove such a directory in one go? (Assuming you have enough permissions to give yourself enough permissions) sudo is not an option (limited user on pc in question).
rsync with an empty dummy directory seems fine: mkdir empty; rsync -r --delete empty/ targetdir/; rmdir empty targetdir With a 10x repeated test on a simple example, this took 10-14s (14 was an outlier, all others took 10 or 11s), vs. chmod -R u+w targetdir && rm -rf targetdir, which took 19-25s and find targetdir -type d -exec chmod 755 {} \; && rm -rf targetdir, which took 12-16s but will likely deteriorate more than rsync with more complex folder structures.
rm -rf with missing w permissions on directories without root or chmod
1,459,101,796,000
I have a directory with the following ACL rules setup: cd /nobackupp13/jrwrigh7 getfacl . I get # file: . # owner: jrwrigh7 # group: a1983 user::rwx group::r-x group:a1983:r-x mask::r-x other::--- default:user::rwx default:group::r-x default:group:a1983:r-x default:mask::r-x default:other::--- However, when I create testfile in this directory, the mask does not take on the default value and restricts the permissions of the file to just r-- instead of r-x: cd /nobackupp13/jrwrigh7 touch testfile getfacl testfile I get # file: testfile # owner: jrwrigh7 # group: a1983 user::rw- group::r-x #effective:r-- group:a1983:r-x #effective:r-- mask::r-- other::--- Supposedly umask should be overridden by ACL (see https://serverfault.com/q/349145/530204 ), but here are the results of umask anyways: cd /nobackupp13/jrwrigh7 umask I get 077 Is there some other permissions system that is preventing this from working? The end goal is to have every file created in this directory be r-x by the group a1983. The whole reason I'm going through this is that my research group have always run into issues accessing/running each other's files on compute machines we don't have admin control over. We are wanting to ensure that every script file is executable, regardless of whether the owner has set it as such.
general information When a file is created by the open() syscall there is a mode setting. Each permission the file gets must be requested in this mode parameter. If the parent directory does not have default ACLs then the permissions of the file are mode combined with umask. If the parent directory does have default ACL then these and mode determine the owner permission and the permission for others. All other ACL entries are taken unchanged from the default ACLs. In order to achieve the same effect the ACL mask is not computed from the ACL_USER, ACL_GROUP, entriesACL_GROUP (as it is when ACL are set explicitly) but it is set to the group part of mode. The mask value is determined by both default ACLs and mode and the default mask. It contains only those permissions which are contained in all three elements. So usually the default mask is reduced but it can be used to reduce the other values, too. The results can be confusing if programs act "strangely". E.g. gcc creates the output file with mode 666 and later executes chmod() with 777. But that only affects the permissions for the owner and others because the ACL entries have precedence. your case touch creates the file with mode 666. The default ACL is set to 750 The result (permissions contained in both) is 640.
ACL default::mask not being used for new file
1,459,101,796,000
There is a troublemaking empty file (md5sums of kernel 4.19.1) left on my ubuntu system, with has strange owner/group/date/attributes How to fix or workaround this defect file? $ uname -a Linux olly-ryzen-pc1 4.20.10-042010-generic #201902150516 SMP Fri Feb 15 10:19:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux stat $ stat /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.md5sums   Datei: /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.md5sums   Größe: 0             Blöcke: 0          EA Block: 4096   Normale leere Datei <= empty file Gerät: 802h/2050d    Inode: 27918873    Verknüpfungen: 1 Zugriff: (5625/-rwS-w-r-t)  Uid: (477987903/ UNKNOWN)   Gid: (3699747887/ UNKNOWN) Zugriff    : 2381-05-02 11:29:39.163881368 +0100 Modifiziert: 2293-06-01 00:54:46.455862499 +0100 Geändert   : 2167-05-10 21:19:01.867729249 +0100  Geburt    : - lsattr $ lsattr /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.md5sums lsattr: Keine Daten verfügbar Beim Lesen der Flags von /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.md5sums apt, dpkg This file can't changed or deleted (remove/purge 4.19.1), but troubles apt-get to install applications. --fix-broken or --reinstall dpkg exit also with 'not allowed' message. Cannot be deleted. Die Control-Info-Datei »/var/lib/dpkg/info/linux-image-unsigned-4. 19.1-041901-generic.md5sums« kann nicht gelöscht werden: Vorgang nicht zulässig chmod -st, chown root:root No changes. rm -f No. live USB Also tried a boot of ubuntu (install 4.18) from USB-Stick to repair, but: sudo e2fsck -f /dev/sba2 does not report an error sudo badblocks -vsn /dev/sda2 reports 0 bad blocks and rm, chmod, chown: same behaivior as above .. Only to compare, here is a neighbor file: $ stat /var/lib/dpkg/info/linux-sound-base.md5sums   Datei: /var/lib/dpkg/info/linux-sound-base.md5sums   Größe: 545           Blöcke: 8          EA Block: 4096   Normale Datei Gerät: 802h/2050d    Inode: 27269131    Verknüpfungen: 1 Zugriff: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root) Zugriff    : 2019-02-03 16:56:08.943545720 +0100 Modifiziert: 2015-07-31 05:42:23.000000000 +0200 Geändert   : 2018-05-22 01:20:37.178864616 +0200  Geburt    : - $ lsattr /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.list --------------e--- /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.list
As fsck does not find anything wrong, you may need to use debugfs to clear the inode. Note that I last used debugfs years ago, so take care! Read the manpage first to see what's possible with this tool. Boot from a rescue medium, and run debugfs /dev/sda2 You can try to use debugfs's rm command to remove the file: rm /var/lib/dpkg/info/linux-image-unsigned-4.19.1-041901-generic.md5sums (assuming that /dev/sda2 is mounted on /, not /var) If that doesn't work, you might try freeing the inode. You already know the inode number (27918873) from the stat output. You can free the inode with: freei 27918873 After manipulating the filesystem with debugfs I recommend running fsck again.
Error when move or delete file on ext4 in dpkg info directory
1,459,101,796,000
I am trying to access a directory test as user ayush. This directory is owned by user ayush and has group git The directory has permissions 0070, and group git, and ayush is a member of that group. ayush:~> ls -ld drwxr-xr-x 7 ayush git 4096 Feb 15 11:33 . ayush:~> ls test ayush:~> ls -ld test/ drwxrwx--- 3 ayush git 4096 Feb 15 11:34 test/ ayush:~> chmod 070 test/ ayush:~> ls -ld test/ d---rwx--- 3 ayush git 4096 Feb 15 11:34 test/ ayush:~> ls -l test/ ls: cannot open directory test/: Permission denied ayush:~> groups git ayush:~> id uid=11417(ayush) gid=30(git) groups=30(git) I have been seeing this error for a while now and it was not there before. This is not a new group and I have using it in some of my code here and there. BTW, I switched to another user who is also part of this group who was able to access "test" directory without any issues. EDIT 1: Its not just this, I am unable to change the group of the folder "test" with 770 permissions. I am getting an "operation not permitted" error. And, I am facing this issue with only the group "git". I am able to switch the group of the folder to another group of which I am a member of. But then I am not able to switch back the user to "git".
I found the issue. I have a cap of 16 groups and I had added my user to 17 groups. The "git" group was listed as the last and hence I wasn't counted as a member of it when doing group operations as only the first 16 groups were considered.
Unable to access group files even though user is part of the group
1,533,526,043,000
I'm an administrator of my Ubuntu 16.04.3. On this system, there are many users, who are in the list of sudoers. I'm thinking if I can make such a configuration as below: I'd like to create a Bash script for each user, each user can do nothing but execute this script. In a word, each user can tell me what they want to do, and I'll put it into a Bash script. When they login, they can do nothing but execute this script.
Initial setups You can setup a script like so: $ cat /usr/local/bin/user1.bash #!/bin/bash whoami And add a file to /etc/sudoers.d like so: $ cat /etc/sudoers.d/users user1 ALL = (ALL) NOPASSWD: /usr/local/bin/user1.bash user2 ALL = (ALL) NOPASSWD: /usr/local/bin/user2.bash user3 ALL = (ALL) NOPASSWD: /usr/local/bin/user3.bash Example run Now when we login as user1: $ su - user1 $ sudo -l Matching Defaults entries for user1 on centos7: always_set_home, match_group_by_gid, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin User user1 may run the following commands on centos7: (ALL) NOPASSWD: /usr/local/bin/user1.bash We can see that this user is only allowed the 1 command user1.bash. If we run it. we can see that this user is able to run the script: $ sudo /usr/local/bin/user1.bash root But cannot run anything else: $ sudo whoami [sudo] password for user1: Sorry, user user1 is not allowed to execute '/bin/whoami' as root on centos7. References Take Control of your Linux | sudoers file: How to with Examples Using sudo
Is it possible to give permission to a user via sudo for only a specific Bash script? [duplicate]
1,533,526,043,000
Does execution of a file need read permission? It is natural to think yes, because execution of a file needs to load the file into memory. If the answer is no, why is that? In particular, same question when the file is a directory? Thanks.
When you execute a file, in many cases you don’t need to read it, so you don’t need read permission. You’re right, the system needs to read it on your behalf, but that’s not defined as requiring the read permission (because nothing running as you ever needs access to the file’s contents). The exception is any circumstance where executing a file involves reading it, by a process running with your credentials. So shell scripts, in fact scripts in general, require read permission, as would any executable handled by binfmt_misc. Likewise, accessing a directory doesn’t involve reading it: you can enter a directory without listing its contents. Think of this as exploring a building with a blindfold: execute/search permission allows you to unlock doors to change rooms (as long as you already know where the doors are), read permission allows you to remove the blindfold to see what’s in the room.
Does execution of a file need read permission?
1,533,526,043,000
I have created a backup-user (let's just call it jeremy) on an Ubuntu-server. Then I've created a backup-dir, containing files from several different servers: /backup | |--server1 | |--daily_backup | |--weekly_backup | |--server2 | |--daily_backup | |--weekly_backup I've then granted access to the backup-dir for jeremy with the following command: setfacl -R -m u:jeremy:rwx backup/ However... If I login with the root-user and create a new directory, for instance: /backup/server2/monthly_backup, then jeremy won’t have access to the folder. Is there a way to make it so that both root and jeremy can read, write and execute everything in the /backup-directory?
One must remember to create a default mask for all new filesystem objects as well. setfacl -d -m u:jeremy:rwx backup/
Grant access for user to folder (even files created after permission is granted)
1,533,526,043,000
Someone asked a question on Ask Ubuntu about why they got permission denied when they entered in a Bash shell /etc/profile I know this is because the file has no execute permission. Even root cannot execute it (sudo /path/to/file/with/no/execute/bits fails with the uninformative error sudo /path/to...: command not found). I also know that root can enter a directory with no execute bits, so the absolute prohibition on executing non-executable files seems special. In chat, Eliah Kagan opined that the reason root would not be able to execute non-executable files was to protect root (presumably, from accidentally executing dangerous code). I briefly wondered why anyone would want to execute /etc/profile and thought that if anyone did want to execute it, they would probably actually want to source it (because it is a configuration file that sets environment and shell variables). I then realised that execute permission is not needed to source any regular file. But source executes the file in the current shell! The file can contain any command, and . file will go right ahead and execute it. If execute permission is restricted to prevent accidental execution of potentially dangerous code, why is it possible to execute non-excutable files using the source command?
I don’t think executing a non-executable file fails on purpose to prevent accidental execution of potentially dangerous code. It’s just part of the semantics of execve: it fails with EACCES if “Execute permission is denied for the file or a script or ELF interpreter.” (I’m quoting from the Linux execve manpage. POSIX says something similar: “Search permission is denied for a directory listed in the new process image file’s path prefix, or the new process image file denies execution permission.”) Unix/Linux has never been particularly concerned with preventing users from blowing their own feet off. I think the explanation is rather more prosaic: the specifications for execution and sourcing are different. Direct execution asks the kernel to execute a given command, and that enforces execution privileges. Sourcing a file is just specified as reading it and executing it; in fact the bash manpage explicitly states that “The file searched for in PATH need not be executable.” POSIX says “Unlike normal command search, however, the file searched for by the dot utility need not be executable.” (. is equivalent to source.) Note that you can execute binaries even when they’re not executable, using a technique similar to sourcing them: $ cp /bin/ls . $ chmod 644 ls $ /lib64/ld-2.26.so ./ls Kusalananda’s point about comparing bash’s source and POSIX . is interesting. In non-POSIX mode, if source is given an argument without a path, it tries to find it in the PATH, and if it doesn’t find it, looks in the current directory; in POSIX mode it doesn’t, because POSIX forbids this: Some older implementations searched the current directory for the file, even if the value of PATH disallowed it. This behavior was omitted from this volume of POSIX.1-2008 due to concerns about introducing the susceptibility to trojan horses that the user might be trying to avoid by leaving dot out of PATH. That doesn’t really change much in the discussion at hand though since an argument with a path will be processed by source or . in any case. (And really you should always use a path, even if only relative, for source arguments, to avoid surprises when you try to source something which is also on your PATH. Try creating a file named test and sourcing that with source test in bash to see what I mean.)
Why isn't execute permission needed to source a file? [duplicate]
1,533,526,043,000
As a non-privileged user, owning a directory on an EXT4 filesystem where I have all the necessary rights (rwx) gives me the possibility to change content and ownership of files (e.g. vim file and :w!) within it even if they are owned by root and even if I don't have the right to change them (root:root and 0644). Is that somehow possible with a directory owned by root if that directory is within a directory owned by my non-privileged user?
The owner of a directory can change the contents of the directory however they want. Even if there's a file in the directory that the directory owner isn't allowed to write, the directory owner can remove that file and create a new file by the same name. More generally, if you have write permission to a directory, then you can remove and create files in that directory. Thus you can change files in that directory, not by writing to them if you don't have write permission on the file, but by deleting the existing file and creating a new file by the same name. If you own a directory parent and it contains a subdirectory child that is owned by root and you don't have write permission on child, then you can't modify files in child. However, you can rename child and create a new subdirectory called child, which will be owned by you and thus can contain whatever you want. This is why security checks that verify file control (e.g. the sanity checks that OpenSSH makes on private key files) verify the whole directory chain up to the root. Likewise, if you give a user sudo rights to run a file, the whole path to the file should be controlled by root. For example, don't give a user sudo rights to run a program that's under their home directory. (On the other hand, a setuid root program anywhere is fine, because setuid is attached to the file itself, not to its path.) Anyone who controls any intermediate step in the directory path can substitute their own content, not by editing the actual file, but by renaming a directory at the point in the path.
Change ownership of directory owned by root
1,533,526,043,000
It seems I need to use sudo to ls directories that I own and have r/w permissions on. If I try to ls my media drive, I can see it, but not its sub-directory, even though I think owning that sub-directory should enable me to do so. When I try, I get this result: me@icvr1:/home$ ls -al /media/ total 12 drwxrwxrwx 3 root root 4096 Dec 20 11:05 . drwxr-xr-x 25 root root 4096 Dec 19 12:41 .. drw-rw-rw-+ 4 me me 4096 Jan 4 12:01 innovationcommons me@icvr1:/home$ ls -al /media/innovationcommons/ ls: cannot access '/media/innovationcommons/External_Storage': Permission denied ls: cannot access '/media/innovationcommons/DataStorage': Permission denied ls: cannot access '/media/innovationcommons/..': Permission denied ls: cannot access '/media/innovationcommons/.': Permission denied total 0 d????????? ? ? ? ? ? . d????????? ? ? ? ? ? .. d????????? ? ? ? ? ? DataStorage d????????? ? ? ? ? ? External_Storage me@icvr1:/home$ ls -al /media/innovationcommons/DataStorage ls: cannot access '/media/innovationcommons/DataStorage': Permission denied However, if I use sudo, I get this more expected and useful result: me@icvr1:/home$ sudo ls -al /media/innovationcommons/ [sudo] password for me: total 16 drw-rw-rw-+ 4 me me 4096 Jan 4 12:01 . drwxrwxrwx 3 root root 4096 Dec 20 11:05 .. drwxrwxrwx 1 me me 4096 Jan 3 13:35 DataStorage drw-rw-rw- 4 me me 4096 Aug 29 11:33 External_Storage me@icvr1:/home$ sudo ls -al /media/innovationcommons/DataStorage total 16 drwxrwxrwx 1 me me 4096 Jan 3 13:35 . drw-rw-rw-+ 4 me me 4096 Jan 4 12:01 .. drwxrwxrwx 1 me me 4096 Jan 2 16:08 Images drwxrwxrwx 1 me me 496 Jan 3 13:37 Places drwxrwxrwx 1 me me 0 Dec 12 14:53 $RECYCLE.BIN drwxrwxrwx 1 me me 4096 Dec 12 14:54 System Volume Information Why can't I successfully ls -al /media/innovationcommons without using sudo, or even just ls its sub-directories?
You don't have execute bit of the folder. The execute bit of the directory allows the affected user to enter the directory, and access files and directories inside See also: Execute vs Read bit. How do directory permissions in Linux work?
Why don't I have permission to ls directories I own and have r/w permissions for? [duplicate]
1,533,526,043,000
we have under /var/scripts/.../.../.. a lot of script as ( .sh .bash .py ) /var/scripts/.../.../klo.py /var/scripts/.../.../klo.sh /var/scripts/.../.../kjrbom.py . . . . how to add for these scripts the execution permission +x , by find command find need to add to all scripts that ended with ( .sh / .bash / .py ) the +x permissions find /var ......... chmod +x .....
With find: find /var/scripts/ -type f -regex '.*\.\(py\|sh\|bash\)$' -exec chmod +x {} + You might want to check the files first: find /var/scripts/ -type f -regex '.*\.\(py\|sh\|bash\)$' -regex '.*\.\(py\|sh\|bash\)$' matches file(s) ending in the given three patterns -regex matches the whole filename, hence we need .* to match anything at start
how to add execution permission (+x) to all scripts
1,533,526,043,000
I'm using proftpd on my server (ubuntu 16.04 x86_64). I see that proftpd run under proftpd user: $ ps aux | grep [p]roftpd proftpd 26334 0.0 0.1 112656 716 ? Ss 04:39 0:00 proftpd: (accepting connections) proftpd write logs to /var/log/proftpd. But write to this directory can only root: $ ls -la /var/log | grep [p]roftpd drwxr-xr-x 2 root adm 4096 Jun 1 04:39 proftpd ls -la /var/log/proftpd total 76 drwxr-xr-x 2 root adm 4096 Jun 1 04:39 . drwxrwxr-x 7 root syslog 4096 Jun 1 04:39 .. -rw-r----- 1 root adm 0 May 15 15:53 controls.log -rw-r----- 1 root adm 7611 Jun 1 09:54 proftpd.log -rw-r----- 1 root adm 23207 May 29 04:39 proftpd.log.1 -rw-r----- 1 root adm 3649 May 21 04:39 proftpd.log.2.gz -rw-r----- 1 root adm 521 Jun 1 09:42 xferlog -rw-r--r-- 1 root adm 17656 May 31 22:55 xferlog.1 -rw-r--r-- 1 root root 0 Jun 1 04:39 xferreport How proftpd write logs? Is it right way, that owner of proftpd directory is root. May be it should be proftpd? Why files (logs) has no permissions to read for other. Is it unsecure?
ProFTPd, like many other services on Unix, uses syslog to do logging. syslog is a process running with superuser privileges. This means that ProFTPd itself never has to create files in the log directory. Yes. It is as it should be. DON'T CHANGE THIS In general, any logged user activities should only be accessible by the superuser. This is to protect the users' privacy. This is my personal opinion. For further information about logging with ProFTPd, see http://www.proftpd.org/docs/howto/Logging.html In general, assume that a service that you have installed behaves as intended, unless it obviously misbehaves. If it's a program installed from a package manager, then it has obviously undergone testing on the version of Unix that you run, and if you find a bug you should contact the package maintainer about this. Most of the time, though, "bugs" are usually the result of running on a highly customised system or with extreme or unusual configurations, and getting it wrong. A default install is very seldom wrong, and should only be "tweaked" once you really know what you're doing. This goes especially for changing permissions or ownership on files and directories.
How process (user1) can write log to directory (root)
1,533,526,043,000
My PC is Mac pro. I removed x for rm in case of delete files by accident: sudo chmod o-x /bin/rm However, when I reboot my PC, I got one message on the terminal: -bash: /bin/rm: Permission denied If I do o+x for bin/rm, the message will disappear. So I just want to know that which files are automatically removed when the system starts up.
There is a lot of cleanup at startup, for example removing files in /tmp. So you shouldn't change /bin/rm permissions. If you fear to delete files by accident you can alias rm to rm -i so that you will be always prompted for confirmation. alias rm='rm -i' in /etc/profile or /etc/bash.bashrc or equivalent.
Why is the command rm called when the system starts up
1,533,526,043,000
Target situation: data/file.txt owned by myUser:myUser and "-rw-rw-rw-" (chmod 666) symbolic link /tmp/file.txt owned by postgres:postgres and "-rw-rw-rw-" So, I can edit the file with my user, and the other user (postgres) can read and write it also, but the link and the file are owned by different users. Real world situation: same step by step of this other question, sudo rm /tmp/file.txt # if exist, remove cd ~ sudo chmod 666 data/file.txt ls -l data/file.txt # "-rw-rw-rw-" as expected more data/file.txt # working fine sudo ln -sf $PWD/data/file.txt /tmp/file.txt # fine ls -l /tmp/file.txt # "lrwxrwxrwx", /tmp/file.txt -> /home/thisUser/file.txt more /tmp/file.txt # fine sudo chown -h postgres:postgres /tmp/file.txt sudo more /tmp/file.txt # NOT WORK! A workaround is sysctl -w fs.protected_symlinks=0 (then more /tmp/file.txt will work fine) but it is not secure; I need another solution. See real-life problem here
The directories /home and /tmp aren't really appropriate for this, and neither is using a symbolic link. Make a directory to store the file and set up permissions for it using an ACL. Let's say that your username is peter. Some of the commands below might be superfluous, and these are given merely to be explicit. # Make a new directory to store the `file.txt`. # sudo mkdir /var/my_dir # Change ownership and group ownership to root. # sudo chown root:root /var/my_dir # Only allow root and members of root to read the directory. # sudo chmod 0750 /var/my_dir # Begin to augment standard permissions with ACLs. # Below, allow peter rwx for all new file system objects in /var/my_dir. # (-d means "default" and -m means "mask") # setfacl -d -m u:peter:rwx /var/my_dir # Set the same mask for the directory itself. # setfacl -m u:peter:rwx /var/my_dir # Below, allow postgres r-x for all new file system objects in /var/my_dir. # setfacl -d -m u:postgres:r-x /var/my_dir # Set the same mask for the directory itself. # setfacl -m u:postgres:r-x /var/my_dir Now, peter can create files in /var/my_dir, and postgres can read them. It may also be convenient to link the directory in your home directory. cd && ln -s /var/my_dir . Files in /tmp should disappear on reboot. Generally speaking, or perhaps arguably, it would not be a good practice to link to files in your home directory. I could expound on that statement if you don't already understand. A better location for this purpose might be /usr/local/var/my_dir, but the main point is to try to get the permissions right instead of using /tmp and /home with symbolic links for this purpose. Update This might also be done in a standard, simpler way that would be more compatible with other software like SFTP/SCP clients. sudo mkdir /var/my_dir sudo chown peter:postgres /var/my_dir sudo chmod 0750 /var/my_dir Now, whatever files exist in /var/my_dir can only be read by root, peter and postgres, while only peter and root can write. Then just make sure your umask creates files that postgres can read. cd touch test ls -l test If the result shows r for "others," then postgres will be able to read the file in /var/my_dir. Yet another approach... sudo touch /usr/local/var/file.txt sudo chown peter:postgres /usr/local/var/file.txt sudo chmod 0640 /usr/local/var/file.txt cd ln -s /usr/local/var/file.txt . Above, we work with a single file, no directories. Again, all of these are simply setting permissions. You merely have to decide how you want to approach the situation, having more knowledge about what you are doing than what we can read in the question.
Best workaround for file's symbolic link with different group than file
1,533,526,043,000
Yesterday one of our servers was having a problem, and it turned out the file /etc/init.d/nfs-kernel-server had lost it's permissions, they were reported as just ------------. Setting the permissions back to the same as the other files resolved the issue, and I'm wanting now to debug what happened. Is there anyway to get a log of when a files permissions changed, and why?
There's no default log for these kinds of actions, you need to set it up in advance. You might consider using auditd, and configuring it to look for changes in the files you're finding with their permissions changed. You can then find information about which users and processes changed which files. For example, you could do something like this ad-hoc: auditctl -w /etc/init.d/nfs-kernel-server -k nfs-kernel-server You can also add this to /etc/audit/audit.rules for long term use: cat > /etc/audit/audit.rules << 'EOF' -w /etc/init.d/nfs-kernel-server EOF After this, you need to start and enable auditd. On most systemd distributions, this can be done like so: systemctl enable auditd systemctl start auditd For non-systemd systems, you will want to consult your documentation, but it is probably a service named "auditd". After that you can consult logs at /var/log/audit/audit.log, or wherever auditd is configured to log. You will see results like this: type=SYSCALL msg=audit(1349582090.742:414): arch=c000003e syscall=268 success=yes exit=0 a0=ffffffffffffff9c a1=17be0f0 a2=1ff a3=4000 items=1 ppid=2859 pid=3069 auid=1001 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=2 comm="chmod" exe="/usr/bin/chmod" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=CWD msg=audit(1349582090.742:414): cwd="/root" type=PATH msg=audit(1349582090.742:414): item=0 name="/var/www/html/1" inode=6171184 dev=fd:00 mode=040755 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:httpd_sys_content_t:s0
How do I find which process is causing a file to lose its permissions? [duplicate]
1,533,526,043,000
I'm running a rsync via apache to sync an assets directory rsync -avz -e 'ssh -l rsync -i /home/rsync/.ssh/rsync -o StrictHostKeyChecking=no' /var/www/html/site/Uploads centos@$IP:/var/www/html/site/Uploads This works correctly but the ownership changes from apache to centos as it's the user. I could setup the keys for the apache user however that user can't be logged in so that doesn't work. How can I get rsync to either run as apache to preserve the ownership or run as the centos user and maintain the owner as apache (cron won't work for my case).
So the best way I found is to have a user that has sudo access for only that command and use --rsync-path='sudo rsync'. e.g.: rsync -avz -e 'ssh -l rsync -i /home/rsync/.ssh/rsync -o StrictHostKeyChecking=no' /path/ --rsync-path='sudo rsync' [email protected]:/path/
rsync files with apache permissions over ssh
1,533,526,043,000
I have list of file with permission -rw-r-----. I want modify this permission and give access to other. i.e -rw-r--rw- Without modifying current permission setting, just add permission to 'other' user.
chmod o+rw yourfile For other add (+) read and write permissions. I think it's quite semantically meaningful. Alternatively, you could learn the numeric notation. R is worth 4, W is worth 2 and X is worth 1. If you want read and write, for example, you add 4 and 2 together giving 6. So to keep the permissions the same for owner (6) and group (4) you could do: chmod 646 yourfile
Adding others rw permission to file
1,533,526,043,000
Say, there is a directory ~/docs with owner boo and group boo and permissions rwxr-x---. Assume there are important files apple.txt and orange.txt in docs which user boo wants to protect from himself (from accidental deletion, e.g. rm -rf /home/boo/*), but it's not an option to change permissions of docs to r-xr-x--- or move the files. What possible solutions are there? Normal users can't do chattr +i apple.txt orange.txt (and this is Linux-only anyway). So the only option I can conceive of would be to first chmod 550 apple.txt orange.txt and then hardlink ln ~/docs/apple.txt ~/docs/orange.txt ~/locked/ the files to a directory ~/locked/ and chmod 550 /home/boo/locked/. Is this right? Or is there a simpler way?
You're ruling out the normal methods of preventing deletion, so this calls for a workaround where deletion is possible but not catastrophic. If apple.txt and orange.txt are symbolic links, then a stray rm -rf in that directory will only remove the symbolic links, not the actual data, so the symbolic links can just be re-created. If for some reason the files can't be symbolic links then a fancier option would be to use a FUSE filesystem that performs a union mount such as funionfs or unionfs-fuse. Put the important files in a branch other than the main branch so that deleting them will only hide them and not delete them from the underlying storage. Of course, the most robust way of ensuring that the files aren't lost is to back them up. If you keep a history of the files and not just the latest version, this also protects against accidental overwrite (e.g. >apple.txt instead of <apple.txt). Version control (in a repository that's backed up!) is the ideal way of keeping a history of old versions.
Protecting files from rm -rf in writeable directory
1,533,526,043,000
I'm using a Linux system on which I don't have root. My home directory is remote-mounted and backed up (and there's a quota on that filesystem). Now, I would like to work on some files on this machine itself, they don't need to be backed up, and I would like to (but not have to) have them relatively large. Where can I put these files? Where can I create a folder of my own outside my own home directory? Notes: Under /tmp is not a solution, the files need to persist. It's a Fedora 20, but if you have a Debian'ish answer that's interesting as well. The local filesystems don't have a quota.
You could use /var/tmp, but: If you have a quota, the admin will probably not appreciate you creating large files outside of your $HOME directory. Quite likely you even got a limit for /var/tmp. So that might just be an option for small files. However, if you are member of the fuse group (ask your admin to add you to the group if you're not), you can use sshfs and mount a remote file system of arbitrary size. Example: sshfs <user@host:directory> <mountpoint>
Where can I/should I place files outside my home directory?
1,533,526,043,000
I have accidentally changed the permission of "/usr/bin" directory and its files by the command: $chmod 775 /usr/bin -R First, there was a problem with sudo but I fixed it. Now I am suspicious that some programs may not run because of changing their permission. I wonder it is possible to turn back its previous permission? I am using Debian/testing.
Most programs in /usr/bin should have permissions 755 — readable and executable by all, writable only by their owner, which is root. A few programs are setuid or setgid: they have extra privileges, which are confered by the setuid or setgid bit in the permissions. /usr/bin/sudo is one of them; it needs to be setuid root: chmod 4755 /usr/bin/sudo restores it. If you only have official packages from Debian (as opposed to packages in distributions derived from Debian or from other sources), then you can find out which ones contain setuid/setgid binaries by going through the Lintian reports: setuid, setgid, both. In principle, all these packages should come with a file in /usr/share/lintian/overrides that declares the setxid binary (the tag “overridden” on these pages indicates the presence of such a declaration), but some packages don't comply (including ubiquitous ones such asat and xserver-xorg). The following script prints out a shell script that executes the chmod command to restore files in /usr/bin to their default permissions, if their default permissions includes the setuid or setgid bit. wget -q -O - https://lintian.debian.org/tags/set{uid,gid,uid-gid}-binary.html | sed -n 's~^.*> *\(usr/bin/[^ ]*\) \([0-7][0-7][0-7][0-7]\).*~[ -e /\1 ] \&\& chmod \2 /\1~p' In addition, some permissions can be configured locally. These permissions are registered with `dpkg-statoverride. You can list them with dpkg-statoverride --list '/usr/bin/*' and you can reapply these permissions with dpkg-statoverride --list '/usr/bin/*' | awk 'system("chmod " $3 " " $4)' If you have packages not from Debian, the only way to be sure to get correct permissions is to reinstall them with apt-get --reinstall install PACKAGE-NAME.
Is it possible to change the directory permission to its previous state?
1,533,526,043,000
I'm having issues with dropbox so I'd like to uninstall and reinstall it. To do so I need to remove ~/.dropbox-dist but no matter what I do it won't budge. If I run ls -l I get: drwxr-xr-x 3 user user 4096 Nov 13 2014 .dropbox-dist I have full permissions on the machine. I have tried, sudo rm -rf ~/.dropbox-dist rm -rvf ~/.dropbox-dist sudo su, rm -rf /home/user/.dropbox-dist Removing from Nautilus chmod 777 ~/.dropbox-dist But the error is always the same, "Operation not permitted"
There are few things you could do here: First check whether you have a Dropbox daemon running. Check the attributes of the Dropbox folder using lsattr and if the folder is not editable, then change its attributes to editable using chattr. UPDATE As OP has reported in the comments, the .dropbox-dist folder contains i attribute which means the folder cannot be modified, deleted or renamed. Hence to change the attrubute, you should use chattr: sudo chattr =e .dropbox-dist
How to delete stubborn directory?
1,533,526,043,000
On Linux Mint 17.0 Cinnamon Edition, I want to use /var/run/postgresql as the unix_socket_directories option for all of my postgres databases. Whenever I run the command pg_ctl -D postgres-data -o '-F -p 33311' start to start my local database, I get the error FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.33311.lock": Permission denied. As many answers across AskUbuntu, StackOverflow and various forums suggest, I have to run sudo chmod 777 /var/run/postgresql or sudo chown -R $USER:$USER /var/run/postgresql to change the permissions of the directory so that I can write to it. Then I am able to start my database. However, every time I reboot, the permissions go away; the directory is no longer world-writable and the user postgres-xc reclaims user and group ownership over the directory. Neither sudo adduser $USER postgres or sudo adduser $USER postgres-xc alleviates the permissions issue. I tried doing a clean install as described here, but I still have the issue on reboot. I've tried changing the value of unix_socket_directories to /tmp in ./postgres-data/postgresql.conf (the local database config file), and this allows me to start that particular database without having to update permissions on every reboot. However, I also have a script which uses pg_ctl -D $DIR initdb && pg_ctl -D $DIR start to setup and start databases on the fly. As such, a default postgresql.conf config file is used for these databases, so unix_socket_directories is the unwritable /var/run/postgresql and I get permission denied errors when running that script. Manually/programmatically editing these configs on-the-fly to use unix_socket_directories = '/tmp' is... undesirable. I know that I could use the -o flag with pg_ctl to override the unix_socket_directories option to /tmp, but this script is shared by other developers who do not use Ubuntu, so I would not necessarily want to restrict everyone to using the /tmp directory, especially if their configurations differed slightly. I would prefer everyone use the default location for their installation. Personally, I would also prefer to keep the default directory for general compatibility with other Ubuntu packages; e.g., pgadmin looks at /var/run/postgresql for a lock file by default. I have also tried editing /etc/postgresql/9.3/main/pg_ctl.conf in an attempt to automatically pass set these options whenever I use pg_ctl: # Automatic pg_ctl configuration # This configuration file contains cluster specific options to be passed to # pg_ctl(1). pg_ctl_options = '-o "-c unix_socket_directories=/tmp -c unix_socket_group=jackson -c unix_socket_permissions=0777"' But that did not have any effect. Please advise on how I can use /var/run/postgresql as my unix_socket_directories option for all of my postgres databases without having to run sudo chown -R $USER:$USER /var/run/postgresql every time I restart my system. Thanks.
Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf
Permanently change permissions of /var/run/postgresql
1,533,526,043,000
A share on the server is defined as follows [share] path = ... read only = no create mask = 0777 directory mask = 0777 force create mode = 0777 force directory mode = 0777 valid users = dobiasd It is mounted via the fstab on the client: //server/share /home/dobiasd/share/ cifs file_mode=0777,dir_mode=0777,iocharset=utf8,username=dobiasd,password=dummy 0 0 The client can create files and directories. A newly created directory can also be deleted again, but it is not possible to create new files or directories inside this new directory. To allow this I first have to do a chmod -R 777 . on the server, so the "drwxrwxr-x" of the directory becomes a "drwxrwxrwx". How can I get samba to create the new directory immediately in a way so that subfolders can be created in it?
So, this is a Samba share, mounted on a Linux box (clients using Windows don't have the issue)? If I understand well, it could be only a umask issue. If you type umask on your client, you will probably get 0002 which means that when you create a new directory, its ACLs are rwxrwxr-x (rw-rw-r-- for files). So, if you want all your newly created folders and files to be world writeable, you can set umask 0000 (in your .bash_profile for instance). Of course, this may be a bad idea... If I were you, I would ensure all your trusted users are members of a same group, say friends and set these rights on your parent share directory: chmod g+rwxs /path/to/share Here, the role of the sgid bit (the s above), is to ensure that all the directories and files which will be created under this directory will be owned by the group owner of the parent directory. Example to be more clear (here, apaul is member of users (primary) and friends groups): $ mkdir /tmp/share $ mkdir /tmp/share/dir1 $ ls -l /tmp/share drwxrwxr-x 2 apaul users 4096 7 april 21:48 dir1 $ chgrp friends /tmp/share $ chmod g+rwxs /tmp/share $ ls -ld /tmp/share drwxrwsr-x 4 apaul friends 4096 7 april 21:49 share/ $ mkdir /tmp/share/dir2 $ ls -l /tmp/share drwxrwxr-x 2 apaul users 4096 7 april 21:48 dir1 drwxrwsr-x 2 apaul friends 4096 7 april 21:49 dir2 Then, all members of the friends group can create sub-directories (or file) under the share, but this one is not world writeable.
How to automatically get write access to newly created directories?
1,533,526,043,000
Consider the following situation: /dev/sda1, /dev/sda2, /dev/sda3 are 3 partitions of the /dev/sda disk. Ubuntu is installed on sda1 and /home mounted on sda2. Only one user foo on Ubuntu system so its home folder is /home/foo on /dev/sda2. I'm going (and I know how) to install another distro (e.g. a Lubuntu) on /dev/sda3 with only one user blah. My question is: How to do that in such a way that the user blah can not access neither mount the partitions /dev/sda1 and /dev/sda2? Is it enough to remove any entry referencing it on fdisk? I'd like to make those 2 partitions only available for the user foo on Ubuntu. I'd like that user blah wouldn't have access even using sudo. My idea is, while installing the new distro on sda3 just don't ask to mount the other partitions so that the disk for the new distro is only sda3.
There are several things mixed here mounting a filesystem by user and superuser, accessing files on a mounted file system and accessing the data on the "raw" device. mounting a file system root can always mount a file system, provided he can access the device that carries it - which it can when the kernel recognizes it. Users are only allowed to mount a file system, if it is referenced in /etc/fstab and either user or users is among the options for that entry (read the mount(8) man page). accessing files on a mounted filesystem Again, traditionally root can always access any files on a mounted file system (unless a patched kernel is used of course). Users are subject to file permissions. accessing data on the raw device (e.g. /dev/sdaX) Same as with files above. Users usually don't have permissions to access raw block devices, root does. Hence if you want to prevent user in the second system from mounting or accessing data on the mounted file system used by the first operating system, edit /etc/fstab and apply permissions appropriately. Remember, that permissions on a file system are bound to UIDs/GIDs not tu user/group names - thus if user foo from system 1 has the same numeric UID as user bar from system 2, they have exactly the same right when accessing files. If you want to make sure that the file system can't be accessed even by a superuser, encryption is the only way to go. Or you can run the second system in a virtual machine on the first one, giving it access only to parts of the hard drive you want. There are various ways to set it up like this, unless you'd want to be able to boot the second installation on bare metal as well, you can just give the virtual machine whole /dev/sda3 as its /dev/sda. One last note (especially for users of Ubuntu and similar distributions that cripple sudo configuration by allowing all users run everything as administrators by simply prepending sudo to their commands) - "access through sudo" is a misplaced term - you either have or have not some (or all) privileges that are usually associated with the root (UID 0) user. You can get the same privileges with su.
How to deny mounting permission?
1,533,526,043,000
This is an odd one, it only happens on one server (shared hosting, so I have limited access to configuration and logs), but I can't wrap my head around it. I have a shell script which runs some app's deployment. The file has a +x flag, but I can't run it by simply calling its name from shell, I get an "access denied" error. Invoking bash with the filename as an arguments works like a charm. It looks something like that: [someuser@someserver:~] $cat test.sh echo "hooray!" [someuser@someserver:~] $chmod +x test.sh [someuser@someserver:~] $ls -l test.sh -rwxrwxr-x 1 someuser someuser 14 Oct 8 11:27 test.sh [someuser@someserver:~] $./test.sh -bash: ./test.sh: Permission denied [someuser@someserver:~] $bash test.sh hooray! Adding a #!/bin/bash at the beginning doesn't help. I also tried from other shell (default is bash, tried in sh), same thing happened. This is not that big of a problem, but it's baffling for me. What could be the cause?
I think it is because of the "noexec" mount option for the folder your script is in. You may try to check that by this command mount | grep `df -P /path/to/folder/with/script | tail -1 | cut -d ' ' -f 1`
Shell script permission denied despite +x flag
1,533,526,043,000
I know that r means read permission, w means write permission, and x means execute permission in the output of ls -l, like -rwxr-xr-x. But My question is what is behavior difference on operation system to this modes? I mean what system does with read only file and what system does with writable file or how system does when it see an executable file? Or better to say: why are not all of files in one mode? I'm asking not about the differences of permissions for user, group, and others, please ignore that. My question is about what the technical difference between executable mode and readable and writable mode. What is the difference between these modes on files access?
When a program wants to read or write to a file, it needs to call the system call open() for the file first. One of the arguments to the call specifies which operations the program wants to be able to do. It the program indicates it wants to read or write the file, and the process does not have the perspective for the operations, the open() call ends up in the error EACCESS, and the file can not be used. In a similar way, when a program - for example, your shell - needs to execute a program file, it uses the system call execve(). This returns the error EACCESS if the execute permission is not given by the file mode. Below are some relevant parts of the man pages in section 2, "system calls" From the man page for open(2) man 2 open: OPEN(2) Linux Programmer's Manual OPEN(2) NAME open, creat - open and possibly create a file or device SYNOPSIS #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); [ ... ] The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read- only, write-only, or read/write, respectively. [ ... ] ERRORS EACCES The requested access to the file is not allowed, or search per‐ mission is denied for one of the directories in the path prefix of pathname, or the file did not exist yet and write access to the parent directory is not allowed. (See also path_resolu‐ tion(7).) From the man page for execve(2) man 2 execve: EXECVE(2) Linux Programmer's Manual EXECVE(2) NAME execve - execute program SYNOPSIS #include <unistd.h> int execve(const char *filename, char *const argv[], char *const envp[]); [ ... ] EACCES Execute permission is denied for the file or a script or ELF interpreter.
What is the system-level effect of file permissions? [closed]
1,533,526,043,000
This is my script #!/usr/bin/python import os print "hello world from python" os.system("echo 'hello world from bash'") os.system("umask 055") os.system("ls -alh > test") If I run this code the permissions of file test are not set as 722 but as 600. What could be the reason? the Umask of my shell is 0077.
When you run umask with system it runs in a shell: umask changes the mask of that shell, but the shell then immediately terminates and the change is lost. To change the umask of your Python process, use os.umask(), which will: Set the current numeric umask and return the previous umask. That way the change will be made to your running program, rather than another program that immediately dies afterwards.
Why can't my python script change umask?
1,533,526,043,000
I am configuring a Linux work station that will be used by a small number of users (20-30). These users will belong to a small set of groups (5-10) with each user belonging to at least one group and potentially multiple groups. On the work station there are files that should only be writeable by members of a particular group. Each file is only writeable by members of one group so standard Linux permissions should work just fine. I have two questions. Who should own the files that already exist? I was thinking either root or creating a set of dummy users corresponding to the groups. Is there a better choice that I am missing? It seems like this is unlikely a unique situation so I was hoping there was a standard convention. The second question is where should I put the files. If I made dummy users I could create subdirectories in /home/. If root owns the files do I go with /srv/groups/ or maybe `/share/? Again is there a convention?
Who should own the files that already exist? I was thinking either root or creating a set of dummy users corresponding to the groups. Leaving them owned root but belonging to a common group, presuming the files are masked 0002 (i.e., are group writable) has a little bit of an advantage in terms of preventing them from becoming accidentally reowned if you create users to match the groups and the people who are in the groups can log in as that user. I'm referring to accident here because of course a malicous user in the group will just be able to delete the files in any case. But if they are owned root (or any other user that is not the group), then while someone in the group can still write to them (and thus delete them), they won't be able to reown or modify the permissions such that other members of the group won't be able to subsequently access the file. Using a group but no fixed owner (i.e., files can be owned by anyone, but should be in the correct group with group permissions) has an advantage if users will be creating files (see below). Creating new users just to match the groups will probably create more potential problems than it actually solves. If using group permissions works, stick with that. You can also create a little command for the superuser: #!/bin/sh chown -R root:groupx $1 chmod -R g+w $1 And use it foo /some/directory. This will ensure everything in the tree is owned root, with group groupx, and group writable. There is a potential problem using root as the owner if root then adds the setuid bit to a file, but I believe only owner can do that. If you are really worried, create a dummy user -- but not one that matches the group. One that has no privileges but no one can use. There is one further issue with users creating new files, which by default will be owned by them. They will be able to change it to the correct group, which will make the file accessible to others, but they won't be able to change the owner. For that reason, and because people may forget, you may want to run foo /some/directory at regular intervals or opportune moments (e.g. when no one is logged in, since changing the ownership may affect software which has the file open). Taking the last paragraph into account, you could just say the owner does not matter at all, only the group is important. In that case the foo command should use: chgrp -R groupx $1 instead of chown. where should I put the files Creating a /home/groupx is absolutely fine even if groupx is a group and not a user. The only potential issue would be if you then go and create a user with the same name -- but you don't want that anyway. Put the files there and foo /home/groupx. If you don't want users to be able to create files, set the directory 755. They will still be able to modify files owned by their group.
Who should own files shared by a group and where should they go
1,533,526,043,000
I am logged into my remote VM (running out of ESXi) as user xyz. I wanted to change my /etc/hosts to add some network names that were not visible by default. I first tried to run sudo vi /etc/hosts but when I got into vi, it was still telling me the file was read-only. Here are the privileges: >ls -l /etc/hosts -rw-r--r-- 1 root root 416 2013-06-19 08:08 /etc/hosts I also noticed that almost every other file in /etc has a lsattr of -----------------e-, only hosts has ----i------------e-. E.g.: >lsattr /etc ... -----------------e- ./python ----i------------e- ./hosts ... Then I tried to chmod and here is what I got: >sudo chmod +w /etc/hosts chmod: changing permissions of `/etc/hosts': Operation not permitted I thought that was weird because root (to which I am switched when I sudo) should be able to do anything. My sudoers file looks quite ordinary: 1 # /etc/sudoers 2 # 3 # This file MUST be edited with the 'visudo' command as root. 4 # 5 # See the man page for details on how to write a sudoers file. 6 # 7 8 Defaults env_reset 9 10 # Host alias specification 11 12 # User alias specification 13 14 # Cmnd alias specification 15 16 # User privilege specification 17 root ALL=(ALL) ALL 18 19 # Allow members of group sudo to execute any command after they have 20 # provided their password 21 # (Note that later entries override this, so you might need to move 22 # it further down) 23 %sudo ALL=(ALL) ALL 24 # 25 #includedir /etc/sudoers.d 26 27 # Members of the admin group may gain root privileges 28 %admin ALL=(ALL) ALL I am looking for an explanation why this is happening and how to work around it.
The specific attribute in this issue is i, the immutable attribute. The file was marked immutable. This means it is unchangeable at all by any user including root. Root can still change the attributes and remove the immutable attribute, but must to so first before making changes to the file, unlike standard no-write permissions to a file which root can simply ignore. These attributes are only applicable to ext[234] file systems so far as I know. You can see the man page for chattr, $man chattr to see a full list and description of the available attributes. The only one I've ever actually used is i. But some of the others include: A: atime remains unmodified when accessed a: can only be opened for writing in append-only mode c: compressed automatically j: all data is written to the journal before being written to the file s: blocks are zeros when file is deleted u: contents of file are saved when file is deleted for later undelete There are other attributes but they are somewhat esoteric and much more info can be found on them in the chattr man page.
Unable to run 'sudo chmod +w /etc/hosts'
1,533,526,043,000
I am running a small embedded system built using buildroot. I have come across this strange behaviour when trying to set up my file permissions on the target device. To illustrate what confuses me I tried the following simpler example # cd /mydir # touch tmp.txt # echo "rubbish" > tmp.txt # cat tmp.txt rubbish # chmod 0444 . # chmod 0444 tmp.txt # echo "new-rubbish" > tmp.txt # cat tmp.txt new-rubbish I am really confused by this. How can I have set the file and directory to be read only and yet I am still able to modify the contents of this file? I have an executable within the same directory and when I try and execute it I get this # chmod 0444 my_binary # ./my_binary -sh: ./my_binary: Permission denied which behaves as I would expect it to. Clearly I have some fundamental misunderstanding of how the file access model works on Linux. Can anyone explain why I am able to write to the file that I have set to be read only?
As you seem to be doing this as root that explains you have rights to write in the directory. root can also append to the file even if it permissions are -r--r--r--. The echo "new-rubbish" > tmp.txt does truncate the file (as JoelDavis pointed out), so it does not remove it and write it again (when using bash).
Changed file access to read only but I can still write to the file. Why?
1,533,526,043,000
I need to set up the following script to run as root whenever I log in: #!/bin/zsh truncate -s 0 ~yourstruly/.juniper_networks/network_connect/ncsvc.log I know how to run the script as root interactively (namely through sudo), but I can't figure out how to make the script run as root non-interactively whenever I log in. How can I do this? FWIW: the script is currently owned by root, has permissions 6755, and the file to be truncated is also owned by root and has permissions 0644, but when I run the script, the call to truncate fails with a "Permission denied" error.
The permissions of the script are irrelevant. Setuid and setgid bits are ignored on scripts on Linux and most other unices. You can configure sudo to allow you to run this script without specifying a password, with the NOPASSWD tag. Make sure that sudo doesn't require to be connected to a terminal: turn off the requiretty option. Note that the NOPASSWD-tagged rule must come before any other rule that would let you run the command with a password prompt, because the first match applies. So run visudo: Defaults !requiretty kjo ALL = NOPASSWD: /path/to/nc-logs-truncate kjo ALL = (ALL) ALL Change the first line of the script to #!/bin/zsh -f, otherwise zsh will load ~/.zshenv which isn't desirable here. Now that I've answered your literal question, this is probably not the best method. A simple chown kjo ~/.juniper_networks/network_connect/ncsvc.log would ensure that the log file belongs to you so you can truncate it at will. Better, move the log file instead of truncating it: it's often useful to keep recent logs around (for example to compare working logs to non-working logs if nc fails). Give yourself write permission on the directory (you might own it already) and mv -f ~/.juniper_networks/network_connect/ncsvc.log ~/.juniper_networks/network_connect/ncsvc.log.0 touch ~/.juniper_networks/network_connect/ncsvc.log Alternatively, make a more unixy NC package, tell ncsvc to write its logs in /var/log, and include its log in the logrotate configuration.
How to set up a script to run as root non-interactively?
1,533,526,043,000
I have an NTFS partition that I want to mount using /etc/fstab. I don't want any files to have executable permissions on this drive, so I wrote the following rule: /dev/sda2 /media/sharedfolder ntfs auto,user,noatime,noexec,rw,async 0 0 However, I don't believe this will prevent files from being created with executable permissions. It will simply prevent them from being executed. Perhaps this is fine, but is it possible to remove all executable permissions from newly created files on this partition using an /etc/fstab rule? Would using umask and fmask be enough, like this rule? /dev/sda2 /media/sharedfolder ntfs auto,user,noatime,noexec,rw,async,umask=0111, 0 0 I'm unsure because Wikipedia lists umask as an option specific to the FAT filesystem.
Wikipedia isn't as good a reference as the man page. Both the the traditional ntfs driver and the now-preferred ntfs-3g support the umask option. You shouldn't set umask to exclude executable permissions on directories, though, since you can't access files inside a non-executable directory. Instead, use separate values for fmask=0111 (non-directories) and dmask=0777 (directories) (you can omit this one since all bits allowed is the default value).
How do I mount an NTFS partition in /etc/fstab and prevent files/directories from receiving exec permissions when they're created?
1,533,526,043,000
After a problem with spam, I stopped postfix postfix stop and checked through the mailq manually to find hundreds of thousands of unsent spam. The spam was sent from one of the sites hosted locally, and I know that user has not tried to send any emails since I stopped outgoing mail. Therefore all the messages in /var/spool/postfix/maildrop that originate from that user on my machine are known to be spam, and I'd like to delete or move them to another dir for later investigation. I would like to move all the files with a given owner (in this case the user 'web2') from /var/spool/postfix/maildrop to /var/spool/postfix/temp-spam How can I do this?
You can use find and xargs, e.g.: find /var/spool/postfix/maildrop -user web2 -print0 -type f | xargs -0 -I{} mv {} /var/spool/postfix/temp-spam You can test it by inserting echo: find /var/spool/postfix/maildrop -user web2 -print0 -type f | xargs -0 -I{} echo mv {} /var/spool/postfix/temp-spam
How to cp or rm files based on ownership / permission
1,533,526,043,000
I just finished the first version of a Linux kernel module I've written in C. The module creates a device file (/dev/wn0) that controls a USB device with three LED lights. For example, running as root, I can do this: echo "#ff0000" >/dev/wn0 ...and the device will glow bright red. My problem is that I want unprivileged users to be able to access the device (by writing data to /dev/wn0). Is there a standard way to do this? Is it as simple as changing the permissions on the /dev/wn0 file? Does that create security concerns?
Ok, I see some possibilities: The quickest way, the whole point of POSIX permissions and ownership: you want someone to be able to read and/or write, you set the permissions accordingly. Just put these people in a group and change the device ownership to that group, giving the group write permissions. You may have to put this in udev rules, if your /dev is managed by udev. This is what some tools do, for example bluez does it to enable users to use bluetooth, or at least that's the method used in my distro unless I try to use "ConsoleKit". If the device is simple and there's no problem in having it used to everyone, just allow everyone to write on it. Write a daemon that starts as some user that can write on the device, grabs the device and drops its privileges by changing its UID and then processes requests from any user through, for example, TCP. Write a small binary to write for the device, that is setuid some user that can write on the device and have users use it to write to the device. That's what mount does, it is setuid root, so that regular users can mount filesystems if /etc/fstab allows them to do so. It does not create any additional security concerns, as far as you're ok with these users being able to use that device. Of course that anyone with access to the device may exploit any vulnerability in the module, but that would be possible no matter how you give people access to it. If you write a daemon, that can be exploited. Maybe it is better keep things simple and make sure your code is not vulnerable. I'd say there is no single standard way to do this — there are some ways parts of UNIX systems do this, and each part does it in the most convenient way for the kind of problem being solved.
Standard way to expose device file to userland applications running on an unprivileged user account?
1,533,526,043,000
I have started using Linux recently for development of a project and currently facing some issues with file permissions in the directories. I have some libraries .so files that I need to access from the folder /usr/local/lib. When I check the files manually in the folder, the files show that I am not the owner and root is the owner. However, in a different directory, where I subsequently tried installing the same libraries at /home/jade/cb/lib/, if I check the libraries, I do have the permission. My C++ program has been stuck since it cannot access the libraries from these. I tried changing the permissions using sudo chmod 777 -R *.* while inside usr/local/lib but the permissions or anything don't change. How do I get rid of this problem? (Distro: Ubuntu 12.10)
Most source that requires you to build it makes use of a configure script. This configure script takes a switch called --prefix that takes an argument which you can override the location of where the software will be installed. Usually you override the default location (usually /usr/local) with a directory that you have write access to. Here's a example from the software application node.js. The node.js software when downloaded and untarred/unzipped looks like this: [saml@grinchy node-v0.8.12]$ ls AUTHORS BSDmakefile common.gypi config.mk deps lib Makefile node.gyp README.md test vcbuild.bat benchmark ChangeLog config.gypi configure doc LICENSE node out src tools Running the configure script included looks like this: [saml@grinchy node-v0.8.12]$ ./configure --help Usage: configure [options] Options: -h, --help show this help message and exit --debug Also build debug build --prefix=PREFIX Select the install prefix (defaults to /usr/local) --without-npm Don't install the bundled npm package manager --without-waf Don't install node-waf --without-ssl Build without SSL --without-snapshot Build without snapshotting V8 libraries. You might want to set this for cross-compiling. [Default: False] ... ... If I want to change the default location I can call configure like so: [saml@grinchy node-v0.8.12]$ ./configure --prefix=/home/saml/my_node.js The resulting Makefile that get's generated will now target my directory instead of the default, /usr/local.
Changing permissions for files in linux
1,533,526,043,000
Possible Duplicate: How to set default file permissions for all folders/files in a directory? Say I have default umask, umask1. I would like all files/folders that I create/modify under a specific path /path/to/foo to have a different umask, umask2, and keep using umask1 for everything else. Is there a way to have the shell do this automatically for me? If so, how? Is there a way to do this for everyone else who belongs to the groupID of /path/to/foo?
You need to use default ACLs. Note that the syntax is a bit different, and is based on the positive permissions, not the negative permissions mask, e.g. rwxr-x--- would be 750 rather than 027. For example setfacl -m d:u::7,g::5,o:0 /path/to/foo or setfacl -m d:u::rwx,g::r-x,o:- /path/to/foo will make it so that files and directories created under /path/to/foo are 750 = rwxr-x--- by default. If you already have some subfolders, you'll want to add the -R flag to set their defaults recursively as well. If you get an Operation not supported error, you probably don't have ACLs enabled on your file system. The correct answer depends on many things, but if you're on Linux using ext2/ext3/ext4, try sudo mount -o remount,acl <mount point> or sudo tune2fs -o acl <file system> See also How to set default file permissions for all folders/files in a directory?
Pre-defined umask under a given path [duplicate]