date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,342,798,053,000
I'm going to be doing a fair amount of PHP work shortly, and I'm interested in learning RoR, so I installed Linux Mint 12 in my VirtualBox. The most frustrating aspect of the switch, so far, has been dealing with Linux permissions. It seems like I can't do anything useful (like, say, copy the Symfony2 tarball from my Downloads directory to my document root and extract it) without posing as the root via sudo. Is there an easy way to tell linux to give me unfettered access to certain directories without simply blowing open all of their permissions?
Two options come to my mind: Own the directory you want by using chown: sudo chown your_username directory (replace your_username with your username and directory with the directory you want.) The other thing you can do is work as root as long as you KNOW WHAT YOU ARE DOING. To use root do: sudo -s and then you can do anything without having to type sudo before every command. To exit this sudo -s shell terminal, type exit and you will be returned to the previous shell terminal.
Is there a way to stop having to write 'sudo' for every little thing in Linux?
1,342,798,053,000
Possible Duplicate: Redirecting stdout to a file you don't have write permission on Running a command like sudo echo 'text' >> /file.txt fails with: bash: /file.txt: Permission denied
This doesn't work because the redirection is executed by the shell, not by the command it applies to. But your shell is not running as root, only echo 'text' is. A common trick when you need to have root permissions to write to a file, but not to generate the data, is to use tee: echo 'text' | sudo tee -a /file.txt tee prints the text to stdout, too. In order to mute it so it behaves more similar to shell appending (>>), route the stdout to /dev/null: echo 'text' | sudo tee -a /file.txt > /dev/null If you do need root permissions to generate the data, you can run two separate sudo commands, or run a shell inside sudo and do the redirection there (careful with the quoting). sudo echo 'text' | sudo tee -a /file.txt sudo sh -c 'echo "text" >>/file.txt' When overwriting rather than appending, if you're used to your shell refusing to truncate an existing file with the > operator (set -o noclobber), remember that this protection will not apply. sudo sh -c 'echo >/etc/passwd' and sudo tee /etc/passwd will overwrite /etc/passwd, you'd need sudo sh -o noclobber -c 'echo >/etc/passwd' for that noclobber setting to also be applied to the sh started by sudo.
How to insert text into a root-owned file using sudo? [duplicate]
1,342,798,053,000
I try to transfer files from remote computer using ssh to my computer : scp My_file.txt user_id@server:/Home This should put My_file.txt in the home folder on my own computer, right? I get scp/Home: permission denied Also when I try: ...@server:/Desktop, in order to copy the files from the remote computer to my desktop. What am I doing wrong?
Your commands are trying to put the new Document to the root (/) of your machine. What you want to do is to transfer them to your home directory (since you have no permissions to write to /). If path to your home is something like /home/erez try the following: scp My_file.txt user_id@server:/home/erez/ You can substitute the path to your home directory with the shortcut ~/, so the following will have the same effect: scp My_file.txt user_id@server:~/ You can even leave out the path altogether on the remote side; this means your home directory. scp My_file.txt user_id@server: That is, to copy the file to your desktop you might want to transfer it to /home/erez/Desktop/: scp My_file.txt user_id@server:/home/erez/Desktop/ or using the shortcut: scp My_file.txt user_id@server:~/Desktop/ or using a relative path on the remote side, which is interpreted relative to your home directory: scp My_file.txt user_id@server:Desktop/ As @ckhan already mentioned, you also have to swap the arguments, it has to be scp FROM TO So if you want to copy the file My_file.txt from the server user_id@server to your desktop you should try the following: scp user_id@server:/path/to/My_file.txt ~/Desktop/ If the file My_file.txt is located in your home directory on the server you may again use the shortcut: scp user_id@server:~/My_file.txt ~/Desktop/
Transfer files using scp: permission denied
1,342,798,053,000
I've never really got how chmod worked up until today. I followed a tutorial that explained a big deal to me. For example, I've read that you've got three different permission groups: owner (u) group (g) everyone (o) Based on these three groups, I now know that: If the file is owned by the user, the user permissions determine the access. If the group of the file is the same as the user's group, the group permission determine the access. If the user is not the file owner, and is not in the group, then the other permission is used. I've also learned that you've got the following permissions: read (r) write (w) execute (x) I created a directory to test my newly acquired knowledge: mkdir test Then I did some tests: chmod u+rwx test/ # drwx------ chmod g+rx test/ # drwxr-x--- chmod u-x test/ # drw-r-x--- After fooling around for some time I think I finally got the hang of chmod and the way you set permission using this command. But... I still have a few questions: What does the d at the start stand for? What's the name and use of the containing slot and what other values can it hold? How can I set and unset it? What is the value for this d? (As you only have 7=4+2+1 7=4+2+1 7=4+2+1) Why do people sometimes use 0777 instead of 777 to set their permissions? But as I shouldn't be asking multiple questions, I'll try to ask it in one question. In UNIX based system such as all Linux distributions, concerning the permissions, what does the first part (d) stand for and what's the use for this part of the permissions?
I’ll answer your questions in three parts: file types, permissions, and use cases for the various forms of chmod. File types The first character in ls -l output represents the file type; d means it’s a directory. It can’t be set or unset, it depends on how the file was created. You can find the complete list of file types in the ls documentation; those you’re likely to come across are -: “regular” file, created with any program which can write a file b: block special file, typically disk or partition devices, can be created with mknod c: character special file, can also be created with mknod (see /dev for examples) d: directory, can be created with mkdir l: symbolic link, can be created with ln -s p: named pipe, can be created with mkfifo s: socket, can be created with nc -U D: door, created by some server processes on Solaris/openindiana. Permissions chmod 0777 is used to set all the permissions in one chmod execution, rather than combining changes with u+ etc. Each of the four digits is an octal value representing a set of permissions: suid, sgid and “sticky” (see below) user permissions group permissions “other” permissions The octal value is calculated as the sum of the permissions: “read” is 4 “write” is 2 “execute” is 1 For the first digit: suid is 4; binaries with this bit set run as their owner user (commonly root) sgid is 2; binaries with this bit set run as their owner group (this was used for games so high scores could be shared, but it’s often a security risk when combined with vulnerabilities in the games), and files created in directories with this bit set belong to the directory’s owner group by default (this is handy for creating shared folders) “sticky” (or “restricted deletion”) is 1; files in directories with this bit set can only be deleted by their owner, the directory’s owner, or root (see /tmp for a common example of this). See the chmod manpage for details. Note that in all this I’m ignoring other security features which can alter users’ permissions on files (SELinux, file ACLs...). Special bits are handled differently depending on the type of file (regular file or directory) and the underlying system. (This is mentioned in the chmod manpage.) On the system I used to test this (with coreutils 8.23 on an ext4 filesystem, running Linux kernel 3.16.7-ckt2), the behaviour is as follows. For a file, the special bits are always cleared unless explicitly set, so chmod 0777 is equivalent to chmod 777, and both commands clear the special bits and give everyone full permissions on the file. For a directory, the special bits are never fully cleared using the four-digit numeric form, so in effect chmod 0777 is also equivalent to chmod 777 but it’s misleading since some of the special bits will remain as-is. (A previous version of this answer got this wrong.) To clear special bits on directories you need to use u-s, g-s and/or o-t explicitly or specify a negative numeric value, so chmod -7000 will clear all the special bits on a directory. In ls -l output, suid, sgid and “sticky” appear in place of the x entry: suid is s or S instead of the user’s x, sgid is s or S instead of the group’s x, and “sticky” is t or T instead of others’ x. A lower-case letter indicates that both the special bit and the executable bit are set; an upper-case letter indicates that only the special bit is set. The various forms of chmod Because of the behaviour described above, using the full four digits in chmod can be confusing (at least it turns out I was confused). It’s useful when you want to set special bits as well as permission bits; otherwise the bits are cleared if you’re manipulating a file, preserved if you’re manipulating a directory. So chmod 2750 ensures you’ll get at least sgid and exactly u=rwx,g=rx,o=; but chmod 0750 won’t necessarily clear the special bits. Using numeric modes instead of text commands ([ugo][=+-][rwxXst]) is probably more a case of habit and the aim of the command. Once you’re used to using numeric modes, it’s often easier to just specify the full mode that way; and it’s useful to be able to think of permissions using numeric modes, since many other commands can use them (install, mknod...). Some text variants can come in handy: if you simply want to ensure a file can be executed by anyone, chmod a+x will do that, regardless of what the other permissions are. Likewise, +X adds the execute permission only if one of the execute permissions is already set or the file is a directory; this can be handy for restoring permissions globally without having to special-case files v. directories. Thus, chmod -R ug=rX,u+w,o= is equivalent to applying chmod -R 750 to all directories and executable files and chmod -R 640 to all other files.
Understanding UNIX permissions and file types
1,342,798,053,000
I made a backup to an NTFS drive, and well, this backup really proved necessary. However, the NTFS drive messed up permissions. I'd like to restore them to normal w/o manually fixing each and every file. One problem is that suddenly all my text files gained execute permissions, which is wrong ofc. So I tried: sudo chmod -R a-x folder\ with\ restored\ backup/ But it is wrong as it removes the x permission from directories as well which makes them unreadable. What is the correct command in this case?
If you are fine with setting the execute permissions for everyone on all folders: chmod -R -x+X -- 'folder with restored backup' The -x removes execute permissions for all The +X will add execute permissions for all, but only for directories. See Stéphane Chazelas's answer for a solution that uses find to really not touch folders, as requested.
How to recursively remove execute permissions from files without touching folders?
1,342,798,053,000
Let's say I have a file a.txt in LINUX with permission of 0664. When I use rsync to copy the file to my Mac with rsync -r -t -v LINUX MAC, the file's permission becomes 0644. How can I keep the permission for a file when using rsync? The -g option doesn't work.
You want the -p flag: -p, --perms preserve permissions I tend to always use the -a flag, which is an aggregation of -p and several other useful ones: -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) Both taken straight from the rsync manpage.
Preserve the permissions with rsync
1,342,798,053,000
I was changing file permissions and I noticed that some of the permissions modes ended in @ as in -rw-r--r--@, or a + as in drwxr-x---+. I've looked at the man pages for chmod and chown, and searched around different help forums, but I can't find anything about what these symbols mean.
+ means that the file has additional ACLs set. You can set them with setfacl and query them with getfacl: martin@martin ~ % touch file martin@martin ~ % ll file -rw-rw-r-- 1 martin martin 0 Sep 23 21:59 file martin@martin ~ % setfacl -m u:root:rw file martin@martin ~ % ll file -rw-rw-r--+ 1 martin martin 0 Sep 23 21:59 file martin@martin ~ % getfacl file # file: file # owner: martin # group: martin user::rw- user:root:rw- group::rw- mask::rw- other::r-- I haven't seen @ yet personally, but according to this thread it signifies extended attributes, at least on MacOS. Try xattr -l on such a file.
File Permissions mode ending in @ or +
1,342,798,053,000
Is it possible to execute a script if there is no permission to read it? In root mode, I made a script and I want the other user to execute this script but not read it. I did chmod to forbid read and write but allow execute, however in user mode, I saw the message that says: permission denied.
The issue is that the script is not what is running, but the interpreter (bash, perl, python, etc.). And the interpreter needs to read the script. This is different from a "regular" program, like ls, in that the program is loaded directly into the kernel, as the interpreter would. Since the kernel itself is reading program file, it doesn't need to worry about read access. The interpreter needs to read the script file, as a normal file would need to be read.
Can a script be executable but not readable?
1,342,798,053,000
When I try to run ./script.sh I got Permission denied but when I run bash script.sh everything is fine. What did I do wrong?
Incorrect POSIX permissions It means you don't have the execute permission bit set for script.sh. When running bash script.sh, you only need read permission for script.sh. See What is the difference between running “bash script.sh” and “./script.sh”? for more info. You can verify this by running ls -l script.sh. You may not even need to start a new Bash process. In many cases, you can simply run source script.sh or . script.sh to run the script commands in your current interactive shell. You would probably want to start a new Bash process if the script changes current directory or otherwise modifies the environment of the current process. Access Control Lists If the POSIX permission bits are set correctly, the Access Control List (ACL) may have been configured to prevent you or your group from executing the file. E.g. the POSIX permissions would indicate that the test shell script is executable. $ ls -l t.sh -rwxrwxrwx+ 1 root root 22 May 14 15:30 t.sh However, attempting to execute the file results in: $ ./t.sh bash: ./t.sh: Permission denied The getfacl command shows the reason why: $ getfacl t.sh # file: t.sh # owner: root # group: root user::rwx group::r-- group:domain\040users:rw- mask::rwx other::rwx In this case, my primary group is domain users which has had execute permissions revoked by restricting the ACL with sudo setfacl -m 'g:domain\040users:rw-' t.sh. This restriction can be lifted by either of the following commands: sudo setfacl -m 'g:domain\040users:rwx' t.sh sudo setfacl -b t.sh See: Access Control Lists, Arch Linux Wiki Using ACLs with Fedora Core 2 Filesystem mounted with noexec option Finally, the reason in this specific case for not being able to run the script is that the filesystem the script resides on was mounted with the noexec option. This option overrides POSIX permissions to prevent any file on that filesystem from being executed. This can be checked by running mount to list all mounted filesystems; the mount options are listed in parentheses in the entry corresponding to the filesystem, e.g. /dev/sda3 on /tmp type ext3 (rw,noexec) You can either move the script to another mounted filesystem or remount the filesystem allowing execution: sudo mount -o remount,exec /dev/sda3 /tmp Note: I’ve used /tmp as an example here since there are good security reasons for keeping /tmp mounted with the noexec,nodev,nosuid set of options.
Run ./script.sh vs bash script.sh - permission denied
1,342,798,053,000
I saw a code change at work, where the mode values were changed from 777 to 0777 to make nfs setattr work. What is the difference in the 2 values?
If you're passing them to chmod (the command-line program), there is no difference. But in a C program or similar, 0777 is octal (three sets of three 1 bits, which is what you intend), while 777 is decimal, and it's quite a different bit pattern. (chmod will interpret any numeric argument as octal, hence no leading zero is necessary.) 0777 (octal)    == binary 0b 111 111 111    == permissions rwxrwxrwx   (== decimal 511) 777 (decimal) == binary 0b 1 100 001 001 == permissions sr----x--x (== octal 1411)
Is there any difference between mode value 0777 and 777
1,342,798,053,000
In Linux, what does the d mean in the first position of drwxr-xr-x? And what are all of the possible letters that could be there, and what do they mean? I'm trying to learn more about the Linux file permissions system, and I'd like to see a list of the character meanings for the first slot.
It means that it is a directory. The first mode field is the "special file" designator; regular files display as - (none). As for which possible letters could be there, on Linux the following exist: d (directory) c (character device) l (symlink) p (named pipe) s (socket) b (block device) D (door, not common on Linux systems, but has been ported)
What does the 'd' mean in ls -al results and what is that slot called? [duplicate]
1,342,798,053,000
I have a path on a Linux machine (Debian 8) which I want to share with Samba 4 to Windows computers (Win7 and 8 in a domain). In my smb.conf I did the following: [myshare] path = /path/to/share writeable = yes browseable = yes guest ok = yes public = yes I have perfect read access from Windows. But in order to have write access, I need to do chmod -R 777 /path/to/share in order to be able to write to it from Windows. What I want is write access from Windows after I provide the Linux credentials of the Linux owner of /path/to/share. I already tried: [myshare] path = /path/to/share writeable = yes browseable = yes Then Windows asks for credentials, but no matter what I enter, it's always denied. What is the correct way to gain write access to Samba shares from a Windows domain computer without granting 777 permissions?
I recommend to create a dedicated user for that share and specify it in force user(see docs). Create a user (shareuser for example) and set the owner of everything in the share folder to that user: adduser --system shareuser chown -R shareuser /path/to/share Then add force user and permission mask settings in smb.conf: [myshare] path = /path/to/share writeable = yes browseable = yes public = yes create mask = 0644 directory mask = 0755 force user = shareuser Note that guest ok is a synonym for public.
How to create a Samba share that is writable from Windows without 777 permissions?
1,342,798,053,000
On my server (Synology DS212) some files and folders have nobody nobody users and groups. What are the characteristics of this user and group? Who can write of read this file? How can I change it? For which user and group?
The nobody user is a pseudo user in many Unixes and Linux distributions. According to the Linux Standard Base, the nobody user and its group are an optional mnemonic user and group. That user is meant to represent the user with the least permissions on the system. In the best case that user and its group are not assigned to any file or directory (as owner). This user is in his corresponding group that is (according to LSB) also called "nobody" and in no other group. In earlier Unixes and Linux distributions daemon (for example a webserver) were called under the nobody user. If a malicious user gained control over such a daemon, the damage he can perform is limited to what the daemon can. But the problem is, when there are multiple daemons running with the nobody user, this has no sense anymore. That's why today such daemons have their own user. The nobody user should have no shell assigned to it. Different distributions handle that in different ways: some refer to /sbin/nologin that prints a message; some refer to /bin/false that simply exits with 1 (false); or some just disable the user in /etc/shadow. According to Linux Standard Base, the nobody user is "Used by NFS". In fact the NFS daemon is one of the few that still needs the nobody user. If the owner of a file or directory in a mounted NFS share doesn't exist at the local system, it is replaced by the nobody user and its group. You can change the permission of a file owned by the nobody user just simply with the root user and chown. But at the machine hosting the NFS share, that user might exist, so take care. I also use a Synology system. They run the apache web-server under the nobody user.
What is nobody user and group?
1,342,798,053,000
What does the letter S mean below? The file in question is a folder.                                                                 I read here that an upper-case S can represent that the setgid bit is active for a binary executable. But this is a folder. Does it still mean that the setgid bit is activated for it? If so, what does that mean?
That means that any file dropped into the folder will take on the folder's owning group. For example: Suppose you have a folder called "shared" which belongs to user "intrpc" and group "users", and you (as user "initrpc") drop a file into it. As a result, the file will be belong to user "intrpc" and group "users", regardless of "initrpc"'s primary group. On most systems, if a directory's set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. You can read about it here. Why is the letter uppercase (from the link you gave)? setgid has no effect if the group does not have execute permissions. setgid is represented with a lower-case "s" in the output of ls. In cases where it has no effect it is represented with an upper-case "S".
Uppercase S in permissions of a folder
1,342,798,053,000
I am in the process of migrating a machine from RHEL 4 to 5. Rather than actually do an upgrade we have created a new VM (both machines are in a cloud) and I am in the process of copying across data between the two. I have come across the following file, which I need to remove from the new machine but am unable to, even when running as root: -rw------- 1 2003 2003 219 jan 11 14:22 .bash_history This file is inside /home/USER/, where USER is the account of the guy who built the machine. He doesn't have an account on the old machine, so I am trying to remove his home folder so that the new machine tallies with the old one, but I get the following error: rm: ne peut enlever `.bash_history': Opération non permise (translated from the French: cannot remove XXX, operation not permitted) I have tried using the following command but this has made no difference: chattr -i .bash_history Is the only choice to create a user with the ID 2003, or is there another way around it? Edit I have tried using rm -f, and I get the same error. I get the same kind of error using chmod 777 first. I have been able to chown the folder that contains the file I am trying to delete, so it is: drwx------ 2 root root 1024 jan 24 15:58 USER Edit2 Running the lsattr command as suggested by Angus gave the following output: -----a------- USER/.bash_history ------------- USER/.. ------------- USER/. The file is flagged as append-only - on changing this flag using chattr -a .bash_history I was able to delete the file.
Check the permissions of the directory. To delete a file inside it, it should be writable by you chmod ugo+w . and not immutable or append-only: chattr -i -a . Check with ls -la and lsattr -a.
Unable to delete file, even when running as root
1,342,798,053,000
When I use the -a option as is asked and answered in Preserve the permissions with rsync, I got a lot of "rsync: failed to set permissions on" errors. rsync: failed to set permissions on "/ata/text/RCS/jvlc,v": Operation not permitted (1) rsync: failed to set permissions on "/ata/text/RCS/jvm,v": Operation not permitted (1) rsync: failed to set permissions on ... Why is this? The files are normal files with permission of 0664.
Most likely, rsync on the destination end is not running as a user with permission to chmod those files (which would have to be either the file's owner or root).
"rsync: failed to set permissions on ..." error with rsync -a or -p option
1,342,798,053,000
With Bash's source it is possible to execute a script without an execution bit set. This is documented and expected behaviour, but isn't this against the use of an execution bit? I know, that source doesn't create a subshell.
Bash is an interpreter; it accepts input and does whatever it wants to. It doesn't need to heed the executable bit. In fact, Bash is portable, and can run on operating systems and filesystems that don't have any concept of an executable bit. What does care about the executable bit is the operating system kernel. When the Linux kernel performs an exec, for example, it checks that the filesystem is not mounted with a noexec option, it checks the executable bit of the program file, and enforces any requirements imposed by security modules (such as SELinux or AppArmor). Note that the executable bit is a rather discretionary kind of control. On a Linux x86-64 system, for example, you can bypass the kernel's verification of the executable bit by explicitly invoking /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 as the interpreter: cp /bin/ls /tmp/ chmod -x /tmp/ls /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /tmp/ls This is somewhat analogous to sourcing Bash source code in Bash, except that ld.so is the interpreter, and the code that it executes is machine code in ELF format.
Why does Bash's source not need the execution bit?
1,342,798,053,000
Assume I'm logged in with user takpar: takpar@skyspace:/$ As root, I've added takpar as a member of group webdev using: # usermod -a -G webdev takpar But it seems it has not been applied, because for example I can't get into a webdev's directory that has read permission for group: 400169 drwxr-x--- 3 webdev webdev 4.0K 2011-08-15 22:34 public_html takpar@skyspace:/home/webdev/$ cd public_html/ bash: cd: public_html/: Permission denied But after a reboot I have access as I expect. As this kind of group changing is in my routine, is there any way to apply changes without needing a reboot? Answer It seems there is no way to make the current session know the new group, for example the file manager won't work with new changes. But a re-login will do the job. The su command is also appropriate for temp commands in urrent session.
Local solution: use su yourself to login again. In the new session you'll be considered as a member of the group. Man pages for newgrp and sg might also be of interest to change your current group id (and login into a new group): To use webdev's group id (and privileges) in your current shell use: newgrp webdev To start a command with some group id (and keep current privileges in your shell) use: sg webdev -c "command" (sg is like su but for groups, and it should work without the group password if you are listed as a member of the group in the system's data)
How to apply changes of newly added user groups without needing to reboot? [duplicate]
1,342,798,053,000
I created a folder on the command line as the root user. Now I want to edit it and its contents in GUI mode. How do I change the permissions on it to allow me to do this?
If I understand you correctly, fire up a terminal, navigate to one level above that directory, change to root and issue the command: chown -R user:group directory/ This changes the ownership of directory/ (and everything else within it) to the user user and the group group. Many systems add a group named after each user automatically, so you may want: chown -R user:user directory/ After this, you can edit the tree under directory/ and even change the permissions of directory/ and any file/directory under it, from the GUI. If you truly want any user to have full permissions on all files under directory/ (which may be OK if this is your personal computer, but is definitely not recommended for multi-user environments), you can issue this: chmod -R a+rwX directory/ as root.
How to change permissions from root user to all users?
1,342,798,053,000
I performed a git commit command and it gave me the following reply: 7 files changed, 93 insertions(+), 15 deletions(-) mode change 100644 => 100755 assets/internal/fonts/icomoon.svg mode change 100644 => 100755 assets/internal/fonts/icomoon.ttf mode change 100644 => 100755 assets/internal/fonts/icomoon.woff I know files can have user / group / other rwx permissions and those can be expressed as three octal digits, like "644" or "755". But why is git showing six digits here? I've read the following articles but didn't find an answer: Wikipedia's article on "File system permissions" How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git? Unix permissions made easy Chmod permissions (flags) explained: 600, 0600, 700, 777, 100 etc..
The values shown are the 16-bit file modes as stored by Git, following the layout of POSIX types and modes: 32-bit mode, split into (high to low bits) 4-bit object type valid values in binary are 1000 (regular file), 1010 (symbolic link) and 1110 (gitlink) 3-bit unused 9-bit unix permission. Only 0755 and 0644 are valid for regular files. Symbolic links and gitlinks have value 0 in this field. That file doesn’t mention directories; they are represented using object type 0100. Gitlinks are used for submodules. Each digit in the six-digit value is in octal, representing three bits; 16 bits thus need six digits, the first of which only represents one bit: Type|---|Perm bits 1000 000 111101101 1 0 0 7 5 5 1000 000 110100100 1 0 0 6 4 4 Git doesn’t store arbitrary modes, only a subset of the values are allowed, from the usual POSIX types and modes (in octal, 12 for a symbolic link, 10 for a regular file, 04 for a directory) to which git adds 16 for Git links. The mode is appended, using four octal digits. For files, you’ll only ever see 100755 or 100644 (although 100664 is also technically possible); directories are 040000 (permissions are ignored), symbolic links 120000. The set-user-ID, set-group-ID and sticky bits aren’t supported at all (they would be stored in the unused bits). See also this related answer.
File permission with six octal digits in git. What does it mean?
1,342,798,053,000
On my server I have directory /srv/svn. Is it possible to set this directory to have multiple group ownerships, for instance devFirmA, devFirmB and devFirmC? The point is, I want to subversion version control manage multiple users accross multiple repositories and I do not know how to merge /srv/svn, the root directory of repositories, permissions. I have, for instance, three firms, FirmA, FirmB and FirmC. Now, inside /srv/svn I've created three directories, FirmA, FirmB, FirmC and inside them I've created repository for each project and now I do not know how to establish permission scheme since all elementes inside /srv/svn are owned by root:root, which is not ok, or am I wrong?
This is an extremely common problem, if I understand it accurately, and I encounter it constantly. If I used ACLs for every trivial grouping problem, I would have tons of unmanageable systems. They are using the best practice when you cannot do it any other way, not for this situation. This is the method I very strongly recommend. First you need to set your umask to 002, this is so a group can share with itself. I usually create a file like /etc/profile.d/firm.sh, and then add a test command with the umask. [ $UID -gt 10000 ] && umask 002 Next you need to set the directories to their respective groups, chgrp -R FirmA /srv/svn/FirmA chgrp -R FirmB /srv/svn/FirmB chgrp -R FirmC /srv/svn/FirmC Finally you need to set the SGID bit properly, so the group will always stay to the one you set. This will prevent a written file from being set to the writer's GID. find /srv/svn/FirmA -type d -print0 | xargs -0 chmod 2775 find /srv/svn/FirmB -type d -print0 | xargs -0 chmod 2775 find /srv/svn/FirmC -type d -print0 | xargs -0 chmod 2775 find /srv/svn/FirmA -type f -print0 | xargs -0 chmod 664 find /srv/svn/FirmB -type f -print0 | xargs -0 chmod 664 find /srv/svn/FirmC -type f -print0 | xargs -0 chmod 664 Now finally if you want to prevent the directories from being accessed by other users. chmod 2770 /srv/svn/FirmA chmod 2770 /srv/svn/FirmB chmod 2770 /srv/svn/FirmC
Setting multiple groups as directory owners
1,350,153,071,000
System: I am testing Linux Mint 19 Beta based on Ubuntu 18.04. I got this warning while installing an unrelated package: gpg: WARNING: unsafe ownership on homedir '/home/vlastimil/.gnupg' This is the ls output the of the directory itself: $ lld /home/vlastimil/.gnupg drwx------ 4 vlastimil vlastimil 4,0K Jun 26 11:42 /home/vlastimil/.gnupg That seems to be OK. This is the ls output the contents of the directory: $ ll /home/vlastimil/.gnupg/ total 24K drwx------ 2 vlastimil vlastimil 4,0K Jun 26 11:36 crls.d drwx------ 2 vlastimil vlastimil 4,0K Jun 26 05:28 private-keys-v1.d -rw-r--r-- 1 vlastimil vlastimil 6,4K Jun 26 11:42 pubring.kbx -rw-r--r-- 1 vlastimil vlastimil 3,2K Jun 26 11:37 pubring.kbx~ srwx------ 1 root root 0 Jun 26 11:38 S.dirmngr -rw------- 1 vlastimil vlastimil 1,2K Jun 26 11:37 trustdb.gpg I am unsure if I can't just delete the seemingly offending directory named S.dirmngr. I am also unsure if that would solve the issue or create another one. I just remember that not long ago, I was instructed to install a package named like that, i.e. dirmngr, but I can't remember with what software installation it was connected. EDIT1: As StephenKitt pointed out, I really ran this line, I have found in the history: sudo gpg --recv-keys ... Will this have any consequences?
This is the result of running gpg with sudo: gpg then runs as root, but its home directory is still the user’s. This explains both the warning (gpg is running as root but another user owns the configuration directory) and dirmngr’s socket’s ownership. To fix this up, you should stop dirmngr: sudo gpgconf --kill dirmngr (sudo just this once because dirmngr is running as root, as evidenced by its socket), then restore your ownership: sudo chown -R $USER ~/.gnupg
gpg: WARNING: unsafe ownership on homedir '/home/user/.gnupg'
1,350,153,071,000
From the post Why can rm remove read-only files? I understand that rm just needs write permission on directory to remove the file. But I find it hard to digest the behaviour where we can easily delete a file who owner and group different. I tried the following mtk : my username abc : created a new user $ ls -l file -rw-rw-r-- 1 mtk mtk 0 Aug 31 15:40 file $ sudo chown abc file $ sudo chgrp abc file $ ls -l file -rw-rw-r-- 1 abc abc 0 Aug 31 15:40 file $ rm file $ ls -l file <deleted> I was thinking this shouldn't have been allowed. A user should be able to delete only files under his ownership? Can someone shed light on why this is permitted? and what is the way to avoid this? I can think only restricting the write permission of the parent directory to dis-allow surprised deletes of file.
The reason why this is permitted is related to what removing a file actually does. Conceptually, rm's job is to remove a name entry from a directory. The fact that the file may then become unreachable if that was the file's only name and that the inode and space occupied by the file can therefore be recovered at that point is almost incidental. The name of the system call that the rm command invokes, which is unlink, is even suggestive of this fact. And, removing a name entry from a directory is fundamentally an operation on that directory, so that directory is the thing that you need to have permission to write. The following scenario may make it feel more comfortable? Suppose there are directories: /home/me # owned and writable only by me /home/you # owned and writable only by you And there is a file which is owned by me and which has two hard links: /home/me/myfile /home/you/myfile Never mind how that hard link /home/you/myfile got there in the first place. Maybe root put it there. The idea of this example is that you should be allowed to remove the hard link /home/you/myfile. After all, it's cluttering up your directory. You should be able to control what does and doesn't exist inside /home/you. And when you do remove /home/you/myfile, notice that you haven't actually deleted the file. You've only removed one link to it. Note that if the sticky bit is set on the directory containing a file (shows up as t in ls), then you do need to be the owner of the file in order to be allowed to delete it (unless you own the directory). The sticky bit is usually set on /tmp.
Why is rm allowed to delete a file under ownership of a different user?
1,350,153,071,000
When creating directories, mkdir -m <mode> <dir> provides for creating one or more directories with the given mode/permissions set (atomically). Is there an equivalent for creating files, on the command line? Something akin to: open("file", O_WRONLY | O_APPEND | O_CREAT, 0777); Is using touch followed by a chmod my only option here? Edit: After trying out teppic's suggestion to use install, I ran it through strace to see how close to atomic it was. The answer is, not very: $ strace install -m 777 /dev/null newfile ... open("newfile", O_WRONLY|O_CREAT|O_EXCL, 0666) = 4 fstat(4, {st_mode=S_IFREG|0666, st_size=0, ...}) = 0 ... fchmod(4, 0600) = 0 close(4) = 0 ... chmod("newfile", 0777) = 0 ... Still, it's a single shell command and one I didn't know before.
You could use the install command with a dummy file, e.g. install -b -m 755 /dev/null newfile The -b option backs up newfile if it already exists. You can use this command to set the owner as well. On Linux it's usually part of GNU coreutils or BusyBox, but it's also available on systems derived from 4.2BSD, e.g. FreeBSD, NetBSD or OpenBSD.
Can files be created with permissions set on the command line?
1,350,153,071,000
Let's say user has Directory1 and it contains File1 File2 CantBeDeletedFile How to make so the user would never be allowed to delete the CantBeDeletedFile? If I change the ownership of Directory1 and remove write permissions users wouldn't be able to delete any file. They also wouldn't be able to add new files etc. I just want to be able to set some files which would never be deleted. More specific description. I am creating user profiles. I am creating application launcher files in their Desktop. So I want to set some launcher files (.desktop) and make them so user can only launch them and they couldn't rename nor delete, just launch. Currently if user owns the directory which contain any file. He can delete. If there is no generic way for all *nix, it's a Linux and ext4 FS.
(I dislike intruding users' home, I think they should be allowed to do whatever they want to do with they homes… but anyway…) This should work on linux (at least). I'm assuming user is already a member of the group user. A solution is to change ownership of Directory1 and set the sticky bit on the directory: chown root:user Directory1 chmod 1775 Directory1 Then use: chown root Directory1/CantBeDeletedFile Now, user won't be able to remove this file due to the sticky bit¹. The user is still able to add/remove their own files in Directory1. But notice that they won't be able to delete Directory1 because it will never be emptied. — 1. When the sticky bit is enabled on a directory, users (other than the owner) can only remove their own files inside a directory. This is used on directories like /tmp whose permissions are 1777=rwxrwxrwt.
Is there any way to prevent deletion of certain files from user owned directory?
1,350,153,071,000
From what I understand, the right place to put your own scripts is /usr/local/bin (for instance a script I use to back up some files). I notice that this folder is currently (by default) owned by root, and my normal user has no access to it. I am the only user on this computer. Shall I change this whole folder to my own user? Or is there another proper way to arrange permissions of /usr/local/bin?
By default, the owner and group of /usr/local and all subdirectories (including bin) should be root.root and the permissions should be rwxr-xr-x. This means that users of the system can read and execute in (and from) this directory structure, but cannot create or edit files there. Only the root account (or an administrator using sudo) should be able to create and edit files in this location. Even though there is only one user on the system, it's generally a bad idea to change permissions of this directory structure to writable to any user other than root. I would suggest placing your script/binary/executable into /usr/local/bin using the root account. It's a good habit to get into. You could also place the script/binary/executable into $HOME/bin and make sure $HOME/bin is in your $PATH. See this question for more discussion: Where should a local executable be placed?
Permissions/ownership of /usr/local/bin
1,350,153,071,000
I am currently having some issues with the cache. It is a little too much right now so I wanted to clear it. I googled and found this little command: sync && echo 3 > /proc/sys/vm/drop_caches. I am logged in as root over SSH (not using sudo). These are the attempts I made: root@server: ~ # ll /proc/sys/vm/drop_caches -rw-r--r-- 1 root root 0 15. Jan 20:21 /proc/sys/vm/drop_caches root@server: ~ # echo 3 > /proc/sys/vm/drop_caches -bash: /proc/sys/vm/drop_caches: Permission denied root@server: ~ # sudo su -c "echo 3 > /proc/sys/vm/drop_caches" bash: /proc/sys/vm/drop_caches: Permission denied root@server: ~ # echo 3 | sudo tee /proc/sys/vm/drop_caches tee: /proc/sys/vm/drop_caches: Permission denied 3 It is a remote machine running Debian. As far as I know there are some vCores in this machine and it uses Virtuozzo for the virtualization. I really just want to clear the cache (So I can only access it using SSH). I also tried registering this as a cronjob. But it simply fails too!
I am logged in as root over SSH...It is a remote machine running Debian. Is it actually a remote machine, or a just a remote system? If this is a VPS slice somewhere, (at least some forms of) OS virtualization (e.g. openVZ) won't permit this from within the container. You don't run the machine, you just run your slice.
"echo 3 > /proc/sys/vm/drop_caches" - Permission denied as root
1,350,153,071,000
I want to set the group permissions for all files and subdirectories within a certain parent directory to whatever the user permission setting for that specific file or directory is. For example, everything under /path/to/parentdir # Permissions before # Path Permissions /path/to/parentdir/file1 755 /path/to/parentdir/file2 644 /path/to/parentdir/file3 600 # Permissions after /path/to/parentdir/file1 775 /path/to/parentdir/file2 664 /path/to/parentdir/file3 660 I'm hoping there's a simple way to do this in hopefully one command. I can think of ways using a script with a bunch of commands, but it feels like there should be a pretty direct way of doing it. Thanks in advance!
This is what you want: chmod -R g=u directory
Make group permissions same as user permissions
1,350,153,071,000
The /etc/sudoers file lists which users can do what with the sudo command The root user creates and modifies the /etc/sudoers file. This concept is difficult for me to understand. If all users having sudo privilage belong to sudoers group, then all of them can become root by giving the sudo su command. Then who is the actual root user and how does he control the powers of users in sudoers group? Please explain it to me.
Executive summary: "root" is the actual name of the administrator account. "sudo" is a command which allows ordinary users to perform administrative tasks. "Sudo" is not a user. Long answer: "root" (aka "superuser") is the name of the system administrator account. The origins of the name are a little archaic, but that doesn't matter. Root user has user id 0 and nominally has unlimited privileges. Root can access any file, run any program, execute any system call, and modify any setting. (But see below¹). Prior to the invention of the "sudo" command, if you wanted to perform administrative tasks, you had to login as root, either by getting a login prompt² somehow, or with the su command ("su" being short for substitute user.)³ That's a bit of a hassle, and also doesn't let you give users partial administrative powers. So the "sudo" command (short for "substitute user do") was invented. The "sudo" command lets you execute commands with superuser privileges as long as your user id is in the sudoers file, giving you the necessary authorization. So, e.g. sudo vi /etc/hosts would allow you to edit the hosts file as if you were running as root. You don't even need the root password, just your own login password. And of course, sudo su would allow you to simply become root. The result is the same as if you had logged in as root or executed the su command, except that you don't need to know the root password but you do need to be in the sudoers file. The sudoers file determines who can use the sudo command and what they can do with it. The sudoers file is what gives you multiple administrators⁴. Effectively, your administrators are root, plus everybody listed in the sudoers file. Without the sudoers file, the only administrator is root. In fact, in organizations where someone else administers your computer for you, it's quite common to not know the root password of your own computer — as long as you're in the sudoers file, it doesn't matter. At one company I worked for, with a ginormous server farm, only a very, very small number of people knew the root passwords. Instead, there was a database of who was allowed to work on which servers. An automated process would add you to the sudoers files of those servers you were authorized to access, and remove you when your authorization expired. ¹ One more thing: modern Unix versions can now restrict even what the root user can do. Under SELinux (Security Enhanced Linux), there's effectively an access control list that determines which program can do what, and even root can't get past those restrictions. Under Apple's System Integrity Protection (SIP) (aka "rootless") system, certain files and directories are locked down so that only applications on the appropriate whitelist can access them. These systems exist to protect a system from the case where a malicious user manages to obtain root access. (Or in some cases, to prevent users from jailbreaking their embedded devices.) For obvious reasons, it's extremely difficult to bypass these restrictions, even with root access. ² The "login: " prompt is another archaic piece of Unix history, dating back to when we all used ascii terminals on serial lines, instead of window systems. You can still get a "login: " prompt by simply typing login in any terminal window, or by opening an ssh (or telnet or rsh) connection to your computer from elsewhere. You could log in as another user from there if you wanted. (And if your computer happens to have serial ports, you can still configure it to allow logins on them.) ³ It's also possible for individual programs to be given root access. These programs can do anything a user with root access can do, even when run by an ordinary user. These are typically limited to specific tasks. For example, the crontab program has root privileges so that it can edit the cron tables. Obviously, "sudo" has root privileges so that it can do what it does. ⁴ I'm going to cover one more point which I glossed over previously. I've been using "administrator" and "root" interchangeably, but there are other kinds of administrators. These are often called "role accounts", which is to say that these accounts don't belong to actual humans, but instead exist to perform some specific role on the system. If you take a look at the /etc/passwd file on your system, you'll find dozens and dozens of such accounts. For example, if mysql was installed on your system, there would be a "mysql" user, and all of the database files, config files, and so forth would all be owned by that user. Only that user (and root, of course) would have the necessary permissions to access the files and run the mysql server. In a sense, that user would be an administrator account, but only for mysql. If you needed to perform database administrative tasks, you would either become "mysql" with the su mysql command, or use sudo where the sudoers file would give you mysql privileges for those specific commands.
Difference between sudo user and root user [closed]
1,350,153,071,000
Can someone tell me what I'm doing wrong, what this is, or how to fix it? I'm running Fedora 18 and getting the error shown [root@servername /]# find . -name ngirc find: `./run/user/1000/gvfs': Permission denied [root@servername /]# [root@thinktank /]# pwd / [root@thinktank /]# ls -ltr ./run/user/1000 ls: cannot access ./run/user/1000/gvfs: Permission denied total 0 d?????????? ? ? ? ? ? gvfs lrwxrwxrwx. 1 root root 17 May 28 12:30 X11-display -> /tmp/.X11-unix/X0 drwx------. 2 kal kal 120 May 28 12:30 keyring-QjDw4b drwx------. 2 kal kal 40 May 28 12:30 gvfs-burn drwx------. 2 kal kal 60 May 28 12:30 krb5cc_5f0bcaf94f916d6b61696e2251a4dbb3 drwx------. 2 kal kal 60 May 28 18:25 dconf
You aren't doing anything wrong, and there's nothing to fix. /run/user/$uid/gvfs or ~$user/.gvfs is the mount point for the FUSE interface to GVFS. GVFS is a virtual filesystem implementation for Gnome, which allows Gnome applications to access resources such as FTP or Samba servers or the content of zip files like local directories. FUSE is a way to implement filesystem drivers as user code (instead of kernel code). The GVFS-FUSE gateway makes GVFS filesystem drivers accessible to all applications, not just the ones using Gnome libraries. Managing trust boundaries with FUSE filesystems is difficult, because the filesystem driver is running as an unprivileged user, as opposed to kernel code for traditional filesystems. To avoid complications, by default, FUSE filesystems are only accessible to the user running the driver process. Even root doesn't get to bypass this restriction. If you're searching for a file on local filesystems only, pass -xdev to find. If you want to traverse multiple local filesystems, enumerate them all. find / /home -xdev -name ngirc If the file has been present since yesterday, you may try locate ngirc instead (locate searches through a file name database which is typically updated nightly). If you do want to traverse the GVFS mount points, you'll have to do so as the appropriate user. find / -name ngirc -path '/run/user/*/gvfs' -prune -o -path '/home/*/.gvfs' -prune -o -name ngirc -print for d in /run/user/*; do su "${d##*/}" -c "find $d -name ngirc -print"; done
Why cannot find read /run/user/1000/gvfs even though it is running as root?
1,350,153,071,000
We use a hosting server of FreeBSD 10.3, where we don't have the authority to be a superuser. We use the server to run apache2 for web pages of our company. The previous administrator of our web pages appeared to set an ACL permission to a directory, but we want to remove it. Let us say the directory is called foobar. Now the result of ls -al foobar is as follows: drwxrwxr-x+ 2 myuser another_user 512 Nov 20 2013 foobar And the permission is as follows: [myuser@hosting_server]$ getfacl foobar # file: foobar/ # owner: myuser # group: another_user user::rwx group::rwx mask::rwx other::r-x Here we want to remove the ACL permission and the plus sign at the last of the permission list. Therefore, we did setfacl -b foobar It eliminated the special permission governed by the ACL, but didn't erase the plus sign+. Our question is how can we erase the plus sign+ in the permission list, shown by 'ls -al foobar'?
Our problem was resolved by using: setfacl -bn foobar The point was we also had to remove the aclMask from the directory with an option -n... The man page of setfacl says as follows: -n Do not recalculate the permissions associated with the ACL mask entry. This option is not applicable to NFSv4 ACLs. We're not sure why this option worked, but it did... In case you get d????????? permission after the above solution, try chmod -R a+rX as two commented below.
How to remove ACL from a directory and back to usual access control?
1,350,153,071,000
On shared unix hosting, if I have a file sensitive-data.txt and I issue: chmod 600 sensitive-data.txt Can root user still read my file? Specifically I'm wondering if it's safe to store my password in mercurial hgrc file. UPDATE Decided to use the mecurial keyring extension as it was super easy to setup: pip install mercurial_keyring and then add to hgrc: [extensions] mercurial_keyring = However I'm still interested in the answer to this question.
Yes, root can: $ echo Hello you\! > file $ chmod 600 file $ ls -l file -rw------- 1 terdon terdon 11 Feb 27 02:14 file $ sudo -i # cat file Hello you! In any case, even if root couldn't read your files as root, they can always log in as you without a password: $ whoami terdon $ sudo -i [sudo] password for terdon: # whoami root # su - terdon $ whoami terdon So, root can change to any other username using su (or sudo -iu username) and will then be able to do anything at all as though they were you.
Can root/superuser read my read-protected files?
1,350,153,071,000
I've got a brand new CentOS 6 installation, which has a symlink in the document root to my development files: [root@localhost html]# ls -l total 4 -rwxrwxrwx. 1 root root 0 Sep 18 20:16 index.html -rwxrwxrwx. 1 root root 17 Sep 18 20:16 index.php lrwxrwxrwx. 1 root root 24 Sep 18 20:19 refresh-app -> /home/billy/refresh-app/ My httpd.conf has this: <Directory "/"> Options All AllowOverride None Order allow,deny Allow from all </directory> The target of the symbolic link has permissions which should allow apache to read anything it wants: [root@localhost billy]# ls -l total 40 (Some entries were omitted because the list was too long drwxr-xr-x. 7 billy billy 4096 Sep 18 20:03 refresh-app I've also tried disabling SELinux by changing /etc/selinux/conf: SELINUX=disabled Yet no matter what I do, when someone tries to go to that link, http://localhost/refresh-app/, I get a 403 FORBIDDEN error page and this is written in the /var/log/httpd/error_log: Symbolic link not allowed or link target not accessible Why can't Apache access the target of the symlink?
Found the issue. Turns out, Apache wants access to not just the directory I'm serving, /home/billy/refresh-app/, but also every directory above that, namely /home/billy/, /home, and /. (I have no idea why... giving someone access to a subdirectory shouldn't require giving away permissions to everything above that subdirectory....) I would guess it's looking for .htaccess or something, or perhaps *nix being strange about how it treats permissions for directory transversal.
"Symbolic link not allowed or link target not accessible" / Apache on CentOS 6
1,350,153,071,000
While logged in, I can do the following: mkdir foo touch foo/bar chmod 400 foo/bar chmod 500 foo Then I can open vim (not as root), edit bar, force a write with w!, and the file is modified. How can I make the operating system disallow any file modification? UPDATE Mar 02 2017 chmod 500 foo is a red herring: the write permission on a directory has nothing to do with the ability to modify a file's contents--only the ability to create and delete files. chmod 400 foo/bar does in fact prevent the file's contents from being changed. But, it does not prevent a file's permissions from being changed--a file's owner can always change his file's permissions (assuming they can access the file i.e. execute permission on all ancestor directories). In fact, strace(1) reveals that this is what vim (7.4.576 Debian Jessie) is doing--vim calls chmod(2) to temporarily add the write permission for the file's owner, modifies the file, and then calls chmod(2) again to remove the write permission. That is why using chattr +i works--only root can call chattr -i. Theoretically, vim (or any program) could do the same thing with chattr as it does with chmod on an immutable file if run as root.
You can set the "immutable" attribute with most filesystems in Linux. chattr +i foo/bar To remove the immutable attribute, you use - instead of +: chattr -i foo/bar To see the current attributes for a file, you can use lsattr: lsattr foo/bar The chattr(1) manpage provides a description of all the available attributes. Here is the description for i: A file with the `i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
How do I make a file NOT modifiable?
1,350,153,071,000
I use Ubuntu 12.04. I am trying to add the user gefalko to the www-data group. I use root@xxx~# usermod -a -G www-data gefalko If I understand correctly, I should now see www-data in the output of groups when run by gefalko: gefalko@xxx:~$ groups However, there is no www-data in the output: gefalko adm cdrom sudo dip plugdev lpadmin sambashare I want to edit index.php owned by www-data, but I can't (permission denied): gefalko@xxx:/var/www/html/projectx$ ls -l total 1320 ... -rwxrwxr-x 1 www-data www-data 1613 Bal 18 10:18 index.php ...
When changing a user's groups, the changes don't take effect until the next time the user logs in. So, you can either log out and log back in again or start a new login shell as gefalko: $ groups sys lp wheel optical scanner terdon terdon@oregano ~ $ sudo usermod -a -G www-data terdon terdon@oregano ~ $ groups sys lp wheel optical scanner terdon ## no change $ su terdon - ## start a new login shell Password: $ groups sys lp wheel optical scanner terdon
usermod -a -G group user not work [duplicate]
1,350,153,071,000
I've set up vsftpd on Amazon EC2 with the Amazon Linux AMI. I created a user and can now successfully connect via ftp. However, if I try to upload something I get the error message 553 Could not create file. I assume this has to do with permissions, but I don't know enough about it to be able to fix it. So basically, what do I have to do to be able to upload files?
There are two likely reasons that this could happen -- you do not have write and execute permissions on the directories leading to the directory you are trying to upload to, or vsftpd is configured not to allow you to upload. In the former case, use chmod and chown as appropriate to make sure that your user has these permissions on every intermediate directory. The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory's attributes, whilst the read bit allows the affected user to list the files within the directory. Since intermediate directories in the path also affect this, the permissions must be set appropriately leading up to the ultimate destination that you intend to upload to. In the latter case, look at your vsftpd.conf. write_enable must be true to allow writing (and it is false by default). There is good documentation on this configuration file at man 5 vsftpd.conf.
VSFTPD, 553 Could not create file. - permissions?
1,350,153,071,000
I have ubuntu server on digitalocean and I want to give someone a folder for their domain on my server, my problem is, I don't want that user to see my folders or files or to be able to move out their folder. How can I restrict this user in their folder and not allow to him to move out and see other files/directories ?
I solved my problem by this way: Create a new group $ sudo addgroup exchangefiles Create the chroot directory $ sudo mkdir /var/www/GroupFolder/ $ sudo chmod g+rx /var/www/GroupFolder/ Create the group-writable directory $ sudo mkdir -p /var/www/GroupFolder/files/ $ sudo chmod g+rwx /var/www/GroupFolder/files/ Give them both to the new group $ sudo chgrp -R exchangefiles /var/www/GroupFolder/ after that I went to /etc/ssh/sshd_config and added to the end of the file: Match Group exchangefiles # Force the connection to use SFTP and chroot to the required directory. ForceCommand internal-sftp ChrootDirectory /var/www/GroupFolder/ # Disable tunneling, authentication agent, TCP and X11 forwarding. PermitTunnel no AllowAgentForwarding no AllowTcpForwarding no X11Forwarding no Now I'm going to add new user with obama name to my group: $ sudo adduser --ingroup exchangefiles obama Now everything is done, so we need to restart the ssh service: $ sudo service ssh restart notice: the user now can't do any thing out file directory I mean all his file must be in file Folder.
How to restrict a user to one folder and not allow them to move out his folder
1,350,153,071,000
I'm trying to create a new user on a Centos 6 system. First, I do useradd kevin Then, I tried to run commands as that user su - kevin However, I get the following error messages -bash: /dev/null: Permission denied -bash: /dev/null: Permission denied -bash: /dev/null: Permission denied -bash: /dev/null: Permission denied -bash: /dev/null: Permission denied -bash: /dev/null: Permission denied [kevin@gazelle ~]$ And I can't do very much as that user. The permissions on /dev/null are as follows: -rwxr-xr-x 1 root root 9 Jul 25 17:07 null Roughly the same as they are on my Mac, crw-rw-rw- 1 root wheel 3, 2 Jul 25 14:08 null It's possible, but really unlikely, that I touched dev. As the root user, I tried adding kevin to the root group: usermod -a -G root kevin However I still am getting /dev/null permission denied errors. Why can't the new user write to /dev/null? What groups should the new user be a part of? Am I not impersonating the user correctly? Is there a beginners guide to setting up users/permissions on Linux?
Someone evidently moved a regular file to /dev/null. Rebooting will recreate it, or do rm -f /dev/null; mknod -m 666 /dev/null c 1 3 As @Flow has noted in a comment, you must be root to do this. 1 and 3 here are the device major and minor number on Linux-based OSes (the 3rd device handled by the mem driver, see /proc/devices, cat /sys/devices/virtual/mem/null/dev, readlink /sys/dev/char/1:3). It varies with the OS. For instance, it's 2, 2 on OpenBSD and AIX, it may also not be always the same on a given OS. Some OSes may supply a makedev / MAKEDEV command to help recreate them.
-bash: /dev/null: Permission denied
1,350,153,071,000
I have the following file: ---------- 1 Steve Steve 341 2017-12-21 01:51 myFile.txt I switched the user to root in the terminal, and I have noticed the following behaviors: I can read this file and write to it. I can't execute this file. If I set the x bit in the user permissions (---x------) or the group permissions (------x---) or the others permissions (---------x) of the file, then I would be able to execute this file. Can anyone explain to me or point me to a tutorial that explains all of the rules that apply when the root user is dealing with files and directories?
Privileged access to files and directories is actually determined by capabilities, not just by being root or not. In practice, root usually has all possible capabilities, but there are situations where all/many of them could be dropped, or some given to other users (their processes). In brief, you already described how the access control checks work for a privileged process. Here's how the different capabilities actually affect it: The main capability here is CAP_DAC_OVERRIDE, a process that has it can "bypass file read, write, and execute permission checks". That includes reading and writing to any files, as well as reading, writing and accessing directories. It doesn't actually apply to executing files that are not marked as executable. The comment in generic_permission (fs/namei.c), before the access checks for files, says that Read/write DACs are always overridable. Executable DACs are overridable when there is at least one exec bit set. And the code checks that there's at least one x bit set if you're trying to execute the file. I suspect that's only a convenience feature, to prevent accidentally running random data files and getting errors or odd results. Anyway, if you can override permissions, you could just make an executable copy and run that. (Though it might make a difference in theory for setuid files of a process was capable of overriding file permissions (CAP_DAC_OVERRIDE), but didn't have other related capabilities (CAP_FSETID/CAP_FOWNER/CAP_SETUID). But having CAP_DAC_OVERRIDE allows editing /etc/shadow and stuff like that, so it's approximately equal to just having full root access anyway.) There's also the CAP_DAC_READ_SEARCH capability that allows to read any files and access any directories, but not to execute or write to them; and CAP_FOWNER that allows a process to do stuff that's usually reserved only for the file owner, like changing the permission bits and file group. Overriding the sticky bit on directories is mentioned only under CAP_FOWNER, so it seems that CAP_DAC_OVERRIDE would not be enough to ignore that. (It would give you write permission, but usually in sticky directories you have that anyway, and +t limits it.) (I think special devices count as "files" here. At least generic_permission() only has a type check for directories, but I didn't check outside of that.) Of course, there are still situations where even capabilities will not help you modify files: some files in /proc and /sys, since they're not really actual files SELinux and other security modules that might limit root chattr immutable +i and append only +a flags on ext2/ext3/ext4, both of which stop even root, and prevent also file renames etc. network filesystems, where the server can do its own access control, e.g. root_squash in NFS maps root to nobody FUSE, which I assume could do anything read-only mounts read-only devices
How do file permissions work for the "root" user?
1,350,153,071,000
I have few directores inside a folder like below - teckapp@machineA:/opt/keeper$ ls -ltrh total 8.0K drwxr-xr-x 10 teckapp cloudmgr 4.0K Feb 9 10:22 keeper-3.4.6 drwxr-xr-x 3 teckapp cloudmgr 4.0K Feb 12 01:44 data I have some other folder as well in some other machines for which I need to change the permission to the above one like this drwxr-xr-x. Meaning how can I change any folder permissions to drwxr-xr-x? I know I need to use chmod command with this but what should be the value with chown that I should use for this?
To apply those permissions to a directory: chmod 755 directory_name To apply to all directories inside the current directory: chmod 755 */ If you want to modify all directories and subdirectories, you'll need to combine find with chmod: find . -type d -exec chmod 755 {} +
How to set the permission drwxr-xr-x to other folders?
1,350,153,071,000
And now I am unable to chmod it back.. or use any of my other system programs. Luckily this is on a VM I've been toying with, but is there any way to resolve this? The system is Ubuntu Server 12.10. I have attempted to restart into recovery mode, unfortunately now I am unable to boot into the system at all due to permissions not granting some programs after init-bottom availability to run- the system just hangs. This is what I see: Begin: Running /scripts/init-bottom ... done [ 37.062059] init: Failed to spawn friendly-recovery pre-start process: unable to execute: Permission denied [ 37.084744] init: Failed to spawn friendly-recovery post-stop process: unable to execute: Permission denied [ 37.101333] init: plymouth main process (220) killed by ABRT signal After this the computer hangs.
Boot another clean OS, mount the file system and fix permissions. As your broken file system lives in a VM, you should have your host system available and working. Mount your broken file system there and fix it. In case of QEMU/KVM you can for example mount the file system using nbd.
How to recover from a chmod -R 000 /bin?
1,350,153,071,000
I changed permissions of a file (chmod g+w testfile) and running ls -l testfile gives: -rwxrwxr-x 1 user1 user1 0 2011-01-24 20:36 testfile I then added a user to that group ("/etc/group" has user1:x:1000:user2 line), but am failing to edit that file as user2. Why is this so?
user2 needs to log out and back in. Group permissions work this way: When you log in, your processes get to have group membership in your main group mentioned in /etc/passwd, plus all the groups where your user is mentioned in /etc/group. (More precisely, the pw_gid field in getpw(your_uid), plus all the groups of which your user is an explicit member. Beyond /etc/passwd and /etc/group, the information may come from other kinds of user databases such as NIS or LDAP.) The main group becomes the process's effective group ID and the other groups become its supplementary group IDs. When a process performs an operation that requires membership in a certain group, such as accessing a file, that group must be either the effective group ID or one of the supplementary group IDs of the process. As you can see, your change to the user's group membership only takes effect when the user logs in. For running processes, it's too late. So the user needs to log out and back in. If that's too much trouble, the user can log in to a separate session (e.g. on a different console, or with ssh localhost). Under the hood, a process can only ever lose privileges (user IDs, group IDs, capabilities). The kernel starts the init process (the first process after boot) running as root, and every process is ultimately descended from that process¹. The login process (or sshd, or the part of your desktop manager that logs you in) is still running as root. Part of its job is to drop the root privileges and switch to the proper user and groups. There's one single exception: executing a setuid or setgid program. That program receives additional permissions: it can choose to act under various subsets of the parent process's memberships plus the additional membership in the user or group that owns the setxid executable. In particular, a setuid root program has root permissions, hence can do everything²; this is how programs like su and sudo can do their job. ¹ There are occasionally processes that aren't derived from init (initrd, udev) but the principle is the same: start as root and lose privileges over time. ² Barring multilevel security frameworks such as SELinux.
I added a user to a group, but group permissions on files still have no effect
1,350,153,071,000
having a bit of a difficult time trying to create a folder under another user's /home/devuser1/pubic_html folder. I'm trying to avoid using sudo and looking for an alternative. The permissions on the said folder reads as: drwxr-s--- 2 devuser1 www-data 4096 Apr 28 19:40 public_html Alternatively, assuming I use the sudo prefix, what would be the implications be? I've read that it's bad practice to use sudo to make a folder. After the new folder is created, I'm still changing the ownership of it to the user in question. Example: chown -vR devuser1:www-data /home/devuser1/public_html/$vhost
sudo -u [username] mkdir /home/[username]/public_html/[folder_name] works fine. From what I can see the permissions and ownership is the same if I were to log in as the same user and create the folder under public_html. You can also call su -c "mkdir /home/[username]/public_html/[folder_name]" [username]
using root to mkdir in another users home directory
1,350,153,071,000
I have directory exam with 2 files in it. I need to delete files but permission is denied. Even rm -rf command can't delete these files. I logged in as a root user.
From root user check attributes of files # lsattr if you notice i (immutable) or a (append-only), remove those attributes: # man chattr # chattr -i [filename] # chattr -a [filename]
Why can't I delete this file as root?
1,350,153,071,000
Witness the following: sh-3.2$ mkdir testcase sh-3.2$ cd testcase sh-3.2$ sudo touch temp sh-3.2$ ls -al total 0 drwxr-xr-x 3 glen staff 102 19 Dec 12:38 . drwxr-xr-x 12 glen staff 408 19 Dec 12:38 .. -rw-r--r-- 1 root staff 0 19 Dec 12:38 temp sh-3.2$ echo nope > temp sh: temp: Permission denied sh-3.2$ vim temp # inside vim itheivery # press [ESC] :wq! # vim exits sh-3.2$ ls -al total 8 drwxr-xr-x 3 glen staff 102 19 Dec 12:38 . drwxr-xr-x 12 glen staff 408 19 Dec 12:38 .. -rw-r--r-- 1 glen staff 7 19 Dec 12:38 temp Somehow vim has taken this root-owned file, and changed it into a user owned file! This only seems to work if the user owns the directory - but it still feels like it shouldn't be possible. Can anyone explain how this is done?
You, glen, are the owner of the directory (see the . file in your listing). A directory is just a list of files and you have the permission to alter this list (e.g. add files, remove files, change ownerships to make it yours again, etc.). You may not be able to alter the contents of the file directly, but you can read and unlink (remove) the file as a whole and add new files subsequently.1 Only witnessing the before and after, this may look like the file has been altered. Vim uses swap files and moves files around under water, so that explains why it seems to write to the same file as you do in your shell, but it's not the same thing.2 So, what Vim does, comes down to this: cat temp > .temp.swp # copy file by contents into a new glen-owned file echo nope >> .temp.swp # or other command to alter the new file rm temp && mv .temp.swp temp # move temporary swap file back 1This is an important difference in file permission handling between Windows and Unices. In Windows, one is usually not able to remove files you don't have write permission for. 2 update: as noted in the comments, Vim does not actually do it this way for changing the ownership, as the inode number on the temp file does not change (comaring ls -li before and after). Using strace we can see exactly what vim does. The interesting part is here: open("temp", O_WRONLY|O_CREAT|O_TRUNC, 0664) = -1 EACCES (Permission denied) unlink("temp") = 0 open("temp", O_WRONLY|O_CREAT|O_TRUNC, 0664) = 4 write(4, "more text bla\n", 14) = 14 close(4) = 0 chmod("temp", 0664) = 0 This shows that it only unlinks, but does not close the file descriptor to temp. It rather just overwrites its whole contents (more text bla\n in my case). I guess this explains why the inode number does not change.
How does vim steal root owned files?
1,350,153,071,000
I've been working on *nix for a few years now, and one of the things I just can't get used to is octal permissions in code. Is there some other reason than line length to prefer chmod 644 ... over chmod u=rw,go=r ...? PS: I'm not looking for an explanation of octal permissions. I know how they work, and it's well explained in the manual. I'm asking why octal seems to be preferred over the more human-readable form.
Using the octal codes has two advantages I can think of, neither of which is that huge: They're shorter, easier to type. A few things only understand them, and if you routinely use them you'll not be scratching your head (or running to documentation) when you run into one. E.g., you have to use octal for chmod in Perl or C. Sometimes really simple utilities won't handle the "friendly" versions; especially in non-GNU userlands. Further, some utilities spit out octal. For example, if you run umask to see what your current umask is, it'll spit it out in octal (though in bash, umask -S does symbolic). So, in short, I'd say the only reason to prefer them is to type fewer characters, but that even if you elect not to use them, you should know how they map so that you can figure out an octal code if you run into one of the things that only does octal. But you don't need to immediately know that 5 maps to rx, you only need to be able to figure that out.
Why use `chmod 644` instead of `chmod u=rw,go=r,...`?
1,350,153,071,000
For example, I want to give my colleagues write access to certain directory. Let's assume that subdirectories in it had access rights 775, files 664, and also there were some executable files in the dir - 775. Now I want to add write permissions. With chmod, I could try something like chmod o+w -R mydir/ But that's not cool, since I don't want to make the dir world-writable - I want give access only to certain users, so I want to use ACL. But is there an easy way to set those permissions? As I see it, I need to tackle at least three cases (dirs, files, executable files) separately: find -type d -exec setfacl -m u:colleague:rwx {} \; find -type f -executable -exec setfacl -m u:colleague:rwx {} \; find -type f \! -executable -exec setfacl -m u:colleague:rw {} \; It seems quite a lot of code lines for such a simple task. Is there a better way?
setfacl has a recursive option (-R) just like chmod: -R, --recursive Apply operations to all files and directories recursively. This option cannot be mixed with `--restore'. it also allows for the use of the capital-x X permission, which means: execute only if the file is a directory or already has execute permission for some user (X) so doing the following should work: setfacl -R -m u:colleague:rwX . (all quotes are from man setfacl for acl-2.2.52 as shipped with Debian)
How do I set permissions recursively on a dir (with ACL enabled)?
1,350,153,071,000
I happen to know there is a slight difference between adduser and useradd. (i.e., adduser has additional features to useradd, such as creating a home directory.) Then what is the relation between addgroup and groupadd? Is there a preferred way to create a group?
On most distribution adduser and addgroup are interactive 'convenience' wrappers around the commands useradd and groupadd. You can find addgroup using the command which addgroup, on my machine (Ubuntu 11.04) this lives in /usr/sbin/addgroup. On my box addgroup is a perl script that prompts for various options (interactively) before invoking the groupadd command. groupadd is usually preferable for scripting (say, if you wan't to create users in batch), whereas addgroup is more user friendly (especially if you are unfamiliar with all the options and flags). Of course addgroup also takes many options via the command when you invoke it, but it is primarily intended as an interactive script. Interestingly on my box addgroup is a symlink to adduser, the script checks the name it was invoked under and performs different actions accordingly.
addgroup vs groupadd
1,350,153,071,000
I performed an ls -la on directory on my CentOS 6.4 server here and the permissions for a given file came out as: -rwxr-xr-x. I understand what -rwxr-xr-x means, what I don't understand is the . after the last attribute. Can someone explain it to me? Is it harmful in any way? Can it be removed?
GNU ls uses a . character to indicate a file with an SELinux security context, but no other alternate access method. -- From ls man page (info coreutils 'ls invocation').
What does a dot after the file permission bits mean?
1,350,153,071,000
I use a FUSE filesystem with no problems as my own user, but root can't access my FUSE mounts. Instead, any command gives Permission denied. How can I give root the permission to read these mounts? ~/top$ sudo ls -l total 12 drwxr-xr-x 2 yonran yonran 4096 2011-07-25 18:50 bar drwxr-xr-x 2 yonran yonran 4096 2011-07-25 18:50 foo drwxr-xr-x 2 yonran yonran 4096 2011-07-25 18:50 normal-directory ~/top$ fuse-zip foo.zip foo ~/top$ unionfs-fuse ~/Pictures bar My user, yonran, can read it fine: ~/top$ ls -l total 8 drwxr-xr-x 1 yonran yonran 4096 2011-07-25 18:12 bar drwxr-xr-x 2 yonran yonran 0 2011-07-25 18:51 foo drwxr-xr-x 2 yonran yonran 4096 2011-07-25 18:50 normal-directory ~/top$ ls bar/ Photos But root can't read either FUSE directory: ~/top$ sudo ls -l ls: cannot access foo: Permission denied ls: cannot access bar: Permission denied total 4 d????????? ? ? ? ? ? bar d????????? ? ? ? ? ? foo drwxr-xr-x 2 yonran yonran 4096 2011-07-25 18:50 normal-directory ~/top$ sudo ls bar/ ls: cannot access bar/: Permission denied I'm running Ubuntu 10.04: I always install any update from Canonical. $ uname -a Linux mochi 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:13:52 UTC 2011 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 10.04.3 LTS Release: 10.04 Codename: lucid Edit: removed the implication that root used to be able to access the mounts. Come to think of it, maybe my scripts never tried to access the directory as root.
It's the way fuse works. If you want to allow access to root or others users, you have to add: user_allow_other in /etc/fuse.conf and mount your fuse filesystem with allow_other or allow_root as options.
Why does root get Permission denied when accessing FUSE directory?
1,350,153,071,000
I was thinking that it might be advantageous to have a user with permissions higher than the root user. You see, I would like to keep all of the activities and almost all existing root user privileges exactly as they are now. However, I would like the ability to deny privileges to root on an extremely isolated case by case basis. One of the advantages of this would allow me to prevent certain unwanted files from being installed during updates. This is just an example of one possible advantage. Because apt-get updates are run by root or with sudo privileges, apt-get has the ability to replace certain unwanted files during updates. If I could deny these privileges to these individual particular files, I could set them as a simlink to /dev/null or possibly have a blank placeholder file that could have permissions that would deny the file from being replaced during the update. Additionally, I can't help but be reminded about a line which was said in an interview with one of the Ubuntu creators when the guy said something about how users better trust "us" (referring to the Ubuntu devs) "because we have root" which was a reference to how system updates are performed with root permission. Simply altering the installation procedure to say work around this problem is absolutely not what I am interested here. Now that my mind has a taste for the idea of having the power to deny root access, I would like to figure out a way to make this happen just for the sake of doing it. I just thought about this and have not spent any time on the idea so far and I'm fairly confident that this could be figured out. However, I am curious to know if this has already been done or if this is possibly not a new idea or concept. Basically, it seems like there should be some way to have a super super-user which would have permission beyond that of the system by only one degree. Note: Although I feel the accepted answer fits the criteria the most, I really like the answer by @CR. also. I would like to create an actual user higher on the tree (me) but I guess I'll just have to sit down one day when I have the time to figure it out. Additionally, I'm not trying to pick on Ubuntu here; I wouldn't use it as my main distro if I felt negative about it.
The "user" you want is called LSM: Linux security module. The most well known are SELinux and AppArmor. By this you can prevent certain binaries (and their child processes) from doing certain stuff (even if their UID is root). But you may allow these operations to getty and its child processes so that you can do it manually.
Can I create a *super* super-user so that I can actually have a user that can deny permission to root?
1,350,153,071,000
To run the command poweroff or reboot one needs to be super user. Is there anyway I can run this as a normal user? I just don't want to sudo and enter my password every time I reboot or power off.
I changed /etc/sudoers so that every user that is in the admin group can execute the following commands without being ask for a password. sudo halt sudo reboot sudo poweroff You just need to add the following lines to /etc/sudoers ## Admin user group is allowed to execute halt and reboot %admin ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff and add yourself to the admin group. If you want only one user to be able to do this just remove the %admin and replace it with username like this ## user is allowed to execute halt and reboot stormvirux ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff You can find out more about /etc/sudoers with man sudoers or the online manpage
Poweroff or Reboot as normal User
1,350,153,071,000
I would like to start a service using a systemd unit file. This service requires a password to start. I don't want to store the password in plaintext in the systemd unit file, because it is world-readable. I also don't want to provide this password interactively. If I were writing a normal script for this, I would store the credentials in a file owned by root with restricted permissions (400 or 600), and then read the file as part of the script. Is there any particular systemd-style way to do this, or should I just follow the same process as I would in a regular shell script?
There are two possible approaches here, depending on your requirements. If you do not want to be prompted for the password when the service is activated, use the EnvironmentFile directive. From man systemd.exec: Similar to Environment= but reads the environment variables from a text file. The text file should contain new-line-separated variable assignments. If you do want to be prompted, you would use one of the systemd-ask-password directives. From man systemd-ask-password: systemd-ask-password may be used to query a system password or passphrase from the user, using a question message specified on the command line. When run from a TTY it will query a password on the TTY and print it to standard output. When run with no TTY or with --no-tty it will use the system-wide query mechanism, which allows active users to respond via several agents
Is there a typical way to pass a password to a Systemd Unit file?
1,350,153,071,000
Two setuid programs, /usr/bin/bar and /usr/bin/baz, share a single configuration file foo. The configuration file's mode is 0640, for it holds sensitive information. The one program runs as bar:bar (that is, as user bar, group bar); the other as baz:baz. Changing users is not an option, and even changing groups would not be preferable. I wish to hard link the single configuration file as /etc/bar/foo and /etc/baz/foo. However, this fails because the file must, as far as I know, belong either to root:bar or to root:baz. Potential solution: Create a new group barbaz whose members are bar and baz. Let foo belong to root:barbaz. That looks like a pretty heavy-handed solution to me. Is there no neater, simpler way to share the configuration file foo between the two programs? For now, I am maintaining two, identical copies of the file. This works, but is obviously wrong. What would be right? For information: I have little experience with Unix groups and none with setgid(2).
You can use ACLs so the file can be read by people in both groups. chgrp bar file chmod 640 file setfacl -m g:baz:r-- file Now both bar and baz groups can read the file. For example, here's a file owned by bin:bin with mode 640. $ ls -l foo -rw-r-----+ 1 bin bin 5 Aug 17 12:19 foo The + means there's an ACL set, so let's take a look at it. $ getfacl foo # file: foo # owner: bin # group: bin user::rw- group::r-- group:sweh:r-- mask::r-- other::--- We can see the line group:sweh:r-- : that means people in the group sweh can read it. Hey, that's me! $ id uid=500(sweh) gid=500(sweh) groups=500(sweh) And yes, I can read the file. $ cat foo data
One file wants to belong to two users. How? Hard linking fails
1,350,153,071,000
There's a command, I think it comes with apache, or is somehow related to it, that checks permissions, all the way down. So if I have /home/foo/bar/baz it will tell me what the permissions are for baz, bar, foo, and home. Does anyone know what this command is or another way of doing this? The command basically starts at the argument, and works it's way up to / letting you know what the permissions are along the way so you can see if you have a permission problem.
The utility you may be thinking of is the namei command. According to the manual page: Namei uses its arguments as pathnames to any type of Unix file (symlinks, files, directories, and so forth). Namei then follows each pathname until a terminal point is found (a file, directory, char device, etc). If it finds a symbolic link, we show the link, and start following it, indenting the output to show the context. The output you desire can be received as follows: $ namei -l /usr/src/linux-headers-2.6.35-22/include/ f: /usr/src/linux-headers-2.6.35-22/include/ drwxr-xr-x root root / drwxr-xr-x root root usr drwxrwsr-x root src src drwxr-xr-x root root linux-headers-2.6.35-22 drwxr-xr-x root root include The namei command is part of the linux-util-ng software package. See the manual page for more details.
How do I recursively check permissions in reverse?
1,350,153,071,000
Maybe I haven't had enough coffee yet today, but I can't remember or think of any reason why /proc/PID/cmdline should be world-readable - after all, /proc/PID/environ isn't. Making it readable only by the user (and maybe the group. and root, of course) would prevent casual exposure of passwords entered as command-line arguments. Sure, it would affect other users running ps and htop and the like - but that's a good thing, right? That would be the point of not making it world-readable.
I suspect the main, and perhaps only, reason is historical — /proc/.../cmdline was initially world-readable, so it remains that way for backwards compatibility. cmdline was added in 0.98.6, released on December 2, 1992, with mode 444; the changelog says - /proc filesystem extensions. Based on ideas (and some code) by Darren Senn, but mostly written by yours truly. More about that later. I don’t know when “later” was; as far as I can tell, Darren Senn’s ideas are lost in the mists of time. environ is an interesting counter-example to the backwards compatibility argument: it started out word-readable, but was made readable only by its owner in 1.1.85. I haven’t found the changelog for that so I don’t know what the reasoning was. The overall accessibility and visibility of /proc/${pid} (including /proc/${pid}/cmdline) can be controlled using proc’s hidepid mount option, which was added in version 3.3 of the kernel. The gid mount option can be used to give full access to a specific group, e.g. so that monitoring processes can still see everything without running as root.
Is there any reason why /proc/*/cmdline is world-readable?
1,350,153,071,000
I am moving a website from one server to another and Git does not store metadata such as file permissions. I need to find the directories and files that are not 775 / 664 respectively. Right now, I'm using this cobbled-together contraption: $ find . -type d -exec ls -la {} \; | grep ^d | grep -v ^drwxrwxr-x $ find . -type f -exec ls -la {} \; | grep -v ^d | grep -v ^-rw-rw-r-- | grep -v '.git' Though this works, I feel it is rather hacky. Is there a better way to do this, perhaps a canonical way, or should I just be hacky? This is running on a recent Ubuntu version with GNU tools under Bash.
Use the -perm test to find in combination with -not: find -type d -not -perm 775 -o -type f -not -perm 664 -perm 775 matches all files with permissions exactly equal to 775. -perm 664 does the same for 664. -not (boolean NOT) negates the test that follows, so it matches exactly the opposite of what it would have: in this case, all those files that don't have the correct permissions. -o (boolean OR) combines two sets of tests together, matching when either of them do: it has the lowest precedence, so it divides our tests into two distinct groups. You can also use parentheses to be more explicit. Here we match directories with permissions that are not 775 and ordinary files with permissions that are not 664. If you wanted two separate commands for directories and files, just cut it in half at -o and use each half separately: find -type f -not -perm 664 find -type d -not -perm 775
Find directories and files with permissions other than 775 / 664
1,350,153,071,000
I know what's ugoa (owner, group, others, all) or rwx (read/right/execute) or 4,2,1 or -, f, d, l, and I tried to read in man chmod to understand what's a capital X in chmod but there wasn't an entry for it. I then read in this article in posix/chmod but was stuck in this passage: Set the executable bit only if the target a) is a directory b) has already at least one executable bit set for any one of user, group, others. I also read in this article that gives this code example: chmod -R u=rwX,g=rX,o=rX testdir/ I understand there is a recursive permission on the testdir/, in regards to the owner (u), group (g), and others (o) but I admit I still miss the intention of the capital X. Maybe a didactic phrasing here could shed some light on this (the main reason I publish this here is because I didn't find an SE session on this). Update Sorry all, I missed that in the man. I didn't imagine the X would appear before the list of arguments and I thought the search returns x instead X, my bad.
The manpage says: execute/search only if the file is a directory or already has execute permission for some user (X) POSIX says: The perm symbol X shall represent the execute/search portion of the file mode bits if the file is a directory or if the current (unmodified) file mode bits have at least one of the execute bits (S_IXUSR, S_IXGRP, or S_IXOTH) set. It shall be ignored if the file is not a directory and none of the execute bits are set in the current file mode bits. This is a conditional permission flag: chmod looks at whatever it is currently processing, and if it’s a directory, or if it has any execute bit set in its current permissions (owner, group or other), it acts as if the requested permission was x, otherwise it ignores it. The condition is verified at the time chmod applies the specific X instruction, so you can clear execute bits in the same run with a-x,a=rwX to only set the executable bit on directories. You can see whether a file has an execute bit set by looking at the “access” part of stat’s output, or the first column of ls -l. Execute bits are represented by x. -rwxr-xr-x is common for executables and indicates that the executable bit is set for the owner, group and other users; -rw-r--r-- is common for other files and indicates that the executable bit is not set (but the read bit is set for everyone, and the write bit for the owner). See Understanding UNIX permissions and their attributes which has much more detail. Thus in your example, u=rwX sets the owner permissions to read and write in all cases, and for directories and executable files, execute; likewise for group (g=rX) and other (o=rX), read, and execute for directories and executable files. The intent of this operator is to allow the user to give chmod a variety of files and directories, and get the correct execute permissions (assuming none of the files had an invalid execute bit set). It avoids having to distinguish between files and directories (as in the traditional find . -type f -exec chmod 644 {} + and find . -type d -exec chmod 755 {} + commands), and attempts to deal with executables in a sensible way. (Note that macOS chmod apparently only supports X for + operations.)
What is a capital X in posix / chmod?
1,350,153,071,000
I just ran into something unexpected (for me) regarding file permissions on Linux (Arch Linux). Basically I have: userX in groupX fileX userX:groupX ---rwx---- What puzzles me: I cannot perform any action (rwx) on fileX. Is this right? Can someone please confirm this is indeed the expected behaviour? The only actions I can perform are mv and rm because I have write permissions on the parent directory. The thing is, I always thought these permissions collapse on each other, starting with the most general one (other -> group -> user). In other words, if o=rwx who cares what the persmissions for group and user are? Apparently this is not the case but it doesn't make much sense to me; it seems counterintuitive. The only thing this approach seems to be useful at, is to easily exclude a very specific person / group, which doesn't seem like a smart way to go at it (imho). Besides, the owner (and group?) should be able to chmod anyway right? Any thoughts on this matter?
The thing is, I always thought these permissions collapse on each other, starting with the most general one (other -> group -> user). If it was the case then “other” permissions would apply to everyone. In other words, if o=rwx who cares what the persmissions for group and user are? That's different from your previous sentence. Here you're implying that the permissions are or'ed together, e.g. that userX has the read permission if userX owns the file and the file is user-readable, or if a group that userX belongs to owns the file and the file is group-readable, or if the file is other-readable. But that's not how it works. In fact, o=rwx means that the rwx permissions apply to others, but it doesn't say anything about entities that are not others. First, it doesn't directly matter which groups a user belongs to. The kernel doesn't have a notion of users belonging to groups. What the kernel maintains is, for every process, a user ID (the effective UID) and a list of group IDs (the effective GID and the supplementary GIDs). The groups are determined at login time, by the login process — it's the login process that reads the group database (e.g. /etc/group). User and group IDs are inherited by child processes¹. When a process tries to open a file, with traditional Unix permissions: If the file's owning user is the process's effective UID, then the user permission bits are used. Otherwise, if the file's owning group is the process's effective GID or one of the process's supplementary group ID, then the group permission bits are used. Otherwise, the other permission bits are used. Only one set of rwx bits are ever used. User takes precedence over group which takes precedence over other. When there are access control lists, the algorithm described above is generalized: If there is an ACL on the file for the process's effective UID, then it is used to determine whether access is granted. Otherwise, if there is an ACL on the file for the process's effective GID or one of the process's supplementary group ID, then the group permission bits are used. Otherwise, the other permission bits are used. See also Precedence of ACLS when a user belongs to multiple groups for more details about how ACL entries are used, including the effect of the mask. Thus -rw----r-- alice interns indicates a file which can be read and written by Alice, and which can be read by all other users except interns. A file with permissions and ownership ----rwx--- alice interns is accessible only to interns except Alice (whether she is an intern or not). Since Alice can call chmod to change the permissions, this does not provide any security; it's an edge case. On systems with ACLs, the generalized mechanism allows removing permissions from specific users or specific groups, which is sometimes useful. Using a single set of bits, rather than or-ing all the bits for each action (read, write, execute), has several advantages: It has the useful effect of allowing removing permissions from a set of users or groups, on systems with ACLs. On systems without ACLs, permissions can be removed from one group. It is simpler to implement: check one set of bits, rather than combining several sets of bits together. It is simpler to analyse a file's permissions, because fewer operations are involved. ¹ They can change when a setuid or setgid process is executed. This isn't related to the issue at hand.
Precedence of user and group owner in file permissions
1,350,153,071,000
I want to format my USB stick to ext4 and just use as I would any other typical non-linux format drive (FAT32, exFAT, NTFS). That is to say, I want to be able to plug the usb stick into any of my linux machines, and read/write to it without needing to adjust permissions, like doing chmod or chown stuff. I would prefer to use GUI partition software like GParted, rather than command-line commands, though I welcome any solution! I'm sure a post like this is duplicate flag heaven for some, but after browsing 6~10 SO and forum posts from google, I didn't find a simple solution to my question. Seemed like everything was about adjusting permissions on a per-user basis. Maybe you just cannot use ext4 drives with the same brainless convenience as NTFS.
Like any unix-style filesystem, ext4 includes standard Unix file ownership and permission conventions. That is, the user is identified by an UID number, and each user will belong to one or more groups, each group identified by its GID number. Each file has an owner UID and one group owner GID. The three classic Unix file permission sets are: one set of permissions for the owner, identified by the owner's UID number one set of permissions for the group owner, identified by the group's GID number one set of permissions for everyone else In order to be able to access the stick without needing to adjust permissions, you must make sure any files and directories created on the stick will have non-restrictive permissions automatically. The problem is, permissions on any new files created are controlled by the umask value... and you don't really want to keep changing it to 000 for creating files on the USB stick and back to the default value (usually 002 or 022) for normal use. A single mistake could lead you creating an important configuration file with wide-open permissions, that might compromise the security of your user account or cause other more minor problems. If you can make sure that your normal user's UID number is the same across all your Linux systems, and you only care about access for that one user (plus root of course), you can get away with just formatting the USB stick to ext4, mounting it for the first time, and assigning the ownership of its root directory to your regular user account before you begin using the filesystem. Assuming that /dev/sdX1 is the USB stick partition you wish to create the filesystem in, and <username> is your username, you can do this when setting up the USB stick for use: sudo mkfs.ext4 /dev/sdX1 sudo mount /dev/sdX1 /mnt sudo chown <username>: /mnt sudo umount /mnt But if you cannot guarantee matching UID/GID numbers, and/or there are multiple users who might want to use the USB stick, you'll need to do something a bit more complicated, but still an one-time operation after creating the ext4 filesystem on the stick. We need to set a default ACL on the root directory of the USB stick filesystem that assigns full access to everyone on any new file or directory. And to ensure that the stick will be mounted with ACL support enabled, we need to use tune2fs to adjust the default mount options stored in the filesystem metadata. sudo mkfs.ext4 /dev/sdX1 sudo tune2fs -o acl /dev/sdX1 sudo mount /dev/sdX1 /mnt sudo chown <username>: /mnt chmod 777 /mnt setfacl -m d:u::rwx,d:g::rwx,d:o::rwx /mnt sudo umount /mnt Assuming that all your systems support ACLs on ext4 filesystems, and that any removable media mounting tool you might use won't choose to ignore the acl mount option, you now should have a USB stick on which all files created on it will have permissions -rw-rw-rw- and all created sub-directories will be drwxrwxrwx+. The plus sign indicates that the sub-directory will have an ACL: the custom default permission set configured for the stick's root directory will be inherited by the sub-directories too, and they will behave the same. The owner UID/GID will still match the UID and primary GID of the user that created the file on the filesystem, but because of relaxed file and directory permissions, that should not be much of an issue. The only problem I might expect is that copying files to the USB stick will by default attempt to duplicate the file permissions of the original, which you don't want in this case. For example, if you create a file on System A with permissions -rw-r--r-- and copy it to the stick, then move the stick to System B with non-matching UID numbers. You can still read the file on System B, but you cannot overwrite it on the stick without first explicitly deleting or renaming the original file. But you can do that, as long as you have write access to the directory the file's in. This can actually be an useful feature: if you modify the same file on multiple systems, this will push you towards saving a new version of the file each time instead of overwriting the One True File... and if the file is important, that might actually be a good thing.
How to make an ext4 formatted usb drive with full RW permissions for any linux machine?
1,350,153,071,000
I'm afraid I've run into something rather strange. When I open a file normally, vim README.txt, everything is fine. But upon sudo vim README.txt, the file renders blank, and gives me a E138: Can't write viminfo file $HOME/.viminfo! error upon trying to exit. I suspected the .viminfo file was corrupt, so I deleted it. This problem remains. Can anyone help?
When you run sudo vim you start vim as root. That means that it is the viminfo file in /root that is the problem. You should do rm /root/.viminf*. To make sure of this, run sudo vim and execute this command: :!echo $HOME. This will show you that your home directory is /root. I would recommend that you do not run vim as root, but rather use sudoedit. This is a more secure solution as the editor is not running as root. You never know what a plugin might do. Additionally it allows you to use your own settings and plugins in vim and not the ones in roots vimrc. sudoedit is the same as running sudo -e. sudoedit works by making a temporary copy of the file that is owned by the invoking user (you). When you finish editing, the changes are written to the actual file and the temporary file is deleted. As a general rule of thumb: Do not run things as root if it is not necessary.
Vim Error E138: Can't write viminfo file $HOME/.viminfo!
1,412,587,091,000
In a shell script, how do I easily and non-invasively test for write access to a file without actually attempting to modify the file? I could parse the output of stat, but that seems really complex, and perhaps brittle, though I'm not sure how much stat output differs across implementations and time. I could append to the end of the file and see if that succeeds, but that's potentially dangerous, for two reasons I can think of: I now have to remove the addition, and in case some other process writes to the file, this immediately becomes non-trivial as my line is no longer the last one. Any process reading the file may have arbitrary requirements on the contents of that file, and I may just have broken that application.
Just use the -w flag of the test utillity: [ -w /path/to/file ] && echo "writeable" || echo "write permission denied" Note that if you're going to write to the file later, it's still possible that you won't be able to write to it. The file may have moved, the permissions may have changed, etc. It can also happen that -w detects write permissions but some other factor intervenes to make the file not writable.
How to non-invasively test for write access to a file?
1,412,587,091,000
If I change the umask to 0000, I'd expect a text file to be created with rwxrwxrwx permissions (based on my understanding of the umask, as described in the "possible duplicate" question) However, when I try this, I get the following $ umask 0000 $ touch /tmp/new.txt $ ls -ld /tmp/new.txt -rw-rw-rw- 1 alanstorm wheel 0 Jun 2 10:52 /tmp/new.txt That is, execute permission is omitted, and I end up with rw-rw-rw- for files (directories are rwxrwxrwx). I tried this on my local OS X machine, an old BSD machine I have at a shared host, and a linux server running on linode. Why is this? Its my understanding that umask is the final arbiter of permissions -- is my understanding of this incorrect? If so, what else influences the default permissions of files on a unix system?
umask is subtractive, not prescriptive: permission bits set in umask are removed by default from modes specified by programs, but umask can't add permission bits. touch specifies mode 666 by default (the link is to the GNU implementation, but others behave in the same way; this is specified by POSIX), so the resulting file ends up with that masked by the current umask: in your case, since umask doesn't mask anything, the result is 666. The mode of a file or directory is usually specified by the program which creates it; most system calls involved take a mode (e.g. open(2), creat(2), mkdir(2) all have a mode parameter; but fopen(2) doesn't, and uses mode 666). Unless the parent directory specifies a default ACL, the process's umask at the time of the call is used to mask the specified mode (bitwise mode & ~umask; effectively this subtracts each set of permissions in umask from the mode), so the umask can only reduce a mode, it can't increase it. If the parent directory specifies a default ACL, that's used instead of the umask: the resulting file permissions are the intersection of the mode specified by the creating program, and that specified by the default ACL. POSIX specifies that the default mode should be 666 for files, 777 for directories; but this is just a documentation default (i.e., when reading POSIX, if a program or function doesn't specify a file or directory's mode, the default applies), and it's not enforced by the system. Generally speaking this means that POSIX-compliant tools specify mode 666 when creating a file, and mode 777 when creating a directory, and the umask is subtracted from that; but the system can't enforce this, because there are many legitimate reasons to use other modes and/or ignore umask: compilers creating an executable try to produce a file with the executable bits set (they do apply umask though); chmod(1) obviously specifies the mode depending on its parameters, and it ignores umask when "who" is specified, or the mode is fully specified (so chmod o+x ignores umask, as does chmod 777, but chmod +w applies umask); tools which preserve permissions apply the appropriate mode and ignore umask: e.g. cp -p, tar -p; tools which take a parameter fully specifying the mode also ignore umask: install --mode, mknod -m... So you should think of umask as specifying the permission bits you don't want to see set by default, but be aware that this is just a request. You can't use it to specify permission bits you want to see set, only those you want to see unset. Furthermore, any process can change its umask anyway, using the umask(2) system call! The umask(2) system call is also the only POSIX-defined way for a process to find out its current umask (inherited from its parent). On Linux, starting with kernel 4.7, you can see a process's current umask by looking for Umask in /proc/${pid}/status. (For the sake of completeness, I'll mention that the behaviour regarding setuid, setgid and sticky bits is system-dependent, and remote filesystems such as NFS can add their own twists.)
Why doesn't umask change execute permissions on files? [duplicate]
1,412,587,091,000
I am relatively new to the concepts mentioned in the question and reading about them from different sources only makes them more confusing. So this is what I understood so far: When we are given permissions for a file, they look like this: -rwsr-xr-- 1 user1 users 190 Oct 12 14:23 file.bin We assume that a user user2 who is in the group users tries to execute file.bin. If the setuid bit were not set, this would mean that both the RUID and EUID of file.bin were equal to the UID of user2. But since the setuid bit is set, this means that the RUID is now equal to the UID of user2, while EUID is the UID of the owner of the file, user1. My questions are: What is the difference between the owner of the file and root? Does root have the same permissions as the owner? Or would we need a separate entry in the permissions list for root? Difference between RUID and EUID? As I understand it the RUID and EUID are applied only to processes. If that is the case, why do they have the value of user id's? If RUID is the user who creates the process, and EUID is the user who is currently running the process, then the first sentence of the first answer in this question does not make any sense to me. Did I understand correctly what the setuid bit does?
Here are the answers: root has always full access to files and directories. The owner of the file usually has them too, but this is not always true. For example: -r-xr----- 1 user1 users 199 Oct 14 18:42 otherfile.bin user1 is the owner; however they can only read and execute, but root still has full access (rwx) to the file. RUID is the Real User ID and it (almost) never changes. If user2 logs in to the system, the shell is then launched with its real ID set to user2. All processes they start from the shell will inherit the real ID user2 as their real ID. EUID is the Effective User ID, it changes for processes (not for the user) that the user executes that have set the setuid bit. If user2 executes file.bin, the RUID will be user2 and the EUID of the process started will be user1. Let's use the case of passwd: -rwsr-xr-x 1 root root 45396 may 25 2012 /usr/bin/passwd When user2 wants to change their password, they execute /usr/bin/passwd. The RUID will be user2 but the EUID of that process will be root. user2 can use passwd to change only their own password because internally passwd checks the RUID and, if it is not root, its actions will be limited to real user's password. It's neccesary that the EUID becomes root in the case of passwd because the process needs to write to /etc/passwd and/or /etc/shadow.
Difference between owner/root and RUID/EUID
1,412,587,091,000
I have a directory that contains data shared between a number of users. Access to this directory and anything underneath, will be controlled by the directory's group, which will be added to the users in question. As such I created the folder "sticky group" chmod g+s set. The directory will contain a tree structure with directories and files, with the total amount of files likely being a few million. The files will be fairly small, I don’t anticipate anything bigger than 50MB. My problem is that the owner of the file or directory is still the user that created it. As such, even if i should remove that user from the access group, I would not remove his access completely. So: Are there other options I missed for ensuring that all files and sub-directories have the same owner? I expect I could periodically surf through the entire directory with a cron-job, but that strikes me as inefficient for what is essentially a once-pr-file command. I found an example using INotify but that strikes me as high-maintenance, since it requires scripting. I haven't been able to figure out if ACL can help me with forced ownership. Is there a smarter way to do this? What I want is to have a directory that can be shared by adding a group to a user. Anything created in this directory inherits the permission scheme from its parent. If there is a better way than what I’m attempting, I’m all ears.
Setting a default owner "automatically" would require a directory setuid behaving like setgid. However, while this can be configured on FreeBSD, other UNIX & Linux systems just ignore u+s. In your case however, there might be another solution. What I want is to have a directory that can be shared by adding a group to a user. Anything created in this directory inherits the permission scheme from its parent. If there is a better way than what I’m attempting, I’m all ears. So, basically, from what I see, you want to control the access to a directory using the groups mechanism. However, this does not require you to restrict the permissions in the whole directory structure. Actually, the directory --x execution bit could be just what you need. Let me give you an example. Assuming that... The group controlling the access to the group_dir directory is ourgroup. Only people in the ourgroup group can access group_dir. user1 and user2 belong to ourgroup. The default umask is 0022. ... consider the following setup: drwxrws--- root:ourgroup |- group_dir/ drwxr-sr-x user1:ourgroup |---- group_dir/user1_submission/ drwxr-sr-x user2:ourgroup |---- group_dir/user2_submission/ -rw-r--r-- user2:ourgroup |-------- group_dir/user2_submission/README Here, let's assume every item was created by its owner. Now, in this setup: All directories can be browsed freely by everyone in ourgroup. Anyone from the group can create, move, delete files anywhere inside group_dir (but not deeper). Anyone who's not in ourgroup will be blocked at group_dir, and will therefore be unable to manipulate anything under it. For instance, user3 (who isn't a member of ourgroup), cannot read group_dir/user2_submission/README (even though he has r-- permission on the file itself). However, there's a little problem in this case: because of the typical umask, items created by users cannot be manipulated by other members of the group. This is where ACLs come in. By setting default permissions, you'll make sure everything's fine despite the umask value: $ setfacl -dRm u::rwX,g::rwX,o::0 group_dir/ This call sets: Default rw(x) permissions for the owner. Default rw(x) permissions for the group. No permissions by default for the others. Note that since the others can't access group_dir anyway, it does not really matter what their permissions are below it. Now, if I create an item as user2: $ touch group_dir/user2_submission/AUTHORS $ ls -l group_dir/user2_submission/AUTHORS rw-rw---- user2:ourgroup group_dir/user2_submission/AUTHORS With this ACL in place, we can try rebuilding our previous structure: drwxrws---+ root:ourgroup |- group_dir/ drwxrws---+ user1:ourgroup |---- group_dir/user1_submission/ drwxrws---+ user2:ourgroup |---- group_dir/user2_submission/ -rw-rw----+ user2:ourgroup |-------- group_dir/user2_submission/README Here again, each item is created by its owner. Additionally, if you'd like to give a little bit more power/security to those using the directory, you might want to consider a sticky bit. This would, for instance, prevent user1 from deleting user2_submission (since he has -w- permission on group_dir) : $ chmod +t group_dir/ Now, if user1 tries to remove user2's directory, he'll get a lovely Operation not permitted. Note however that while this prevents directory structure modifications in group_dir, files and directories below it are still accessible: user1@host $ rm -r user2_submission Operation not permitted user1@host $ > user2_submission/README user1@host $ file user2_submission/README user2_submission/README: empty (uh-oh) Another thing to take into account is that the ACLs we used set up default permissions. It is therefore possible for the owner of an item to change the permissions associated to it. For instance, user2 can perfectly run... $ chown g= user2_submission/ -R or $ chgrp nobody user2_submission -R ... hence making his full submission directory unavailable to anyone in the group. However, since you're originally willing to give full rws access to anyone in the group, I'm assuming you're trusting these users, and that you wouldn't expect too many malicious operations from them.
Forcing owner on created files and folders
1,412,587,091,000
I can never remember what the conversion is from something like rw-r--r-- to 644. Is there a simple web based converter between the 2?
This site provides an interactive way to see what permissions bits are set when various bits are set/unset. http://permissions-calculator.org/ The "calculator" looks like this:   
Is there a web based converter between rwx and the octal version?
1,412,587,091,000
When I run chmod +w filename it doesn't give write permission to other, it just gives write permission to user and group. After executing this command chmod +w testfile.txt running ls -l testfile.txt prints -rw-rw-r-- 1 ravi ravi 20 Mar 10 18:09 testfile.txt but in case of +r and +x it works properly. I don't want to use chmod ugo+w filename.
Your specific situation In your specific situation, we can guess that your current umask is 002 (this is a common default value) and this explains your surprise. In that specific situation where umask value is 002 (all numbers octal). +r means ugo+r because 002 & 444 is 000, which lets all bits to be set +x means ugo+x because 002 & 111 is 000, which lets all bits to be set but +w means ug+w because 002 & 222 is 002, which prevents the "o" bit to be set. Other examples With umask 022 +w would mean u+w. With umask 007 +rwx would mean ug+rwx. With umask 077 +rwx would mean u+rwx. What would have matched your expectations When you change umask to 000, by executing umask 000 in your terminal, then chmod +w file will set permissions to ugo+w. Side note As suggested by ilkkachu, note that umask 000 doesn't mean that everybody can read and write all your files. But umask 000 means everyone that has some kind of access to any user account on your machine (which may include programs running server services ofc) can read and write all the files you make with that mask active and don't change (if the containing chain of directories up to the root also allows them).
Why does chmod +w not give write permission to other(o)
1,412,587,091,000
After upgrading to a new release version, my bash scripts start spitting errors: bash: /dev/stderr: Permission denied in previous versions Bash would internally recognize those file names (which is why this question is not a duplicate of this one) and do the right thing (tm), however, this has stopped working now. What can I do to be able to run my scripts again successfully? I have tried adding the user running the script to the group tty, but this makes no difference (even after logging out and back in). I can reproduce this on the command line without problem: $ echo test > /dev/stdout bash: /dev/stdout: Permission denied $ echo test > /dev/stderr bash: /dev/stderr: Permission denied $ ls -l /dev/stdout /dev/stderr lrwxrwxrwx 1 root root 15 May 13 02:04 /dev/stderr -> /proc/self/fd/2 lrwxrwxrwx 1 root root 15 May 13 02:04 /dev/stdout -> /proc/self/fd/1 $ ls -lL /dev/stdout /dev/stderr crw--w---- 1 username tty 136, 1 May 13 05:01 /dev/stderr crw--w---- 1 username tty 136, 1 May 13 05:01 /dev/stdout $ echo $BASH_VERSION 4.2.24(1)-release On an older system (Ubuntu 10.04): $ echo $BASH_VERSION 4.1.5(1)-release
I don't think this is entirely a bash issue. In a comment, you said that you saw this error after doing sudo su username2 when logged in as username. It's the su that's triggering the problem. /dev/stdout is a symlink to /proc/self/fd/1, which is a symlink to, for example, /dev/pts/1. /dev/pts/1, which is a pseudoterminal, is owned by, and writable by, username; that ownership was granted when username logged in. When you sudo su username2, the ownership of /dev/pts/1 doesn't change, and username2 doesn't have write permission. I'd argue that this is a bug. /dev/stdout should be, in effect, an alias for the standard output stream, but here we see a situation where echo hello works but echo hello > /dev/stdout fails. One workaround would be to make username2 a member of group tty, but that would give username2 permission to write to any tty, which is probably undesirable. Another workaround would be to login to the username2 account rather than using su, so that /dev/stdout points to a newly allocated pseudoterminal owned by username2. This might not be practical. Another workaround would be to modify your scripts so they don't refer to /dev/stdout and /dev/stderr; for example, replace this: echo OUT > /dev/stdout echo ERR > /dev/stderr by this: echo OUT echo ERR 1>&2 I see this on my own system, Ubuntu 12.04, with bash 4.2.24 -- even though the bash document (info bash) on my system says that /dev/stdout and /dev/stderr are treated specially when used in redirections. But even if bash doesn't treat those names specially, they should still act as equivalents for the standard I/O streams. (POSIX doesn't mention /dev/std{in,out,err}, so it may be difficult to argue that this is a bug.) Looking at old versions of bash, the documentation implies that /dev/stdout et al are treated specially whether the files exist or not. The feature was introduced in bash 2.04, and the NEWS file for that version says: The redirection code now handles several filenames specially: /dev/fd/N, /dev/stdin, /dev/stdout, and /dev/stderr, whether or not they are present in the file system. But if you examine the source code (redir.c), you'll see that that special handling is enabled only if the symbol HAVE_DEV_STDIN is defined (this is determined when bash is built from source). As far as I can tell, no released version of bash has made the special handling of /dev/stdout et al unconditional -- unless some distribution has patched it. So another workaround (which I haven't tried) would be to grab the bash sources, modify redir.c to make the special /dev/* handling unconditional, and use your rebuilt version rather than the one that came with your system. This is probably overkill, though. SUMMARY : Your OS, like mine, is not handling the ownership and permissions of /dev/stdout and /dev/stderr correctly. bash supposedly treats these names specially in redirections, but in fact it does so only if the files don't exist. That wouldn't matter if /dev/stdout and /dev/stderr worked correctly. This problem only shows up when you su to another account or do something similar; if you simply login to an account, the permissions are correct.
bash: /dev/stderr: Permission denied
1,412,587,091,000
Could you please explain why a binary compiled file (in, for example, /usr/sbin) has write permission for root user? For me, this is compiled. Meaning that direct write has no use and may expose file to some security issue somehow. A script (e.g. a bash file) may be writeable because it is a text file basically, but why is it the same for a compiled file where no write is actually necessary as far as I know? Thank you in advance for your feedback.
It doesn't really matter if the files in /bin (or any other standard directory where executables are kept) are writable by root or not. On a Linux server I'm using, they are writable by root, but on my OpenBSD machine, they're not. As long as they are not writable by the group or by "other"! There is no security issue having, e.g. -rwxr-xr-x 1 root root 126584 Feb 18 2016 /bin/ls If someone wanted to overwrite it, they'd have to be root, and if they are root and overwrite it, then they are either installing a new version, or clumsy, or an attacker with root permissions already. Another thing to consider is that root can write to the file no matter if it's write protected or not, because... root. Notice too that "a script" is as much an executable as a binary file. A script doesn't need to be writable "because it's a text file". If anything, it should probably just have the same permission as the other executables in the same directory. Don't go changing the permissions on everything now! That can wreak all sorts of havoc and potentially confuse package managers who might verify that permissions are set properly. It may also make the system vulnerable if you accidentally change the permissions in the wrong way on a security-critical application. Just assume that the permissions on the executables are set correctly, unless you find something that looks really odd, in which case you should probably contact the relevant package maintainer to verify rather than start changing stuff. From the comments and on chat, there was a call for some history. The history of the permissions on binaries on Linux is not anything I know anything about. It may be speculated that they simply inherited the permissions from the directory, or just from the default umask of Linux, but I really don't know. What I do know is that OpenBSD installs the binaries in the base system1 with permission mode 555 by default (-r-xr-xr-x). This is specified in a Makefile fragment in /usr/share/mk/bsd.own.mk which sets BINMODE to 555 (unless it's set already). This is later used when installing the executables during make build in /usr/src. I had a look at the annotated CVS log for this file, and found that this line in the file is unchanged since it was imported from NetBSD in 1995. On NetBSD, the file was first put into CVS in 1993, with BINMODE set to 555. The FreeBSD project seems to have used the exact same file as NetBSD since at least 1994, and with a later commit adds a hint in the commit message that the old files were from the 4.4BSD release of the Berkeley Software Distribution. Beyond that, the CSRG at Berkeley kept the sources in SCCS but their repository is available in Git form on GitHub2. The file that we're giving the forencic treatement here seems to have been committed by Keith Bostic (or someone in close proximity to him) in 1990. So that's that story. If you want the why, then I suppose we'll have to ask Keith. I was kinda hoping to see a commit message to a change saying "this needs to be 555 because ...", but no. 1 BSD systems have a stricter division into "base system" and "3rd party packages" (ports/packages) than Linux. The base system is a coherent unit that provides a complete set of facilities for running the operating system, while the ports or packages are seen as "local software" and are installed under /usr/local. 2 A more comprehensive GitHub repository of Unix releases from the 70's onwards is available too.
Why are executables in e.g. /usr/sbin writable by root?
1,412,587,091,000
I would like to create a new user on some of my Debian/Ubuntu hosts that is able to update the server using the commands apt-get update and apt-get dist-upgrade, but I do not wan't to give them full sudo access to be able to do anything else. Is this possible? Perhaps there is a way to create a script that they can't edit but can execute, which will get executed as the root user?
Sudo and the /etc/sudoers file aren't just for granting users full root access. You can edit the sudoers file with an existing sudo user, with the command sudo visudo You can group the commands that you want to grant access to like below: Cmnd_Alias SHUTDOWN_CMDS = /sbin/poweroff, /sbin/halt, /sbin/reboot Cmnd_Alias UPDATE_COMMANDS = /usr/bin/apt-get You can then give a specific user privileges to those commands like so: [User's name] ALL=(ALL) NOPASSWD: SHUTDOWN_CMDS, UPDATE_COMMANDS This can be seen in the image below: Now if you try sudo apt-get update or sudo apt-get dist-upgrade those commands will execute without asking for a password. If you want to be prompted for a password, remove the NOPASSWD bit where you grant a user access to command groups. If you try to run anything else as the sudo user, you will be prompted for a password and fail. References Ubuntu Docs - Sudoers How To Edit the Sudoers File on Ubuntu and CentOS Take Control of your Linux | sudoers file: How to with Examples
Allow certain guests to execute certain commands
1,412,587,091,000
I want to run the iptables command in a Ubuntu 16.04 Docker container. I have created a user, given that user root permissions, added them to the sudo group, but I am still being told that I am not running iptables as root. $ groups stack root sudo $ sudo whoami root $ sudo iptables --list iptables v1.6.0: can't initialize iptables table `filter': Permission denied (you must be root) Perhaps iptables or your kernel needs to be upgraded. In my /etc/sudoers file I have the line: %sudo ALL=(ALL:ALL) ALL, which I believe should allow any user in the sudo group (which I am) to run any command, but I still get the permission denied error. How would I successfully run the iptables command as this user? Please note I am doing this in a Docker container with image: ubuntu:16.04
Capabilities If you want have iptables access within your containers, you need to enable specific capabilities via the --cap-add=NET_ADMIN switch when running the container initially. Example $ docker run --cap-add=NET_ADMIN -it ubuntu:16.04 Then in the container set up iptables & sudo: # apt update -y # apt-get install iptables sudo -y Then inside the container, set up a user, user1, and added it to the sudo group: # adduser user1 # adduser user1 sudo Then set user to user1: # su - user1 Check user1's sudo permissions: $ sudo -l [sudo] password for user1: Matching Defaults entries for user1 on 1356bf8bd61a: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User user1 may run the following commands on 1356bf8bd61a: (ALL : ALL) ALL Check if they can access iptables via sudo: $ sudo iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination References How to start “ubuntu” docker container Docker run reference How can I add a new user as sudoer using the command line? How to disable requiretty for a single command in sudoers?
List IP tables in Docker Container
1,412,587,091,000
Which permissions affect hard link creation? Does file ownership itself matter? Suppose user alice wants to create a hard link to the file target.txt in a directory target-dir. Which permissions does alice need on both target.txt and target-dir? If target.txt is owned by user bill and target-dir is owned by user chad, does that change anything? I've tried to simulate this situation by creating the following folder/file structure on an ext4 filesystem: #> ls -lh . * .: drwxr-xr-x 2 bill bill 60 Oct 1 11:29 source-dir drwxrwxrwx 2 chad chad 60 Oct 1 11:40 target-dir source-dir: -r--r--r-- 1 bill bill 0 Oct 1 11:29 target.txt target-dir: -rw-rw-r-- 1 alice alice 0 Oct 1 11:40 dummy While alice can create a soft link to target.txt, she can't create a hard link: #> ln source-dir/target.txt target-dir/ ln: failed to create hard link ‘target-dir/target.txt’ => ‘source-dir/target.txt’: Operation not permitted If alice owns target.txt and no permissions are changed, the hard link succeeds. What am I missing here?
To create the hard link, alice will need write+execute permissions on target-dir on all cases. The permissions needed on target.txt will vary: If fs.protected_hardlinks = 1 then alice needs either ownership of target.txt or at least read+write permissions on it. If fs.protected_hardlinks = 0 then any set of permissions will do; Even 000 is okay. This answer to a similar question had the missing piece of information to answer this question. From this commit message (emphasis mine): On systems that have user-writable directories on the same partition as system files, a long-standing class of security issues is the hardlink-based time-of-check-time-of-use race, most commonly seen in world-writable directories like /tmp. The common method of exploitation of this flaw is to cross privilege boundaries when following a given hardlink (i.e. a root process follows a hardlink created by another user). Additionally, an issue exists where users can "pin" a potentially vulnerable setuid/setgid file so that an administrator will not actually upgrade a system fully. The solution is to permit hardlinks to only be created when the user is already the existing file's owner, or if they already have read/write access to the existing file.
Hard link creation - Permissions?
1,412,587,091,000
When using the tar utility to store files in backups one loses the extended ACLs. Is there some commonly used and not hackish solution (like: create a script that will recrate the ACLs from scratch) to preserve the ACLs?
Using tar To create: tar --acls -cpf backup.tar some-dir-or-file To untar: tar --acls -xpf backup.tar
What to use to backup files, preserving ACLs?
1,412,587,091,000
Is it possible to test effective permissions of a file for a specific user? I normally do this by su user and then accessing the file, but I now want to test this on an user with no shell (i.e. a System user)
The sudo command can run anything as a particular user with the -u option. Instead of worrying about shells, just try to cat (or execute, whatever) your file as your target user: $ sudo -u apache cat .ssh/authorized_keys cat: .ssh/authorized_keys: Permission denied
Test effective permissions of file for user
1,412,587,091,000
The execute permission makes sense for files (which include scripts etc.), but when it comes to directories, the write (w) permission works the same way as execute (x), right? Which means, if we are giving the write permission to a directory we also normally check "x" (for execute) for that directory as well, right?
The execute permission on directories allows accessing files inside the directory. The read permission allows enumerating the directory entries. The write permission allows creating and removing entries in it. Having read or write permission on a directory without execute permission is not useful. Having execute but not read permission is occasionally useful: it allows accessing files only if you know their exact name, a sort of primitive password protection. So in practice the useful permissions on a directory are: ---: no access --x: can access files whose name is known (occasionally useful) r-x: normal read-only access rwx: normal read and write access See also Directory with +x permission, parents without it. When would this be useful? and Do the parent directory's permissions matter when accessing a subdirectory?
In Linux, is "write" permission equivalent to "execute" for directories?
1,412,587,091,000
Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer? Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file. Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!
After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only. Alternatively, type C-x C-q (read-only-mode). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.
How to modify write permission on current buffer in emacs?
1,412,587,091,000
Possible Duplicate: Why do we use su - and not just su? I understand that root doesn't have to be a superuser. But in the case that it is ... what is the difference between sudo su - and sudo su root?
There are two questions there: Difference between su - username and su username If - (or -l) is specified, su simulates a real login. The environment is cleared except for a few select variables (TERM notably, DISPLAY and XAUTHORITY on some systems). Otherwise the environment is left as it is except for PATH that is reset. Difference between passing no user name and specifying root This might be system-dependent. On Linux with shadow as the package providing su, if no username is specified, then su first tries to see if user root has a passwd entry. If it does, it uses that. If it doesn't, it tries uid 0. Not sure about other Unix-like operating systems.
What is the difference between 'su -' and 'su root'? [duplicate]
1,412,587,091,000
Say I have the following output from ls -l: drwxr-xr-x 2 root root 4096 Apr 7 17:21 foo How can I automatically convert this to the format used by chmod? For example: $ echo drwxr-xr-x | chmod-format 755 I'm using OS X 10.8.3.
Some systems have commands to display the permissions of a file as a number, but unfortunately, nothing portable. zsh has a stat (aka zstat) builtin in the stat module: zmodload zsh/stat stat -H s some-file Then, the mode is in $s[mode] but is the mode, that is type + perms. If you want the permissions expressed in octal, you need: perms=$(([##8] s[mode] & 8#7777)) BSDs (including Apple OS/X) have a stat command as well. stat -f %Lp some-file (without the L, the full mode is returned, in octal) GNU find (from as far back as 1990 and probably before) can print the permissions as octal: find some-file -prune -printf '%m\n' Later (2001, long after zsh stat (1997) but before BSD stat (2002)) a GNU stat command was introduced with again a different syntax: stat -c %a some-file Long before those, IRIX already had a stat command (already there in IRIX 5.3 in 1994) with another syntax: stat -qp some-file Again, when there's no standard command, the best bet for portability is to use perl: perl -e 'printf "%o\n", (stat shift)[2]&07777' some-file
Convert ls -l output format to chmod format
1,412,587,091,000
I'm using Amazon Linux. I'm trying to append some text onto a file. The file is owned by root. I thought by using "sudo", I could append the needed text, but I'm getting "permission denied", see below [myuser@mymachine ~]$ ls -al /etc/yum.repos.d/google-chrome.repo -rw-r--r-- 1 root root 186 Jul 31 15:50 /etc/yum.repos.d/google-chrome.repo [myuser@mymachine ~]$ sudo echo -e "[google-chrome]\nname=google-chrome\nbaseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch\nenabled=1\ngpgcheck=1\ngpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub" >> /etc/yum.repos.d/google-chrome.repo -bash: /etc/yum.repos.d/google-chrome.repo: Permission denied How can I adjust my statement so that I can append the necessary text onto the file?
You have to use tee utility to redirect or append streams to a file which needs some permissions, like: echo something | sudo tee /etc/file or for append echo something | sudo tee -a /etc/file because by default your shell is running with your own user permissions and the redirection > or >> will be done with same permissions as your user, you are actually running the echo using the sudo and redirecting it without root permission. As an alternative you can also get a root shell then try normal redirect: sudo -i echo something >> /etc/pat/to/file exit or sudo -s for a non-login shell. you can also run a non interactive shell using root access: sudo bash -c 'echo something >> /etc/somewhere/file'
Getting "permission denied" when trying to append text onto a file using sudo [duplicate]
1,412,587,091,000
I create a file as regular user testuser: $ cat > /tmp/zz the file is owned by that user (as expected): $ ls -lA /tmp/zz -rw------- 1 testuser testuser 0 Feb 20 15:32 zz Now when I try to truncate it as root, I get permission denied: # truncate --size=0 /tmp/zz truncate: cannot open '/tmp/zz' for writing: Permission denied When I try with strace, I see the following: openat(AT_FDCWD, "/tmp/zz", O_WRONLY|O_CREAT|O_NONBLOCK, 0666) = -1 EACCES (Permission denied) write(2, "truncate: ", 10truncate: ) = 10 write(2, "cannot open '/tmp/zz' for writin"..., 33cannot open '/tmp/zz' for writing) = 33 ... write(2, ": Permission denied", 19: Permission denied) = 19 write(2, "\n", 1 Why does root not have permissions to write to that file? Root can delete the file, but not write.
This is a new behavior available on Linux kernels since version 4.19 to prevent attacks using /tmp/ tricks. The default value of the option might have been enabled later or be different depending on the distribution. (FEATURED) Avoid unintentional writes to an attacker-controlled FIFO or regular file: disallow open of FIFOs or regular files not owned by the user in world writable sticky directories, unless the owner is the same as that of the directory or the file is opened without the O_CREAT flag. The purpose is to make data spoofing attacks harder. This protection can be turned on and off separately for FIFOs (protected_fifos) and regular files (protected_regular) via sysctl, just like the symlinks/hardlinks protection commit This is intended to protect an user (including root which normally has always enough privileges) to write to a preexisting file in a directory like /tmp or /var/tmp while it would have intended to create it itself. It's enabled with this sysctl toggle: fs.protected_regular. One can revert to former behavior with: sysctl -w fs.protected_regular=0 but this will likely lower overall security, while making some strange "bugs" like OP's case disappear. As for why root could still delete the file, that is because the additional security feature is triggered only for opening a file for writing, not for unlink-ing it: truncate -s ... does open the file for writing, rm doesn't (it uses unlink or unlinkat).
root cannot write to file that is owned by regular user
1,412,587,091,000
Were I root, I could simply create a dummy user/group, set file permissions accordingly and execute the process as that user. However I am not, so is there any way to achieve this without being root?
More similar Qs with more answers worth attention: https://stackoverflow.com/q/3859710/94687 https://stackoverflow.com/q/4410447/94687 https://stackoverflow.com/q/4249063/94687 https://stackoverflow.com/q/1019707/94687 NOTE: Some of the answers there point to specific solutions not yet mentioned here. Actually, there are quite a few jailing tools with different implementation, but many of them are either not secure by design (like fakeroot, LD_PRELOAD-based), or not complete (like fakeroot-ng, ptrace-based), or would require root (chroot, or plash mentioned at fakechroot warning label). These are just examples; I thought of listing them all side-by-side, with indication of these 2 features ("can be trusted?", "requires root to set up?"), perhaps at Operating-system-level virtualization Implementations. In general, the answers there cover the full described range of possibilities and even more: virtual machines/OS (the answer mentioning virtual machines/OS) kernel extension (like SELinux) (mentioned in comments here), chroot Chroot-based helpers (which however must be setUID root, because chroot requires root; or perhaps chroot could work in an isolated namespace--see below): [to tell a little more about them!] Known chroot-based isolation tools: hasher with its hsh-run and hsh-shell commands. (Hasher was designed for building software in a safe and repeatable manner.) schroot mentioned in another answer ... ptrace Another trustworthy isolation solution (besides a seccomp-based one) would be the complete syscall-interception through ptrace, as explained in the manpage for fakeroot-ng: Unlike previous implementations, fakeroot-ng uses a technology that leaves the traced process no choice regarding whether it will use fakeroot-ng's "services" or not. Compiling a program statically, directly calling the kernel and manipulating ones own address space are all techniques that can be trivially used to bypass LD_PRELOAD based control over a process, and do not apply to fakeroot-ng. It is, theoretically, possible to mold fakeroot-ng in such a way as to have total control over the traced process. While it is theoretically possible, it has not been done. Fakeroot-ng does assume certain "nicely behaved" assumptions about the process being traced, and a process that break those assumptions may be able to, if not totally escape then at least circumvent some of the "fake" environment imposed on it by fakeroot-ng. As such, you are strongly warned against using fakeroot-ng as a security tool. Bug reports that claim that a process can deliberatly (as opposed to inadvertly) escape fake‐ root-ng's control will either be closed as "not a bug" or marked as low priority. It is possible that this policy be rethought in the future. For the time being, however, you have been warned. Still, as you can read it, fakeroot-ng itself is not designed for this purpose. (BTW, I wonder why they have chosen to use the seccomp-based approach for Chromium rather than a ptrace-based...) Of the tools not mentioned above, I have noted Geordi for myself, because I liked that the controlling program is written in Haskell. Known ptrace-based isolation tools: Geordi proot fakeroot-ng ... (see also How to achieve the effect of chroot in userspace in Linux (without being root)?) seccomp One known way to achieve isolation is through the seccomp sandboxing approach used in Google Chromium. But this approach supposes that you write a helper which would process some (the allowed ones) of the "intercepted" file access and other syscalls; and also, of course, make effort to "intercept" the syscalls and redirect them to the helper (perhaps, it would even mean such a thing as replacing the intercepted syscalls in the code of the controlled process; so, it doesn't sound to be quite simple; if you are interested, you'd better read the details rather than just my answer). More related info (from Wikipedia): http://en.wikipedia.org/wiki/Seccomp http://code.google.com/p/seccompsandbox/wiki/overview LWN article: Google's Chromium sandbox, Jake Edge, August 2009 seccomp-nurse, a sandboxing framework based on seccomp. (The last item seems to be interesting if one is looking for a general seccomp-based solution outside of Chromium. There is also a blog post worth reading from the author of "seccomp-nurse": SECCOMP as a Sandboxing solution ?.) The illustration of this approach from the "seccomp-nurse" project:                        A "flexible" seccomp possible in the future of Linux? There used to appear in 2009 also suggestions to patch the Linux kernel so that there is more flexibility to the seccomp mode--so that "many of the acrobatics that we currently need could be avoided". ("Acrobatics" refers to the complications of writing a helper that has to execute many possibly innocent syscalls on behalf of the jailed process and of substituting the possibly innocent syscalls in the jailed process.) An LWN article wrote to this point: One suggestion that came out was to add a new "mode" to seccomp. The API was designed with the idea that different applications might have different security requirements; it includes a "mode" value which specifies the restrictions that should be put in place. Only the original mode has ever been implemented, but others can certainly be added. Creating a new mode which allowed the initiating process to specify which system calls would be allowed would make the facility more useful for situations like the Chrome sandbox. Adam Langley (also of Google) has posted a patch which does just that. The new "mode 2" implementation accepts a bitmask describing which system calls are accessible. If one of those is prctl(), then the sandboxed code can further restrict its own system calls (but it cannot restore access to system calls which have been denied). All told, it looks like a reasonable solution which could make life easier for sandbox developers. That said, this code may never be merged because the discussion has since moved on to other possibilities. This "flexible seccomp" would bring the possibilities of Linux closer to providing the desired feature in the OS, without the need to write helpers that complicated. (A blog posting with basically the same content as this answer: http://geofft.mit.edu/blog/sipb/33.) namespaces (unshare) Isolating through namespaces (unshare-based solutions) -- not mentioned here -- e.g., unsharing mount-points (combined with FUSE?) could perhaps be a part of a working solution for you wanting to confine filesystem accesses of your untrusted processes. More on namespaces, now, as their implementation has been completed (this isolation technique is also known under the nme "Linux Containers", or "LXC", isn't it?..): "One of the overall goals of namespaces is to support the implementation of containers, a tool for lightweight virtualization (as well as other purposes)". It's even possible to create a new user namespace, so that "a process can have a normal unprivileged user ID outside a user namespace while at the same time having a user ID of 0 inside the namespace. This means that the process has full root privileges for operations inside the user namespace, but is unprivileged for operations outside the namespace". For real working commands to do this, see the answers at: Is there a linux vfs tool that allows bind a directory in different location (like mount --bind) in user space? Simulate chroot with unshare and special user-space programming/compiling But well, of course, the desired "jail" guarantees are implementable by programming in user-space (without additional support for this feature from the OS; maybe that's why this feature hasn't been included in the first place in the design of OSes); with more or less complications. The mentioned ptrace- or seccomp-based sandboxing can be seen as some variants of implementing the guarantees by writing a sandbox-helper that would control your other processes, which would be treated as "black boxes", arbitrary Unix programs. Another approach could be to use programming techniques that can care about the effects that must be disallowed. (It must be you who writes the programs then; they are not black boxes anymore.) To mention one, using a pure programming language (which would force you to program without side-effects) like Haskell will simply make all the effects of the program explicit, so the programmer can easily make sure there will be no disallowed effects. I guess, there are sandboxing facilities available for those programming in some other language, e.g., Java. Cf. "Sandboxed Haskell" project proposal. NaCl--not mentioned here--belongs to this group, doesn't it? Some pages accumulating info on this topic were also pointed at in the answers there: page on Google Chrome's sandboxing methods for Linux sandboxing.org group
How to "jail" a process without being root?
1,412,587,091,000
Let's say that we have 2 users: a and b, that are both part of group general. I would like that any file or folder that A creates, would have write permission to the group GENERAL. How can I do it? For instance, the newly created file is set as: -rw-r--r-- 1 a general This doesn't give write permission to the group general
Yes, you can do that changing the umask. The umask determines which are the default permissions for a newly creted file. You can add umask g+w at the end of your shell configuration file (~/.bashrc for example). But actually, it´s not a recommendable practice. In the case you do want to ensure the integrity of a file and you forget to update the file permissions, it will be modifiable by the group. It's against the "secure initial values" principle of security. What you could do instead is make all the newly created file of a specific directory writable by the group. You can do this manipulating the ACLs of the directory. For example, setfacl -dm u::rw,g::rw,o::r ~/shared. Look at those posts for reference : https://serverfault.com/questions/349145/can-i-override-my-umask-using-acls-to-make-all-files-created-in-a-given-director and https://stackoverflow.com/questions/580584/setting-default-permissions-for-newly-created-files-and-sub-directories-under-a.
Give default write permission to group to any newly created files and folders
1,412,587,091,000
I would like to create a tar file with contents belonging to an owner:group pair who do not exist on the system from which the file is being made. Here's the direction I've tried: tar ca --owner='otherowner' --group='othergroup' mydata.tgz mydata And when running this command, I get the following error: tar: otherowner: Invalid owner tar: Error is not recoverable: exiting now Is there a way to force tar to accept the owner:group, even though neither of them exist on the system from which the file is being created?
Linux doesn't use internally owners and groups names but numbers - UIDs and GIDs. Users and groups names are mapped from contents of /etc/passwd and /etc/group files for convenience of user. Since you don't have 'otherowner' entry in any of those files, Linux doesn't actually know which UID and GID should be assigned to a file. Let's try to pass a number instead: $ tar cf archive.tar test.c --owner=0 --group=0 $ tar -tvf archive.tar -rw-rw-r-- root/root 45 2013-01-10 15:06 test.c $ tar cf archive.tar test.c --owner=543543 --group=543543 $ tar -tvf archive.tar -rw-rw-r-- 543543/543543 45 2013-01-10 15:06 test.c It seems to work.
Force the owner and group for the contents of a tar file?
1,412,587,091,000
root user can write to a file even if its write permissions are not set. root user can read a file even if its read permissions are not set. root user can cd into a directory even if its execute permissions are not set. root user cannot execute a file when its execute permissions are not set. Why? user$ echo '#!'$(which bash) > file user$ chmod 000 file user$ ls -l file ---------- 1 user user 12 Jul 17 11:11 file user$ cat file # Normal user cannot read cat: file: Permission denied user$ su root$ echo 'echo hello' >> file # root can write root$ cat file # root can read #!/bin/bash echo hello root$ ./file # root cannot execute bash: ./file: Permission denied
In short, because the execute bit is considered special; if it's not set at all, then the file is considered to be not an executable and thus can't be executed. However, if even ONE of the execute bits is set, root can and will execute it. Observe: caleburn: ~/ >cat hello.sh #!/bin/sh echo "Hello!" caleburn: ~/ >chmod 000 hello.sh caleburn: ~/ >./hello.sh -bash: ./hello.sh: Permission denied caleburn: ~/ >sudo ./hello.sh sudo: ./hello.sh: command not found caleburn: ~/ >chmod 100 hello.sh caleburn: ~/ >./hello.sh /bin/sh: ./hello.sh: Permission denied caleburn: ~/ >sudo ./hello.sh Hello!
Why can't root execute when executable bits are not set?
1,412,587,091,000
I'm running some services inside of Docker LXC containers on my server and I'm beginning to actually do serious things with them. One thing I'm not clear on is how user permissions work inside and outside of the container. If, for example, I'm running MySQL in a container and have its data directory set to /data, which is a Docker volume, how do permissions inside and outside of the container affect access policies? Obviously, the idea is to run MySQL as its own user in the container (ie mysql:mysql) and give it read and write rights to that directory. I assume that this would be fairly straightforward, just chmoding the directory, etc. But how does this work outside of the container? Now that I have this Docker shared volume called 'data,' how do I manage access control to it? I'm specifically looking to be able to run an unprivileged user outside of the Docker container which will periodically access the MySQL shared volume and backup the data. How can I setup permissions, users, and groups so that a specific user on the host can read/write files and folders in the Docker shared volume?
Since the release of 0.9 Docker has dropped LXC and uses its own execution environment, libcontainer. Your question's a bit old but I guess my answer still applies the version you are using. Quick Answer: To understand the permissions of volumes, you can take the analogy of mount --bind Host-Dir Container-Dir. So to fulfill your requirement you can use any traditional methods for managing permissions. I guess ACL is what you need. Long Answer: So as in your example we have a container named dock with a volume /data. docker run -tid --name dock -v /usr/container/Databases/:/data \ centos:latest /bin/bash Inside the container our MySQL server has been configured to use the /data as its data directory. So we have our databases in the /data inside the container. And outside the container on the Host OS, we have mounted this /data volume from /usr/container/Databases/ and we assign a normal user bob to take backups of the databases. From the host machine we'll configure ACLs for user bob. useradd -u 3000 bob usermod -R o=--- /usr/container/Databases/ setfacl -R -m u:bob:rwx /usr/container/Databases/ setfacl -R -d -m u:bob:rwx /usr/container/Databases/ To test it out lets take a backup with user bob. su - bob tar -cvf container-data.tar /usr/container/Databases/ And tar will list out and you can see that our user was able to access all the files. Now from inside the container if you check with getfacl you will notice that instead of bob it shows 3000. This is because the UID of bob is 3000 and there is no such user in the container so it simply displays the UID it receives from the meta data. Now if you create a user in your container with useradd -u 3000 bob you will notice that now the getfacl shows the name bob instead of 3000. Summary: So the user permissions you assign from either inside or outside the container reflects to both environments. So to manage the permissions of volumes, UIDs in host machine must be different from the UIDs in the container.
User permissions inside and outside of LXC containers?
1,412,587,091,000
When I install a program like GIMP or LibreOffice on Linux I'm never asked about permissions. By installing a program on Ubuntu, am I explicitly giving that program full permission to read/write anywhere on my drive and full access to the internet? Theoretically, could GIMP read or delete any directory on my drive, not requiring a sudo-type password? I'm only curious if it's technically possible, not if it's likely or not. Of course, I know it's not likely.
There are two things here: when you install a program by standard means (system installer such as apt/apt-get on Ubuntu) it is usually installed in some directory where it is available to all users (/usr/bin...). This directory requires privileges to be written to so you need special privileges during installation. when you use the program, it runs with your user id and can only read or write where programs executed with your id are allowed to read or write. In the case of Gimp, you will discover for instance that you cannot edit standard resources such as brushes because they are in the shared /usr/share/gimp/ and that you have to copy them first. This also shows in Edit>Preferences>Folders where most folders come in pairs, a system one which is read-only and a user one that can be written to.
Why no permissions like Android or iOS?
1,412,587,091,000
I need some clarification/confirmation/elaboration on the different roles DAC, ACL and MAC play in Linux file security. After some research from the documentation, this is my understanding of the stack: SELinux must allow you access to the file object. If the file's ACLs (e.g., setfacl, getfacl for an ACL mount) explicitly allows/denies access to the object, then no further processing is required. Otherwise, it is up to the file's permissions (rwxrwxrwx DAC model). Am I missing something? Are there situations where this is not the case?
When a process performs an operation to a file, the Linux kernel performs the check in the following order: Discretionary Access Control (DAC) or user dictated access control. This includes both classic UNIX style permission checks and POSIX Access Control Lists (ACL). Classical UNIX checks compare the current process UID and GID versus the UID and GID of the file being accessed with regards to which modes have been set (Read/Write/eXecute). Access Control List extends classic UNIX checks to allow more options regarding permission control. Mandatory Access Control (MAC) or policy based access control. This is implemented using Linux Security Modules (LSM) which are not real modules anymore (they used to be but it was dropped). They enable additionnal checks based on other models than the classical UNIX style security checks. All of those models are based on a policy describing what kind of opeartions are allowed for which process in which context. Here is an example for inodes access (which includes file access) to back my answer with links to an online Linux Cross Reference. The "function_name (filename:line)" given are for the 3.14 version of the Linux kernel. The function inode_permission (fs/namei.c:449) first checks for read permission on the filesystem itself (sb_permission in fs/namei.c:425), then calls __inode_permission (fs/namei.c:394) to check for read/write/execute permissions and POSIX ACL on an inode in do_inode_permission (fs/namei.c:368) (DAC) and then LSM-related permissions (MAC) in security_inode_permission (security/security.c:550). There was only one exception to this order (DAC then MAC): it was for the mmap checks. But this has been fixed in the 3.15 version of the Linux kernel (relevant commit).
What roles do DAC (file permissions), ACL and MAC (SELinux) play in Linux file security?
1,412,587,091,000
How can I mount some device with read-write access for a given user?
There's no generic way to do exactly that. If the filesystem doesn't have a notion of file ownership, it probably has a mount option (uid) to decide which user the files will belong to. If the filesystem does have a notion of file ownership, mount it read-write, and users will be able to write every file they have permission to. If you only want a specific user to access the filesystem, and there is a FUSE driver for it, then arrange for the user to have read-write access to the device and mount it through FUSE as that user. Another way to only let a specific user (or a specific group, or better fine-tuning through an ACL) is to place the mount point underneath a restricted-access directory: mkdir -p /media/restricted/joe/somedisk chown joe /media/restricted/joe/somedisk chmod 700 /media/restricted/joe/somedisk mount /dev/sdz42 /media/restricted/joe/somedisk If you want some users to have read-write access and others to have read-only access regardless of file permissions, mount the filesystem read-write under a restricted access directory and use bindfs to make a read-only view of that filesystem. bindfs -o perms=a-w /media/private/somedisk /media/public-read-only/somedisk You can also make a bindfs view read-write to some users and read-only for others; see the -m and -M options in the bindfs man page. Remember to put the primary mount point under a directory that only root can access.
Mount device with r/w access to specific user
1,412,587,091,000
I have a rather simplistic understanding of file permissions on *nix systems. I understand that there is a file owner and file group, but is there a hard and fast rule on whether the said file owner must belong to the file group also? Or put another way, can a file belong to a group that the owner is not a part of? If so (or if not), why? I'd like to increase my understanding... I can't seem to find anything that specifically talks about this out on the interwebs... I'm also open to some good reading material on the subject.
No, there's no need for a file's owner to belong to that file's group. There's no mechanism in place for checking or enforcing this. Additionally, a user could belong to a group at one time and then be removed; nothing will go through the filesystem to check for files that would be in conflict. Basically, the owner and group metadata for a file is just sitting there on the disk, and doesn't have any external links. (Tangent: it's stored by numeric user id and group id, and these are resolved by the system when asked.) Also, only one set of permissions is ever used at a time — if you are the owner, only owner permissions are looked at and the group permissions don't matter. If you are not the owner but are in the group, group permissions are used. Finally, if you are not in the group nor the owner, the "other" permissions are used. If you are both the owner of a file and in the file's group, the group bits don't matter.
File owner must belong to file group?
1,412,587,091,000
I'm unable to delete a file with rm -rf /home/wordpress/testDomain.com from my Linux machine. Instead of the file being deleted, I get an Operation not permitted error. How can I fix this? $ cd /home/wordpress/testDomain.com/wp-content/plugins/sitepress-multilingual-cms/vendor/otgs $ sudo rm -f annmanagement rm: cannot remove 'annmanagement': Operation not permitted $ ls -al total 3308 drwxr-xr-x 2 www-data www-data 4096 May 27 13:43 . drwxr-xr-x 3 www-data www-data 4096 May 27 13:46 .. -r-------- 1 root root 3375768 Dec 27 2016 annmanagement $ sudo find . -inum 535255 -exec rm -i {} \;** rm: remove regular file './annmanagement'? y rm: cannot remove './annmanagement': Operation not permitted $ lsattr ----i---------e----- ./annmanagement $ stat annmanagement File: annmanagement Size: 3375768 Blocks: 6600 IO Block: 4096 regular file Device: fd00h/64768d Inode: 535255 Links: 1 Access: (0400/-r--------) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2022-05-27 09:02:30.650849241 +0200 Modify: 2016-12-27 10:48:37.000000000 +0100 Change: 2022-03-15 07:59:42.524922372 +0100 Birth: - Strace output: $ sudo strace rm -f annmanagement** execve("/bin/rm", ["rm", "-f", "annmanagement"], 0x7ffc24e45690 /* 13 vars */) = 0 brk(NULL) = 0x55cd820a2000 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe7894d320) = -1 EINVAL (Invalid argument) access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=42697, ...}) = 0 mmap(NULL, 42697, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8c5d386000 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8c5d384000 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8c5d192000 mmap(0x7f8c5d1b4000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f8c5d1b4000 mmap(0x7f8c5d32c000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f8c5d32c000 mmap(0x7f8c5d37a000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f8c5d37a000 mmap(0x7f8c5d380000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8c5d380000 close(3) = 0 arch_prctl(ARCH_SET_FS, 0x7f8c5d385580) = 0 mprotect(0x7f8c5d37a000, 16384, PROT_READ) = 0 mprotect(0x55cd80c6a000, 4096, PROT_READ) = 0 mprotect(0x7f8c5d3be000, 4096, PROT_READ) = 0 munmap(0x7f8c5d386000, 42697) = 0 brk(NULL) = 0x55cd820a2000 brk(0x55cd820c3000) = 0x55cd820c3000 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=3035952, ...}) = 0 mmap(NULL, 3035952, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8c5ceac000 close(3) = 0 ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0 newfstatat(AT_FDCWD, "annmanagement", {st_mode=S_IFREG|0400, st_size=3375768, ...}, AT_SYMLINK_NOFOLLOW) = 0 unlinkat(AT_FDCWD, "annmanagement", 0) = -1 EPERM (Operation not permitted) openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2996, ...}) = 0 read(3, "# Locale name alias data base.\n#"..., 4096) = 2996 read(3, "", 4096) = 0 close(3) = 0 openat(AT_FDCWD, "/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, "rm: ", 4rm: ) = 4 write(2, "cannot remove 'annmanagement'", 29cannot remove 'annmanagement') = 29 openat(AT_FDCWD, "/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, ": Operation not permitted", 25: Operation not permitted) = 25 write(2, "\n", 1 ) = 1 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) close(0) = 0 close(1) = 0 close(2) = 0 exit_group(1) = ? +++ exited with 1 +++
The file has the i ("immutable") attribute, according to the output from lsattr that you show. From the chattr(1) manual (on Ubuntu): A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be opened in write mode. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute. This recreates your situation on my local system for the file called file: $ touch file $ lsattr file --------------e----- file $ sudo chattr +i file $ lsattr file ----i---------e----- file $ sudo rm file rm: cannot remove 'file': Operation not permitted To remove the file, I first have to unset the immutable attribute as root: $ sudo chattr -i file $ rm file
Unable to delete this file as root [duplicate]
1,412,587,091,000
I need to set read and write permissions for root user to directory subfolderN and all its parent folders till root. I can do it by hands: $ sudo chmod +rx /root/subfolder1/subfolder2/subfolderN $ sudo chmod +rx /root/subfolder1/subfolder2 $ sudo chmod +rx /root/subfolder1 $ sudo chmod +rx /root But if N is big I am tired. How to do automatically by one command?
This can be done easily in the shell, starting in the subdir and moving upwards: f=/root/subfolder1/subfolder2/subfolderN while [[ $f != / ]]; do chmod +rx "$f"; f=$(dirname "$f"); done; This starts with whatever file/directory you set f too, and works on every parent directory, until it encounters "/" (or whatever you set the string in the condition of the loop to). It does not chmod "/". Make sure both f and the directory in the condition of the loop are absolute paths.
set read and write permissions to folder and all its parent directories
1,412,587,091,000
We have an automated baseline check that raises an alert if the permissions on /etc/shadow aren’t set to 000. The staff who receive these alerts have started to question the sanity of 000, since root can read and write wherever it wants to (all files are automatically at least 600 for root) but root can’t execute a file without execute permission set (no automatic 700 file permission for root). Setting /etc/shadow permissions to 000 is in a number of baselines, e.g. the Ansible playbooks in the official Red Hat GitHub repository (for PCI DSS, CJIS, NIST, CCE). Is there an origin story behind why /etc/shadow should be 000 and not e.g. the seemingly functionality identical 600? Or are my assumptions wrong about how restrictive / permissive Linux is for the root user?
The idea behind setting /etc/shadow permissions to 000 is to protect that file from being accessed by daemons, even when running as root, by ensuring that access is controlled by the DAC_OVERRIDE capability. Since Fedora 12 and RHEL 6, Fedora-based systems run daemons without DAC_OVERRIDE, but grant DAC_OVERRIDE to administrator login sessions (so that the change is invisible to administrators). See lower process capabilities for details. This relies on the fact that 600 and 000 permissions aren’t functionally identical: 600 grants read-write to the file owner, whereas 000 only grants access to processes with the DAC_OVERRIDE capability. Traditionally, running as root always granted DAC_OVERRIDE, but that doesn’t have to be the case. (SELinux can also be used to limit root’s abilities, but that’s not what’s involved here. /etc/shadow does have its own SELinux context, providing additional access controls.)
/etc/shadow permissions security best practice (000 vs. 600 vs. 640)
1,412,587,091,000
It seems that whenever I create a file with touch the permissions are set to: -rw-r--r--. Is there some way that I can configure the permissions with touch or does this have to be done after with a different command?
You can modify your umask to allow (for most implementations) more read/write privileges, but not executable, since generally the requested permissions are 0666. If your umask is 022, you'll see touch make a 0644 file. Interestingly, POSIX describes this behavior in terms of creat: If file does not exist: The creat() function is called with the following arguments: The file operand is used as the path argument. The value of the bitwise-inclusive OR of S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH is used as the mode argument. and it is only by following the links to creat, then to open, noticing the mention of umask and back-tracking to open (and creat) to verify that umask is supposed to affect touch. For umask to affect only the touch command, use a subshell: (umask 066; touch private-file) (umask 0; touch world-writable-file) touch file-as-per-current-umask (note that in any case, if the file existed beforehand, touch will not change its permissions, just update its timestamps).
How to set file permissions with touch command
1,412,587,091,000
I'm running a server, and I need to give read/write access to a particular directory to a single user. I've tried the following: sudo adduser abcd sudo groupadd abcdefg chown -R .abcdefg /var/www/allowfolder chmod -R g+rw /var/www/allowfolder usermod -a -G comments abcd The above seems to work, however it gives the user read-only access to the rest of the server. How can I set up permissions so that the user can only read and write to a particular folder? The user should also be able to run programs like mysql.
Negative ACLs You can prevent a user from accessing certain parts of the filesystem by setting access control lists. For example, to ensure that the user abcd cannot access any file under /home: setfacl -m user:abcd:0 /home This approach is simple, but you must remember to block access to everything that you don't want abcd to be able to access. Chroot To get positive control over what abcd can see, set up a chroot, i.e. restrict the user to a subtree of the filesystem. You need to make all the files that the user needs (e.g. mysql and all its dependencies, if you want the user to be able to run mysql) under the chroot. Say the path to the chroot is /home/restricted/abcd; the mysql program needs to be available under /home/restricted/abcd. A symbolic link pointing outside the chroot is no good because symbolic link lookup is affected by the chroot jail. Under Linux, you can make good use of bind mounts: mount --rbind /bin /home/restricted/abcd/bin mount --rbind /dev /home/restricted/abcd/dev mount --rbind /etc /home/restricted/abcd/dev mount --rbind /lib /home/restricted/abcd/lib mount --rbind /proc /home/restricted/abcd/proc mount --rbind /sbin /home/restricted/abcd/sbin mount --rbind /sys /home/restricted/abcd/sys mount --rbind /usr /home/restricted/abcd/usr You can also copy files (but then you'll need to take care that they're up to date). To restrict the user to the chroot, add a ChrootDirectory directive to /etc/sshd_config. Match User abcd ChrootDirectory /home/restricted/abcd You can test it with: chroot --userspec=abcd /home/restricted/abcd/ /bin/bash Security framework You can also use security frameworks such as SELinux or AppArmor. In both cases, you need to write a fairly delicate configuration, to make sure you aren't leaving any holes.
Give user read/write access to only one directory
1,412,587,091,000
I'm using rsync -rlptD to copy a directory from another user. There are a few files (I have no way of knowing these in advance) which I don't have permission to copy. Is there a way have rsync ignore these. The trouble is that if rsync return non-zero my bash -x script will exit.
Rsync doesn't have an option for this. I see two solutions. One is to parse rsync error messages; this isn't very robust. The other is to generate a list of unreadable files to filter. cd /source/directory exclude_file=$(mktemp) find . ! -readable -o -type d ! -executable | sed -e 's:^\./:/:' -e 's:[?*\\[]:\\1:g' >>"$exclude_file" rsync -rlptD --exclude-from="$exclude_file" . /target/directory rm "$exclude_file" If your find doesn't have -readable and -executable, replace them by the appropriate -perm directive. This assumes that there are no unreadable files whose name contains a newline. If you need to cope with those, you'll need to produce a null-delimited file list like this, and pass the -0 option to rsync: find . \( ! -readable -o -type d ! -executable \) -print0 | perl -0000 -pe 's:\A\./:/:' -e 's:[?*\\[]:$1:g' >>"$exclude_file"
rsync: skip files for which I don't have permissions
1,412,587,091,000
I was reading Practical Unix and Internet Security, when I came across the following lines which I couldn't comprehend. If you are using the wu archive server, you can configure it in such a way that uploaded files are uploaded in mode 004, so they cannot be downloaded by another client. This provides better protection than simply making the directory unreadable, as it prevents people from uploading files and then telling their friends the exact filename to download. A permission of 004 corresponds to -------r--. Can't a file be downloaded if it has read access? Also why is it considered better than simply making the directory non-readable? What does this imply? Note: This is with regard to unauthorised users leaving illegal and copyrighted material on servers using anonymous FTP. The above solution was suggested to prevent this along with a script which deletes the directory contents after a period of time.
The permissions 004 (------r--) means that the file can only be read by processes that are not running as the same user or as the same group as the FTP server. This is rather unusual: usually the user has more rights than the group, and the group has more rights than others. Normally the user can change the permissions, so it's pointless to give more restrictive permissions to the user. It makes sense here because the FTP server (presumably) doesn't have a command to change permissions, so the files will retain their permissions until something else changes them. Since the user that the FTP server is running as can't read the files, people won't be able to download the file. That makes it impossible to use the FTP server to share file. Presumably some process running as a different user and group reads the file at some point, verifies that it complies to some policy, copies the data if it does, and deletes the uploaded file. It would have made more sense to me to give the file permissions 040 (readable by the group only) and have the consumer process run as the same group as the FTP server, but a different user.
What is so special about Linux permission 004?
1,412,587,091,000
I experienced a strange behaviour in my /tmp directory. Although a user belongs to a group that has permissions to read/write a file, he cannot do so. In this example, I create a new file /tmp/test.txt as user max. I give it the 777 permissions and make the file belong to the group root, but user root still cannot edit it. su max touch /tmp/test.txt chmod 777 /tmp/test.txt su root chown max:root /tmp/test.txt # ls -l /tmp/test.txt -rwxrwxrwx 1 max root 0 26. Feb 12:08 test.txt # echo "foobar" > /tmp/test.txt bash: /tmp/test.txt: Permission denied When moving test.txt to a different directory, everything works as expected. /tmp is a tmpfs mounted via fstab via the following options: tmpfs /tmp tmpfs nodev,nosuid,size=5G 0 0 When running ls -l /, the tmp folder looks like the following: drwxrwxrwt 20 root root 640 26. Feb 12:01 tmp/ I am running Manjaro, an Arch Linux derivate. Did I do something wrong with mounting tmpfs?
The behavior you are showing seems to depend on the fs.protected_regular Linux kernel parameter, introduced along with fs.protected_fifos by this commit (converged in version 4.19, I believe), with the aim to fix security vulnerabilities. Excerpt of the commit message (emphasis mine): namei: allow restricted O_CREAT of FIFOs and regular files Disallows open of FIFOs or regular files not owned by the user in world writable sticky directories, unless the owner is the same as that of the directory or the file is opened without the O_CREAT flag. The purpose is to make data spoofing attacks harder. ... The same commit message also reports a list of related Common Vulnerabilities and Exposures (CVE) numbers. Thus, provided that userX is root or is otherwise granted write access to /tmp/file, and that /tmp is a world writable directory with the sticky bit set, they can open file for writing only if: userX is the owner of file; or both file and directory /tmp are owned by the same user. In your test, root has write permissions on /tmp/test.txt, but is not the owner of the file, nor have /tmp/test.txt and /tmp the same owner (respectively max and root). The issue appears to be totally unrelated to the way /tmp is mounted. The relevant documentation is in Documentation/sysctl/fs.txt: protected_fifos: The intent of this protection is to avoid unintentional writes to an attacker-controlled FIFO, where a program expected to create a regular file. ... protected_regular: This protection is similar to protected_fifos, but it avoids writes to an attacker-controlled regular file, where a program expected to create one. When set to "0", writing to regular files is unrestricted. When set to "1" don't allow O_CREAT open on regular files that we don't own in world writable sticky directories, unless they are owned by the owner of the directory. When set to "2" it also applies to group writable sticky directories. That is, the protection described above can be disabled with the command: sysctl fs.protected_regular=0 A bit of testing to backup our hypothesis: $ su - root # sysctl fs.protected_regular fs.protected_regular = 1 # cd / # mkdir test # chmod 1777 test # su - otheruser $ echo hello >/test/somefile $ exit logout # cat /test/somefile hello # ls -lah test/somefile -rw-r--r-- 1 otheruser otheruser 6 Feb 26 17:21 test/somefile # echo root >>test/somefile -bash: test/somefile: Permission denied # sysctl fs.protected_regular=0 fs.protected_regular = 0 # echo root >>test/somefile # cat /test/somefile hello root # sysctl fs.protected_regular=1 fs.protected_regular = 1 # echo root >>test/somefile -bash: test/somefile: Permission denied # chmod 0777 /test/ # echo root >>test/somefile # cat test/somefile hello root root Unlike fs.protected_hardlinks and fs.protected_symlinks, fs.protected_regular and fs.protected_fifos are not enabled by default in the kernel code. Enabling them is a backward incompatible change (as the example you provided in this comment points out) and, as far as I can tell, systemd did it in version 241, with this recent commit. Credits: thanks to JdeBP for pointing in the right direction with a comment to the question.
Group permissions for root not working in /tmp
1,412,587,091,000
I currently have an extra HDD which I am using as my workspace. I am trying to get it to mount automatically on reboots using the following line added to /etc/fstab /dev/sdb1 /media/workspace auto defaults 0 1 This works to auto mount it, however I would like to restrict read/write access to users belonging to a specific group. How would I go about doing this in /etc/fstab? Can I simply just use chown or chmod to control the access?
If the filesystem type is one that doesn't have permissions, such as FAT, you can add umask, gid and uid to the fstab options. For example: /dev/sdb1 /media/workspace auto defaults,uid=1000,gid=1000,umask=022 0 1 uid=1000 is the user id. gid=1000 is the group id. umask=022 this will set permissions so that the owner has read, write, execute. Group and Others will have read and execute. To see your changes you do not need to reboot. Just umount and mount again without arguments. For example: umount /media/workspace mount /media/workspace But make sure to do not have any process (even your shell) using that directory.
Automatically mount a drive using /etc/fstab, and limiting access to all users of a specific group
1,412,587,091,000
Is there a way to back up and restore file ownership and permissions (the things that can be changed with chown and chmod)? You can do this in Windows using icacls. What about access control lists?
You can do this with the commands from the acl package (which should be available on all mainstream distributions, but might not be part of the base installation). They back up and restore ACL when ACL are present, but they also work for basic permissions even on systems that don't support ACL. To back up permissions in the current directory and its subdirectories recursively: getfacl -R . >permissions.facl To restore permissions: setfacl --restore=permissions.facl
Back up and restore file permissions
1,412,587,091,000
Why does redirection, using sudo give me an error for the following commands? $ sudo printf "foo" >/etc/file bash: /etc/file: Permission denied $ sudo printf "foo" ~/file; cat ~file >/etc/file bash: /etc/file: Permission denied ...yet I have no such problem when I use an editor, or cp. I don't think I've ever tried this before, so I don't know if there is something haywire on my system, or if this is normal. It seems a bit restrictive to be normal, but(?) maybe it is intended to be restrictive... (using Ubuntu)
It is normal. The file after the > is not open by the process running under sudo, but by the shell, which isn't. Try this instead: printf "foo" | sudo tee /etc/file
Why can't sudo redirect stdout to /etc/file, but sudo 'nano' or 'cp' can? [duplicate]