date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,434,136,955,000 |
Kindly Consider:
$ id # Me
uid=100(user1) gid=200(group1) groups=200(group1)
$ ls -l tnsnames.ora # So user1 has only read permission on below file.
-rw-rw-r-- 1 oracle dba 411024 Jul 28 2010 tnsnames.ora
$ cp tnsnames.ora tnsnames.ora_bak
$ cat tnsnames.ora_bak > tnsnames.ora # No write access
-bash: tnsnames.ora: Permission denied
$ cp -p tnsnames.ora tnsnames.ora_copy # Copy file and preserve mode, ownership, timestamps. Requires sudo to succeed completely.
$ ls -l tnsnames.ora_copy # Mode and timestamps preserved; ownership not preserved.
-rw-rw-r-- 1 user1 group1 411024 Jul 28 2010 tnsnames.ora_copy
$ mv tnsnames.ora tnsnames.ora_move
$ ls -l tnsnames.ora_move # Move preserves mode, ownership, timestamps.
-rw-rw-r-- 1 oracle dba 411024 Jul 28 2010 tnsnames.ora_move
$
Update
$ ls -l # As pointed out by @Gilles, the source (which is also the destination here) directory has r-x mode which allows mv to work.
drwxrwxrwx 3 oracle dba 4096 Aug 11 20:38 oracle
How can the mv command move the file and preserve mode, ownership, timestamps while we cannot do the same with cp ...?
Also if you do not have write access to a file, how is it possible to change the location (metadata) of the file using mv; or we can look at it the other way... where mv will first make a copy of the file, then how does it get the rights to set the owner/group on the copied file and delete the source file it does not have write permissions on..
OS/Bash/Utility Version information:
$ echo $SHELL
/bin/bash
$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
...
$ uname -a
Linux server1 2.6.18-371.8.1.el5 #1 SMP Fri Mar 28 05:53:58 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
$ cp --version
cp (GNU coreutils) 5.97
...
$ mv --version
mv (GNU coreutils) 5.97
...
|
mv does not make a copy of the file and remove the original, unless you're moving the file between different filesystems. mv moves the file.
In order to move a file, you need to have permission to detach it from the directory where it was before, and to attach it to the directory where you're putting it. In other words, you need write (and execute) permission to both the source directory and the destination directory. You do not need to have any particular permission on the file, since you aren't modifying or accessing the file itself. (Analogy: you can move a locked box around even if you don't have the key do open the box.)
cp -p can and does preserve the permissions of the file, but it cannot preserve the file's ownership in general. Since you aren't running cp as root, it cannot create files that don't belong to you, or that don't belong to a group that you belong to.
| Move preserves ownership of source files not allowing writes |
1,434,136,955,000 |
Related question: How does the Linux file system/organization differ from Windows?
I am somewhat familiar with how privileges work when it comes to files and directories - each entry has an owner and group property that represent the owner of the file and the group that the owner belongs to (correct me if I'm wrong).
How does this differ from the organization of permissions in the NTFS filesystem on Windows? What advantages does Unix's permission system have over NTFS?
|
NTFS has Windows ACEs. Unix uses "mode bits" on each file.
On NTFS, each file can have an owner, and zero or more Windows access control entries (ACEs). An ACE consists of a principal (users and groups are principals), a set of operations (Read, Write, Execute, etc.) and whether those operations are allowed or denied. Files can have many ACEs. Other objects in Windows other than files can have ACEs as well, such as registry entries, printer objects, and other things. All ACEs are taken into account when a file operation occurs. Deny takes precedence over allow.
Windows ACEs support inheritance where you can set an ACE for a directory and have it automatically propagate to lower level directories.
Files in Unix have an owning user (owner) and an owning group (owner-group). There are three fixed "principals" which are owner, members of the owning group, and everyone else (a.k.a world). For each principal there are three "bits" which cover read, write, and execute abilities. (these have different meanings for directories than files, see this). These bits determine who can perform what operations. This is called the file's mode and is built into the file (there are no separate ACEs).
Most of the time you are concerned with the "world" permissions, i.e. setting all three bits to 0 for "world" means no one who isn't the owner or group-owner can do anything with the file. Unix permissions only work on the filesystem, but since most objects appear as files you can use permissions to restrict access to disks, printers, etc. Unix permissions are simpler but more "coarse." Unix permissions do not support inheritance and will not affect lower level directories, with the exception of execute permission for directories (I think) which causes newly created files to assume permissions of the directory (but doesn't affect currently created files).
Traditionally Unix files have a single owner and a single owner-group. There are extensions to Linux that add ACEs to files in similar fashion to Windows.
Unix's advantage is only that a simpler system is usually easier to understand and secure, and speed since the filesystem doesn't have to fetch ACEs in addition to inodes when opening files.
| How does the Unix file privilege system differ from that of Windows? |
1,434,136,955,000 |
The below fails:
sudo -u chris ls /root
ls: cannot open directory '/root': Permission denied
While the below succeeds:
sudo ls /root
...
I do not understand why. I assume -u just changes the $USER/running user to the parameter provided in addition to having root privliges. What is the cause behind this behavior?
|
sudo -u chris runs the given command as user chris, not as root with USER set to chris. So if chris can’t access /root, sudo -u chris won’t change that.
See man sudo:
-u user, --user=user
Run the command as a user other than the default target user (usually root).
sudo isn’t specifically a “run as root” tool; it’s a “run as some other user or group” tool.
| Why do I not have sufficient permission just like root when running sudo as a user |
1,434,136,955,000 |
I have a file with the following file mode bits (a+rw):
[0] mypc<johndoe>:~>sudo touch /tmp/test
[0] mypc<johndoe>:~>sudo chmod a+rw /tmp/test
[0] mypc<johndoe>:~>ls -l /tmp/test
-rw-rw-rw- 1 root root 0 Mar 13 11:09 /tmp/test
Why can't I remove the file?
[0] mypc<johndoe>:~>rm /tmp/test
rm: cannot remove '/tmp/test': Operation not permitted
|
The /tmp directory is conventionally marked with the restricted deletion flag, which appears as a permission letter t or T in ls output.
Restricted deletion implies several things. In the general case, it implies that only the owner of the file, or the owner of /tmp itself, can delete a file/directory in /tmp.
You can not delete the file, because you are not the owner, which is root. Try running rm with sudo which you probably forgot.
sudo rm /tmp/test
More specifically to Linux alone, the restricted deletion flag (on a world-writable directory such as /tmp) also enables the protected_symlinks, protected_hardlinks, protected_regular, and protected_fifos restrictions, which in such directories respectively prevent users from following symbolic links that they do not own, prevent users making hard links to files that they do not own, prevents users opening FIFOs that they do not own, and prevents users from open existing files that they do not own when they expected to create them.
This will surprise you with permissions errors when doing various further things as root when you do use sudo.
More on these at question like "Hard link permissions behavior different between CentOS 6 and CentOS 7" , "Symbolic link not working as expected when changes user", and "Group permissions for root not working in /tmp".
| Can't remove a file with file mode bits a+rw |
1,434,136,955,000 |
I am working with Ubuntu and I have a jar file in this folder /export/home/david
And I am logged in machineB as david user.
Some other user is also logged in that same machine. And I want other user to copy the above jar file from my location.
But somehow they are not able to do that as they are getting permission denied. Is there any way I can add some permission on that jar file or on my folder so that anybody can copy the files from that folder?
Update:-
Below is the result I got -
david@machineB:~$ groups david
david : uucp
otheruser@machineB:~$ groups otheruser
otheruser : app
david@machineB:~$ ls -l foo.jar
-rw-r--r-- 1 david uucp 6543346 2014-03-07 18:27 foo.jar
david@machineB:~$ ls -ld $(echo "/home/david/foo.jar" | sed -r ':a; s#(.*)/[^/]*$#\1#;p;ta')
drwxr-xr-x 22 root root 4096 2014-05-04 08:04 /home
drwx------ 4 david uucp 4096 2014-03-07 18:36 /home/david
|
Well, for some strange reason, your $HOME directory is only accessible to you. This is not the default on any system I am familiar with, you or your sysadmin have probably set it up this way.
Anyway, all you need to do is give everyone read/execute access to your $HOME. This is the norm on most multi-user systems to allow people to share their work. Just run this command:
chmod a+rx ~/
This will set the permissions of your home to rwxr-xr-x and allow anyone to copy files from your $HOME.
| Allow other user to copy the files from my folder? |
1,434,136,955,000 |
I know that similar questions have been asked about permissions, but which form of compression or archiving keeps the permissions and file owners of each file and directory?
I was considering the tar.gz format, but would this be right?
I need to move 37GB of files and directories to another server and need everything to be exactly the same when uncompressed.
|
Both traditional archiving tools tar and cpio preserve ownership and Unix permissions (user/group/other) as well as timestamps (with cpio, be sure to pass -m when extracting). If you don't like their arcane syntax¹, you can use their POSIX replacement pax (pax -w -pe) All of these output an uncompressed archive; pipe the archive into a tool like gzip or xz to compress it (GNU tar has options to do the compression). Users and groups are identified by their name; GNU tar has an option .
None of these tools preserve modern features such as ACL, capabilities, security contexts or other extended attributes.
Some versions of tar can store ACL. See What to use to backup files, preserving ACLs? With GNU tar, pass --acls both when creating and extracting the archive.
A squashfs filesystem, as suggested by mikeserv, stores capabilities and extended attributes including SELinux context, but not ACL. (You need versions that aren't too antique.) If you have both ACL and security contexts, you can use a squashfs filesystem, and save the ACL by running getfacl -R at the root of the original filesystem and restore them after extracting the files with setfacl --restore.
If you want to save absolutely everything including ACL, subsecond timestamps, extended attributes and filesystem-specific attributes, you can clone the filesystem. The downside of this approach is that you can't conveniently directly write a compressed copy. The ultimate way to clone the filesystem is to copy the block device; of course this is wasteful in that it copies the empty space. Alternatively, create a filesystem that's large enough to store all the files and use cp -a with the cp command from GNU coreutils to copy the files; GNU cp is pretty good at copying everything including non-traditional features such as extended attribute and ACLs.
¹ Though this one is really overblown.
| Compression / archiving that keeps permissions and file owner? |
1,434,136,955,000 |
I have a text file named foo.txt with root permission in one Linux distribution. I copied it to another Linux distribution on another computer.
Would file permissions be still maintained for foo.txt?
If yes, how does Unix/Linux linux know, and duplicate the permissions of the file?
Does it add extra bytes (which indicates the permissions) to the file?
|
To add Eric's answer (don't have rep to comment), permissions are not stored in file but file's inode (filesystem's pointer to the file's physical location on disk) as metadata along with owner and timestamps. This means that copying file to non-POSIX filesystem like NTFS or FAT will drop the permission and owner data.
File owner and group is just a pair of numbers, user ID (UID) and group ID (GID) respectively. Root UID is 0 as standard so file will show up as owned by root on (almost) every unix-compliant system. On the other hand, non-root owner will not be saved in meaningful way.
So in short, root ownership will be preserved if tarball'd or copied via extX usbstick or the like. Non-root ownership is unreliable.
| How does Unix implement file permissions? |
1,434,136,955,000 |
A question that occurred to me earlier: are file permissions/attributes OS- (and therefore kernel-) dependent or are they filesystem-dependent?
It seems to me that the second alternative is the more logical one, yet I never heard of reiserfs file permissions, for example: only "Unix file permissions". On the other hand, to quote from a Wikipedia article:
As new versions of Windows came out, Microsoft has added to the inventory of available attributes on the NTFS file system
which seems to suggest that Windows file attributes are somehow tied to the filesystem.
Can someone please enlighten me?
|
Both the kernel and the filesystem play a role. Permissions are stored in the filesystem, so there needs to be a place to store the information in the filesystem format. Permissions are enforced and communicated to applications by the kernel, so the kernel must implement rules to determine what the information stored in the filesystem means.
“Unix file permissions” refer to a traditional permission system which involves three actions (read, write, execute) controlled via three role types (user, group, other). The job of the filesystem is to store 3×3=9 bits of information. The job of the kernel is to interpret these bits as permissions; in particular, when a process attempts an operation on a file, the kernel must determine, given the user and groups that the process is running as, the permission bits of the file, and the requested operation, whether to allow the operation. (“Unix file permissions” also usually includes setuid and setgid bits, which aren't strictly speaking permissions.)
Modern unix systems may support other forms of permissions. Most modern unix systems (Solaris, Linux, *BSD) support access control lists which allow assigning read/write/excecute permissions for more than one user and more than one group for each file. The filesystem must have room to store this extra information, and the kernel must include code to look up and use this information. Ext2, reiserfs, btrfs, zfs, and most other modern unix filesystem formats define a place to store such ACLs. Mac OS X supports a different set of ACL which include non-traditional permissions such “append” and “create subdirectory”; the HFS+ filesystem format supports them. If you mount an HFS+ volume on Linux, these ACLs won't be enforced since the Linux kernel doesn't support them.
Conversely, there are operating systems and filesystems that don't support access control. For example, FAT and variants were designed for single-user operating systems and removable media and its permissions are limited to read/read-write and hidden/visible. These are the permissions enforced by DOS. If you mount an ext2 filesystem on DOS, it won't enforce the ext2 permissions. Conversely, if you access a FAT filesystem on Linux, all files will have the same permissions.
Successive versions of Windows have added support for more permission types. The NTFS filesystem was extended to store those extra permissions. If you access a filesystem with the newer permissions on an older operating system, the OS won't know about these newer permissions and so won't enforce them. Conversely, if you access an older filesystem with a newer operating system, it won't have contain of the new permissions and it is up to the OS to provide sensible fallbacks.
| How do file permissions/attributes work? Kernel-level, FS-level or both? |
1,434,136,955,000 |
This is a follow up question to this Q/A.
I tried the command on my laptop it worked:
setfacl -m 'u:programX:rwx' /etc/NetworkManager
I checked that my embedded device had acl installed and marked correct.
But I'm finding when using the command on the embedded device I get setfacl: /etc/NetworkManager: Operation not supported.
When I check man setfacl my version of acl seems to support the -m flag.
Why wouldn't acl on the device support the operation, when it works fine on my laptop?
Result of mount | grep -w /:
/dev/block/mtd/by-name/linuxroot on / type ext4 (rw,relatime,barrier=1,data=ordered)
|
The ext4 code in older kernels (I do not know until when) needs acl as mount option. So you may try:
mount -o remount,acl /
/etc/fstab
Your fstab contains a line like
/dev/sda3 / ext4 defaults 0 0
You have to add acl to the options field:
/dev/sda3 / ext4 defaults,acl 0 0
| Operation not supported with setfacl? |
1,434,136,955,000 |
This is on a Raspberry Pi.
Here's the output of sudo ls -lL /sys/class/gpio/gpio18:
-rwxrwx--- 1 root gpio 4096 Mar 8 10:50 active_low
-rwxrwx--- 1 root gpio 4096 Mar 8 10:52 direction
-rwxrwx--- 1 cameron cameron 4096 Mar 8 10:50 edge
drwxrwx--- 2 root gpio 0 Mar 8 10:50 power
drwxrwx--- 2 root gpio 0 Mar 8 10:50 subsystem
-rwxrwx--- 1 root gpio 4096 Mar 8 10:50 uevent
-rwxrwx--- 1 cameron cameron 4096 Mar 8 10:50 value
So looks like I should now have access to value, great. However:
cameron@raspberrypi~ $ echo 1 > /sys/class/gpio/gpio18/value
-bash: /sys/class/gpio/gpio18/value: Permission denied
What's going on? If I chmod 777 everything, then it works, but I shouldn't have to do that when I own the file.
|
I solved the problem by adding cameron to the gpio group:
sudo usermod -aG gpio cameron
gpio export 18 out
echo 1 > /sys/class/gpio/gpio18/value
Now everything works.
| Unable to write to a GPIO pin despite file permissions on /sys/class/gpio/gpio18/value |
1,434,136,955,000 |
I installed anaconda on our new VM and I can't list its contents. I can change my directory to .../anaconda/ but when I type ls -l I get:
ls: cannot open directory .: Permission denied
However, when I enter:
sudo ls -l
I get
total 92
drwxrwxrwx. 2 gcw8 PosixUsers 12288 May 26 15:30 bin
drwxrwxrwx. 2 gcw8 PosixUsers 12288 May 26 15:30 conda-meta
drwxrwxrwx. 3 gcw8 PosixUsers 4096 Mar 27 16:33 docs
drwxrwxrwx. 2 gcw8 PosixUsers 4096 Mar 27 16:33 envs
drwxrwxrwx. 2 gcw8 PosixUsers 4096 Mar 27 16:33 etc
drwxrwxrwx. 6 gcw8 PosixUsers 4096 May 26 15:19 Examples
drwxrwxrwx. 41 gcw8 PosixUsers 4096 May 26 15:19 include
drwxrwxrwx. 11 gcw8 PosixUsers 20480 May 26 15:19 lib
-rw-rwxrwx. 1 gcw8 PosixUsers 3700 Nov 7 2013 LICENSE.txt
drwxrwxrwx. 185 gcw8 PosixUsers 12288 May 26 15:30 pkgs
drwxrwxrwx. 3 gcw8 PosixUsers 4096 Mar 27 16:33 plugins
drwxrwxrwx. 10 gcw8 PosixUsers 4096 Mar 27 16:33 share
drwxrwxrwx. 3 gcw8 PosixUsers 4096 Mar 27 16:48 ssl
The groups command indicates that I'm a member of PosixUsers and I'm the one who initially created this so why can't I access it? At one point I ran chmod -R ugo+rwx .../anaconda/ but I still don't see how that would result in this error. If anything, it should alleviate it. I'm running CentOS and all of this is being done via ssh. Can anyone see the problem?
|
Note the . at the end of the permissions (drwxrwxrwx.): that means there's an SELinux context involved. You need to get that right for your user to be able to list the contents of the directory.
To see the contexts for your directory, run
sudo ls -alZ
(the -Z option shows the SELinux contexts required).
The CentOS wiki has a good page on SELinux. You'll find more information about the last character in the permissions at '+' and 's' in permission strings.
| Permission errors even though permissions are wide open |
1,434,136,955,000 |
I have mirrored 100 GiB of files. On my mirror, some of the timestamps and maybe file permissions are wrong. I would like to use rsync to fix this.
The server from which I have downloaded has more than 100 GiB of files. My mirror mirrors certain files from each source directory. It does not mirror whole directories.
How can I tell rsync to fix my timestamps and file permissions, without redownloading 100 GiB?
For information, I am now trying rsync -av --list-only HOST::MODULE >/tmp/list.txt. Once I have fetched this data, if none of you can tell me a better answer, I will write a script to touch each of my files based on the data.
But is there no neater way to do the job?
(There is this question, but it does not seem to answer what I need.)
|
If your source and destination are on separate systems, with an rsync client talking to an rsync server (of any sort), then the permissions and timestamps will be updated without a data content transfer. For example:
rsync -avP --existing server:/path/to/source /path/to/target
rsync -avP --existing server::module /path/to/target
On the other hand, if your source and destination are managed by the same single rsync process, such as when the server's filesystem is accessible via NFS, then there is no efficient way it can confirm that the data is the same in both cases so it abandons its shortcuts and simply recopies the data with the corrected permissions and timestamps. For example:
rsync -avP --existing /path/to/server/source /path/to/target
If you have this second scenario and you are absolutely certain that the file contents are identical, there is a workaround that will force rsync to assume the content is the same - even though its "quick check" fails - and just update the permissions and timestamp:
rsync -avP --existing --size-only /path/to/server/source /path/to/target
The --existing flag ensures that no new files are created in the target location, but that existing files are updated appropriately. The --size-only flag forces rsync to ignore timestamps.
| Can rsync fix time stamps without redownloading? |
1,434,136,955,000 |
I have set of linux folders and I need to get the permissions of the folders numerically.
For example in the below directory, I need to what is the permission value of the folder... Whether 755, 644 or 622 etc...
drwxrwsr-x 2 dev puser 4096 Jul 7 2014 fonts
|
To get the octal permission notation.
stat -c "%a" file
644
See the manpage of stat, -c specifies the format and %a prints the permissions in octal.
Or for multiple files and folders:
stat -c "%a %n" *
755 dir
644 file1
600 file2
| How to get file permission in octal [duplicate] |
1,434,136,955,000 |
I'm backing up servers on a backup server. Each server which is backed up has it's own account on the backup server, and the files are rsynced. It is important that the permissions remain intact (using rsync -p) to simplify restores.
I'm trying to create a script which can read the files and create some statistics. I don't like that script to be running under the root user, and it it also impossible to run it for every backup user, as the script should be able to read all files from all users. However, this creates a problem when a file is for example chmodded 600. I don't want to touch permissions, but another user except for root and the owner can't read it.
A specific - non root - user should be able to read all files in a directory or partition, regardless the permission levels (and the owner of the files should have no way to prevent it). Is there a way to achieve this? I'm running FreeBSD with a ZFS volume.
|
Use sudo.
If your sudoers file lists an exact and specific command then the command must be called exactly as listed in the sudoers or it will be denied.
E.g.:
backupuser ALL=(root) /usr/bin/rsync -aH /files/to/backup/ /copy/of/backup/
In this example the user backup can execute the command exactly as shown:
sudo /usr/bin/rsync -aH /files/to/backup/ /copy/of/backup/
If they call sudo rsync... instead of sudo /usr/bin/rsync the command fails, or if the flags or paths are different the command fails.
If you're doing this in a script then you want to enable passwordless use of those commands:
backupuser ALL=(root) NOPASSWD: /usr/bin/rsync -aH /files/to/backup/ /copy/of/backup/
For more see the sudoers(5) man page under Cmnd_list.
| Read files owned by another user as non-root |
1,434,136,955,000 |
I downloaded a .pem file and my Mac OS X (10.8.2) added an @ sign at the end of the file permissions. This is causing file permission issues. I can't seem to remove the quarantine flag. I even tried the command
xattr -d <filename>.pem
but that didn't work
|
xattr -d requires you to specify which attribute you want to remove. You can find this out by listing the file attributes by passing ls the -@ flag as in:
ls -l@ filename
Once you know what the attribute is, you can target it for removal with -d or you can use the following to clear all attributes:
xattr -c filename
| how to remove quarantine from file permissions in os x |
1,434,136,955,000 |
I host my own git repository on a VPS. Let's say my user is john.
I'm using the ssh protocol to access my git repository, so my url is something like ssh://[email protected]/path/to/git/myrepo/.
Root is the owner of everything that's under /path/to/git
I'm attempting to give read/write access to john to everything which is under /path/to/git/myrepo
I've tried both chmod and setfacl to control access, but both fail the same way: they apply rights recursively (with the right options) to all the current existing subdirectories of /path/to/git/myrepo, but as soon as a new directory is created, my user can not write in the new directory.
I know that there are hooks in git that would allow me to reapply the rights after each commit, but I'm starting to think that I'm going the wrong way because this seems too complicated for a very basic purpose.
Q: How should I set up my right to give rw access to john to anything under /path/to/git/myrepo and make it resilient to tree structure change?
Q2: If I should take a step back change the general approach, please tell me.
Edit: The question was answered as is, but that was the wrong question. The right question would have been "How to configure a bare git repository on the server for use with ssh access?". See my own answer.
|
create a group myrepousers for example, and add your git users to that group.
Then change the group of everything under /path/to/git/myrepo to myrepousers:
chown -R .myrepousers /path/to/git/myrepo
Then fix the permissions:
chmod -R g+w /path/to/git/myrepo
find /path/to/git/myrepo -type d -exec chmod g+s {} \;
Should be all set.
| How to grant read/write to specific user in any existent or future subdirectory of a given directory? |
1,434,136,955,000 |
New on the job, small place, and the security stuff just landed on my desk. I was hired to be a front-end developer. Happy to learn new things, but never had to do sysadmin stuff before.
I started digging and it appears that apache, the site, and everything is running on root. There are no other groups or users. ACK!
What steps should I take to change this? I know that this is a big no-no...
Bonus points if anyone can please point me to a good basic 101 tutorial on apache/php security.
|
It is unusual to find Apache running as root in any stock configuration. How have you determined that Apache is running as root? Note that Apache must start up as root in order to bind to privileged ports, but typically sheds its privileges later on.
You can look in your Apache configuration (often in /etc/httpd or /etc/apache2, depending on your distribution) for the User and Group directives (documented here). These two directives control under what user id Apache runs.
It is also unusual to find a system that has "no other groups or users". What do getent passwd and getent group show? Are there really no other users or groups other than root? Most distributions ship with an apache or www-data user or somesuch and a matching configuration that will run Apache as that user.
There are a variety of introductory guides out there to Apache configuration and security. A simple Google search yields many likely looking results. The RedHat/CentOS Deployment Guide is a good place to start (if you're on a RedHat/CentOS system).
| How do I stop Apache from running as root? |
1,434,136,955,000 |
It's a well-known fact that if one wants to execute a script in shell, then the script needs to have execute permissions:
$ ls -l
total 4
-rw-r--r-- 1 user user 19 Mar 14 01:08 hw
$ ./hw
bash: ./hw: Permission denied
$ /home/user/hw
bash: /home/user/hw: Permission denied
$
However, it is possible to execute this script with bash <scriptname>, sh <scriptname>, etc:
$ bash hw
Hello, World!
$
This means that basically one can execute a script file, even if it only has read permissions. This maybe is a silly question, but what is the point of giving execute permissions to a script file? Is it solely because in order for a program to run it needs to have execute permissions, but it actually doesn't add security or any other benefits?
|
Yes, you can use bash /path/to/script, but scripts can have different interpreters. Its possible your script was written to work with ksh, zsh, or maybe even awk or expect. Thus you have to know what interpreter to use to call the script with. By instead making a script with a shebang line (that #!/bin/bash at the top) executable, the user no longer needs to know what interpreter to use.
It also allows you to put the script in $PATH and call it like a normal program.
| reason to add execute permissions to a shell script |
1,434,136,955,000 |
Normally only root can access /etc/shadow. But programs like su and sudo can check passwords without running as root. So the question is: Why can these programs access /etc/shadow without privileges? I tried to access it without privileges via python with the spwd module, but I didn't get access (like expected). Which mechanism do these programs use?
|
why have programs like su access to /etc/shadow
Because programs like su and passwd have set SetUID. You can check by using :
[root@tpserver tmp]# ls -l /usr/bin/passwd
-r-s--x--x 1 root root 21200 Aug 22 2013 /usr/bin/passwd
When you look around in your file permission you will see "s". If anybody is trying to run the passwd program, by default it's taking the privilege of owner (root here) of the file. This means any user can get root privilege to execute the passwd program, because only the root user can edit or update /etc/passwd and /etc/shadow file. Other users cant. When the normal user runs the passwd program on his terminal, the passwd program is run as "root", because the effective UID is set to "root". So the normal user can easily update the file.
You can use the chmod command with the u+s or g+s arguments to set the setuid and setgid bits on an executable file, respectively
Long Answer : Set-User_Id (SUID): Power for a Moment:
By default, when a user executes a file, the process which results in
this execution has the same permissions as those of the user. In fact,
the process inherits his default group and user identification.
If you set the SUID attribute on an executable file, the process resulting in its execution doesn't use the user's identification but the user identification of the file owner.
The SUID mechanism, invented by Dennis Ritchie, is a potential security hazard. It lets a user acquire hidden powers by running such a file owned by root.
$ ls -l /etc/passwd /etc/shadow /usr/bin/passwd
-rw-r--r-- 1 root root 2232 Mar 15 00:26 /etc/passwd
-r-------- 1 root root 1447 Mar 19 19:01 /etc/shadow
The listing shows that passwd is readable by all, but shadow is unreadable by group and others. When a user running the program belongs to one of these two categories (probably, others), so access fails in the read test on shadow. Suppose normal user wants to change his password. How can he do that? He can do that by running /usr/bin/passwd. Many UNIX/Linux programs have a special permission mode that lets users update sensitive system files –like /etc/shadow --something they can't do directly with an editor. This is true of the passwd program.
$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 22984 Jan 6 2007 /usr/bin/passwd
The s letter in the user category of the permission field represents a special mode known as the set-user-id (SUID). This mode lets a process have the privileges of the owner of the file during the instance of the program. Thus when a non privileged user executes passwd, the effective UID of the process is not the user's, but of root's – the owner of the program. This SUID privilege is then used by passwd to edit /etc/shadow.
Reference Link
| why have programs like su access to /etc/shadow |
1,434,136,955,000 |
Reading mod_wsgi's documentation I found you can choose which group to run the worker processes as.
I can understand group ownership of files and how only a user who belongs to that group can achieve the group permissions of that file, but I don't understand how this applies to running processes.
So, what is a process GID and what purpose does it serve?
|
It really comes down to what makes up a process in Unix. A process can come into existence in one of 2 ways. Either via the fork() function or through one of the exec() functions in C.
fork()
fork() basically just makes a copy of the current process, but assigns it a new process ID (PID). It's a child of the original process. You can see this relationship in the output of ps:
$ ps axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 5255 1964 1964 ? -1 Sl 500 0:39 gnome-terminal
5255 5259 1964 1964 ? -1 S 500 0:00 \_ gnome-pty-helper
5255 18422 18422 18422 pts/1 18422 Ss+ 500 0:01 \_ bash
5255 30473 30473 30473 pts/4 30473 Ss+ 500 0:00 \_ bash
30473 782 782 30473 pts/4 30473 Sl 500 1:14 | \_ evince s.pdf
Here you can see that gnome-terminal is the parent process (PID = 5255) and that bash is it's child (PID = 18422, PPID = 5255).
NOTE: PPID = Parent Process ID.
When a process forks from its parent, it "inherits" certain things, such as copies of all the file descriptors that the parent currently has for open files and the parent's user and group IDs.
NOTE: The last 2 are what identify what file and group permissions this process will have when accessing the file system.
So if a process just inherits its user and group ID from its parent, then why isn't everything just owned by root or a single user? This is where exec() comes in.
exec() Part #1
The exec() family of functions, specifically execve(), "replace" a current process image with a new process image. The terminology "process image" is really just a file, i.e. an executable on disk. So this is how a bash script can execute a program such as /usr/bin/time.
So what about the user ID and group ID? Well to understand that let's first discuss the concept of "Persona".
Persona
At any time, each process has an effective user ID, an effective group ID, and a set of supplementary group IDs. These IDs determine the privileges of the process. They are collectively called the persona of the process, because they determine "who it is" for purposes of access control.
exec() Part #2
So in addition to being able to swap out the "process image", exec() can also change the user & group IDs from the original "real" ones to "effective" ones.
An example
For this demonstration I'm going to show you what happens when we start out in a shell as our default UID/GID, and then spawn a child shell using one of my supplementary GIDs, making it the child shell's effective GID.
To perform this I'm going to make use of the unix command newgrp. newgrp allows you to spawn a new shell passing it the supplementary group that I'd like to make my effective GID.
For starters:
$ id -a
uid=500(saml) gid=501(saml) groups=501(saml),502(vboxusers),503(jupiter)
We can see that this shell is currently configured with my default UID/GID of saml & saml. Touching some files shows that this is the case as well:
$ touch afile1
$ touch afile2
$ ls -l
total 0
-rw-rw-r-- 1 saml saml 0 May 21 23:47 afile1
-rw-rw-r-- 1 saml saml 0 May 21 23:47 afile2
Now we make our supplementary group jupiter the effective GID:
$ newgrp jupiter
$ id -a
uid=500(saml) gid=503(jupiter) groups=501(saml),502(vboxusers),503(jupiter)
Now if we touch some files:
$ touch afile3
$ touch afile4
$ ls -l
total 0
-rw-rw-r-- 1 saml saml 0 May 21 23:47 afile1
-rw-rw-r-- 1 saml saml 0 May 21 23:47 afile2
-rw-r--r-- 1 saml jupiter 0 May 21 23:49 afile3
-rw-r--r-- 1 saml jupiter 0 May 21 23:49 afile4
We see that the shell's effective GID is jupiter, so any interactions with the disk result in files being created with jupiter rather than my normal default group of saml.
References
fork() man page
exec() man page
execve() man page
credentials man page
newgrp man page
The GNU C Library
The GNU C Library - 26.4 Creating a Process
The GNU C Library - 26.5 Executing a File
GID, current, primary, supplementary, effective and real group IDs?
| What is a process GID and what purpose does it serve? |
1,434,136,955,000 |
I have the following problem: On every machine running Postgresql there is a special user postgres. This user has administrative access to the database server.
Now I want to write a Bash script that executes a database command with psql as user postgres (psql shall execute as user postgres, not the script). So far, that wouldn't be a problem: I could just run the script as user postgres.
However, I want to write the output of psql to a file in a directory where postgres has no write access.
How can I do that?
I thought about changing EUIDs in the script itself, however:
I couldn't find a way to change the EUID in a Bash script
How can I change the EUID when using something like
psql -U postgres -c "<command>" > file?
|
Use a subshell: (su -c 'psql -U postgres -c "<command>"' postgres) > file
Inside the subshell you can drop permissions to do your work, but output is redirected to your original shell which still has your original permissions.
| How to run part of a script with reduced privileges? |
1,434,136,955,000 |
User has write-only permissions on a file, unable to cat or vi but is able to nano normally. How is this possible?
I was wondering what happens if you only have write-access on a file and this was how I tested it.
# cd /home/tester
# cat hello.txt
Hello World!
# ls -l hello.txt
-rw------- 1 root root 13 Nov 17 01:55 hello.txt
# chmod o+w hello.txt
# ls -l hello.txt
-rw-----w- 1 root root 13 Nov 17 01:55 hello.txt
# su tester
$ cd ~
$ cat hello.txt
cat: hello.txt: Permission denied
$ nano hello.txt
For some reason, nano is able to read the file (see screenshot). I've confirmed vi is not. My original hypothesis is that having write only permission allows you to only append the file like echo "Hello" > hello.txt.
(See this screenshot for the actual commands I ran.)
Update
ls -l "$(type -p nano)" shows permissions -rwsr-xr-x root root.
|
-rwsr-xr-x root root in the result of ls -l "$(type -p nano)" means it is setuid. As a result, whoever runs nano has root privileges. This is not expected and shouldn't be happening in any normal environment. Find out with your administrator what the point is.
| Nano able to read on write-only access file |
1,434,136,955,000 |
If the group of /some/dir is foo, and I run
chmod g+s /some/dir
...then any child of /some/dir will also have group foo.
Crucially, however, a new subdirectory /some/dir/subdir will not have g+s (although, as just stated, it its group will be foo).
How can I ensure that all descendant subdirectories of /some/dir not only inherit the group foo, but also inherit the g+s permission?
FWIW, my umask is 002, the filesystem is nfs, and the options according to mount are (rw,relatime,vers=3,rsize=20961,wsize=413177,namlen=255,hard,proto=tcp,timeo=450,retrans=2,sec=sys,mountaddr=xxx.xxx.xxx.xxx,mountvers=3,mountport=333,mountproto=udp,local_lock=none,addr=xxx.xxx.xxx.xxx).
UPDATE: I now understand the source of my confusion: sometimes changing a directory's group (with chgrp) has the effect of disabling a previously enabled setgid bit. E.g.
% rm -rf /some/dir
% mkdir -p /some/dir
% chmod g+s /some/dir
% ls -ld /some/dir
drwxrwsr-x 2 jones jones 0 Nov 7 07:13 /some/dir
% chgrp foo /some/dir
% ls -ld /some/dir
drwxrwxr-x 2 jones jones 0 Nov 7 07:13 /some/dir
(Note that the setgid bit ends up unset.)
As I said, this happens only sometimes. For example, if I repeat the same sequence above, but I run the chgrp command under sudo, then the setgid bit remains set at the end.
This effect of chgrp on the permissions is what threw me off.
|
Once /some/dir has the setgid bit, new subdirectories do inherit it, so all newly-created descendents have the appropriate group and setgid bit.
Using chgrp can drop the setgid bit. POSIX says
Unless chgrp is invoked by a process with appropriate privileges, the set-user-ID and set-group-ID bits of a regular file shall be cleared upon successful completion; the set-user-ID and set-group-ID bits of other file types may be cleared.
| How to ensure all new subdirectories (and sub-subdirectories, etc.) have g+s? |
1,434,136,955,000 |
Long story short, I destroyed /var and restored it from backup - but the backup didn't have correct permissions set, and now everything in /var is owned by root. This seems to make a few programs unhappy.
I've since fixed apt failing fopen on /var/cache/man as advised here as well as apache2 failing to start (by giving ownership of /var/lib/apache2 to www-data). However, right now the only way to fix everything seems to be to manually muck around with permissions as problems arise - this seems very difficult as I would have to wait for a program to start giving problems, establish that the problem is related to permissions of some files in /var and then set them right myself.
Is there an easy way to correct this? I already tried reinstalling (plain aptitude reinstall x) every package that was listed in dpkg -S /var, but that didn't work.
|
Actually apt-get --reinstall install package should work, with files at least:
➜ ~ ls -l /usr/share/lintian/checks/version-substvars.desc
-rw-r--r-- 1 root root 2441 Jun 22 14:19 /usr/share/lintian/checks/version-substvars.desc
➜ ~ sudo chmod +x /usr/share/lintian/checks/version-substvars.desc
➜ ~ ls -l /usr/share/lintian/checks/version-substvars.desc
-rwxr-xr-x 1 root root 2441 Jun 22 14:19 /usr/share/lintian/checks/version-substvars.desc
➜ ~ sudo apt-get --reinstall install lintian
(Reading database ... 291736 files and directories currently installed.)
Preparing to unpack .../lintian_2.5.27_all.deb ...
Unpacking lintian (2.5.27) over (2.5.27) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up lintian (2.5.27) ...
➜ ~ ls -l /usr/share/lintian/checks/version-substvars.desc
-rw-r--r-- 1 root root 2441 Jun 22 14:19 /usr/share/lintian/checks/version-substvars.desc
Now, you probably didn't get all the packages that have files on your /var directory, so its better to find them all:
➜ ~ find /var -exec dpkg -S {} + 2> /dev/null | grep -v "no path found" | wc -l
460
In my case, it accounts for 460 paths that have a package, this is actually less if you consider that the same package can have several paths, which with some post processing we can find out that are ~122:
➜ ~ find /var -exec dpkg -S {} + 2> /dev/null | grep -v "no path found" | cut -d : -f 1 | sort | uniq | wc -l
122
This of course counts several package that has the same path, like wamerican, aspell-en, ispanish, wspanish, aspell-es, myspell-es. This is easily fixable:
➜ ~ find /var -exec dpkg -S {} + 2> /dev/null | grep -v "no path found" | cut -d : -f 1 | sed 's/, /\n/g' | sort | uniq | wc -l
107
So, I have 107 package that have any kind of file in /var or subdirectories. You can reinstall them using:
sudo apt-get --reinstall install $(find /var -exec dpkg -S {} + 2> /dev/null | grep -v "no path found" | cut -d : -f 1 | sed 's/, /\n/g')
This should fix the permissions.
Now, there's another option, find a good installation and copy the file permissions over your installation with:
chmod --recursive --reference good/var bad/var
| Fix broken permissions on /var (or any other system directory) |
1,434,136,955,000 |
Is it possible to represent the +X symbolic permission with an octal value? The chmod(1) man page says:
execute/search only if the file is a directory or already has execute permission for some user
which means that chmod -R g+X will add the group execute permission only if there's already an execute bit set for user, group, or other. You could certainly do this the hard way with find:
find . -perm /ugo=x -exec chmod g+x {} \;
However, it's not obvious how one could do the same thing with an octal mode without using find or test to check the file permissions first. Is this possible, or are there some areas where symbolic and octal permissions just don't overlap?
|
The short story: it's not possible, no.
The longer story: octal permissions are states. The [+-][rwxXst] notation represents operations that culminate in changing states. Note, not the =[rwxXst] one, which sets state and is equivalent to the octal modes as Gilles said. The X one is the only conditional operation, the other ones are all unconditional.
When you chmod a file with octal permissions, you supply the final state of the permission bits verbatim. When you use the operations, you choose what you want done to the permission bits.
Your question is tantamount to asking if there's a single number that represents all square roots. The answers is obviously ‘no’: every square root yields a number (pedants: though it could be imaginary/irrational), but without the starting state (the number), you can't tell which.
| Is it possible to represent the +X symbolic permission with an octal value? |
1,434,136,955,000 |
I would like to allow a specific user to be able to sudo /sbin/iptables only.
I have a bash script which configures iptables. The problem is that configuring /sbin/iptables as sudoable is not enough - The script itself also has to be sudoable.
The problem is that that file could be edited by the user (he may change configurations there), giving him the ability to run any command as root.
What is the proper approach to this problem?
|
I can see two methods:
Allow the user to use /sbin/iptables through sudo without restriction (which is something dangerous, this means you trust the user somehow), and run the script with the permissions of the user. The script will invoke sudo each time /sbin/iptables is needed. This is assuming the script execution will be quick, since some password input will eventually be required at regular intervals¹.
Advantage: you don't need to have any trust in the script.
Disadvantage: as already mentioned, allowing the user to use /sbin/iptables without restriction is something dangerous.
Allow the user to call only the script through sudo.
Advantage: the use of /sbin/iptables is restricted by the script.
Disadvantage: the script must be flawless.
About the problem you mentioned: if the script is owned by let's say root and has usual permissions: rwxr-xr-x, others users cannot modify it, they can only execute it (eventually through sudo to obtain more privileges).
With solution 2, and in the case of shell scripts (compared to more robust binaries/programs), beware of environment variables and the several external factors that can modify the execution of your script. Check that your sudo configuration resets properly the definition of every potentially harmful variable.
—
1. In fact, sudo can be configured with NOPASSWD if needed.
| Allow users to run only specific binaries with root permissions/privileges |
1,434,136,955,000 |
I have a bash script that needs to run with root privileges, but must be invoked by the normal user.
Difficult part is that the script should not ask for a password, and I don't want to use the sudoers file. I'd like to avoid using sudo or su.
Is this possible?
|
If it wasn't a bash script but a regular application, you would give ownership of it to root and set the setuid bit on the application. Then upon execution, the effective user the application is running under is root. Due to security concerns however this is in many systems prohibited for shell scripts. This question here on unix.stackexchange.com does handle ways how to overcome this.
| How to get a program running with root privileges without using su or sudo |
1,434,136,955,000 |
I have 2 users in my machine: linuxlite and otheruser.
otheruser has a file:
otheruser@linuxlite:~$ ls -l a
-rw-rw-r-- 1 otheruser otheruser 6 Mar 31 12:47 a
otheruser@linuxlite:~$ cat a
hello
linuxlite made a file and a symlink in /tmp:
otheruser@linuxlite:~$ ls -l /tmp/file /tmp/link
-rw-rw-r-- 1 linuxlite linuxlite 3 Mar 31 12:49 /tmp/file
lrwxrwxrwx 1 linuxlite linuxlite 17 Mar 31 12:49 /tmp/link -> /home/otheruser/a
Now, although otheruser can read /tmp/file and /home/otheruser/a, he cannot read /tmp/link:
otheruser@linuxlite:~$ cat /tmp/file
hi
otheruser@linuxlite:~$ cat /home/otheruser/a
hello
otheruser@linuxlite:~$ cat /tmp/link
cat: /tmp/link: Permission denied
My question is, why cannot otheruser read a symlink owned by linuxlite if he can read the target and also another file owned by him in the same directory as the symlink?
If it matters, then the permissions on /tmp are:
otheruser@linuxlite:~$ ls -l -d /tmp
drwxrwxrwt 9 root root 4096 Mar 31 13:17 /tmp
Distribution is Linux Lite 3.0, kernel is: Linux 4.4.0-21.generic (i686)
|
Linux Lite is based on Ubuntu, which restricts symlinks in world-writable sticky directories (including /tmp): symlinks there can only be dereferenced by their owner.
If you create the symlink elsewhere (in /home/linuxlite for example) you’ll be able to dereference it in the way you expect.
(Ubuntu isn’t the only distribution to behave in this way; I mentioned the connection between Linux Lite and Ubuntu because the documentation for this is seemingly Ubuntu-specific.)
| permissions of symlinks inside /tmp |
1,434,136,955,000 |
Can the default permissions and ownership of /sys/class/gpio/ files be set, e.g. by configuring udev? The point would be to have a real gid for processes that can access GPIO pins on a board.
Most "solutions" include suid wrappers, scripts with chown and trusted middleman binaries. Web searches turn up failed attempts to write udev rules.
(related: Q1)
(resources: avrfreaks, linux, udev)
|
The GPIO interface seems to be built for system (uid root) use only and doesn't have the features a /dev interface would for user processes. This includes creation permissions.
In order to allow user processes (including daemons and other system services) access, the permissions need to be granted by a root process at some point. It could be an init script, a middleman, or a manual (sudo) command.
| Set GPIO permissions cleanly |
1,434,136,955,000 |
People around the net are all yelling how insecure it is to have writable root FTP directory, if you configure your FTP server with the chroot option (vsftpd won't even run).
I miss the explanation why is it bad?
Could someone expand a little bit more on that topic and explain what are the dangers, how a chroot directory writable by unprivileged users can be exploited?
|
The attack here is commonly known as the "Roaring Beast" attack; you can read more about it in these bulletins:
https://www.auscert.org.au/bulletins/15286/
https://www.auscert.org.au/bulletins/15526/
In order to use the chroot(2) function, the FTP server must have root privileges. Later, the unprivileged client requests the creation of files within /etc (or /lib) within that chrooted server process. These directories usually contain dynamically loaded libraries and configuration for system libraries like the DNS resolver, user/group name discovery, etc. The client-created files are not in the real /etc/ and /lib directories on the system -- but within the chroot, these client-created files are real.
So the malicious client connects to an FTP server which chroots their process, they create the necessary /lib and /etc directories/files within that chroot, upload a malicious copy of some dynamic libraries, and then ask the server to perform some action that triggers the use of their new dynamic libraries (usually just a directory listing, which leads to using the system functions for user/group discovery, etc). The server process runs that malicious libraries, and because the server might still have root privileges, that malicious library code can then have extra access to do whatever it wants.
Note that /etc and /lib are not the only directories to watch; the issue is more about the assumptions made by system libraries about their file locations in general. Thus different platforms may have other directories to guard.
ProFTPD, for example, now bars the creation of such /etc/ and /lib directories when chrooted, to mitigate such attacks.
| What are the dangers of having writable chroot directory for FTP? |
1,434,136,955,000 |
I'm working with a fresh install of Ubuntu 12.04 and I've just added a new user:
useradd -m testuser
I thought that the -m flag to create a home directory for users was pretty standard, but now that I've taken a closer look I'm a little confused:
By default the new directory that was just created shows up as:
drwxr-xr-x 4 testuser testuser 4.0K May 20 20:24 testuser
With the g+r and o+r permissions that means every other user on the system can not only cd to that user's home directory, but also see what is stored there.
When reading over some documentation for suPHP it recommends setting the permissions as 711 or drwx--x--x which is how it would make the most sense to me.
I noticed that I can change the permissions on the files inside /etc/skel and they are set correctly when creating new users with useradd -m but changing the permissions on the /etc/skel directory itself does not seem to have any effect on the new directories that are created for users in /home/
So - what type of permissions should a user's home directory and files have - and why?
If I wanted permissions to be different for useradd -m - like the 711 / drwx--x--x as I saw mentioned, how is one to do that? Must you create the user and then run chmod ?
|
To make the creation of the home directory behave differently do
useradd -m -K UMASK=0066 testuser
Giving other no access at all should be safe.
| What type of permissions should a user's home directory and files have? |
1,434,136,955,000 |
Possible Duplicate:
Make all new files in a directory accessible to a group
I have a directory in which collaborative files / directories are stored. Say directory abc is owned by root and the group is project-abc. I'd like for this directory to have the following:
Only members of group project-abc are allowed to change the contents of this directory.
Files added to abc must have read and write permissions set for members or group abc
Directories added must have read, write and execute permissions for group abc
This is straightforward for static directories, but the contents of this directory are expected to change quite often. What's my best approach to producing the desired result?
|
The best thing you can do is to add the setgid bit (chmod g+s) to your directories. See Directory Setuid and Setgid in the coreutils manual. New directories will then preserve group ownership.
As for permissions, the best you can do is make sure umask 002 is in use every time someone works inside this directory.
(Yes, basic unix-style permissions are too basic sometimes… I don't know if ACLs can make collaborative work inside a directory easier. If they are activated in your system, you might have a look.)
| How do I set permissions for a directory so that files and directories created under it maintain group write permissions? [duplicate] |
1,434,136,955,000 |
Suppose User A and User B have disk quotas of 1 GB.
Also suppose User B creates a 900 MB file with permission 0666.
This allows User A to access that file temporarily (for some project, etc.).
Notice this allows User A to write to the file as well.
If User A creates a hard link to that file, and User B then deletes the file, has User A essentially exploited the quota system by "stealing" 900 MB of storage from User B?
Assume User B never reports this to the admin, and the admin never finds out.
Also assume User B never suspects a thing about User A. In other words, assume User B will not look at User A's directory and corresponding files.
If similar question has been asked/answered before, I apologize for not being able to find them.
|
This is one of the ugly corner cases of the Unix permission model. Granting write access to a file permits hard-linking it. If user A has write permission to the directory containing the file, they can move it to a directory where user B has no access. User B then can't access the file anymore, but it still counts against user B for quota purposes.
Some older Unix systems had a worse hole: a user could call chown to grant one of their file to another user; if they'd made the file world-writable before, they could keep using that file but the file would count against the other user's quota. This is one reason modern systems reserve chown to root.
There is no purely technical solution. It's up to user B to notice that their disk usage (du ~) doesn't match their quota usage and complain to the system administartor, who'll investigate and castigate user A.
| Hard Linking Other Users' Files |
1,434,136,955,000 |
I downloaded and saved 2 files on Linux tails live os. I have set the appropriate permissions on those 2 files to allow them as executable. This is the command I used.
sudo chmod 777 home/amnesia/Desktop/file
sudo chmod 777 file
However, when I try to access these 2 files, both the files yield me an error as cannot access.
I am not sure why it isn't recognizing the file permissions correctly.
|
this to:
sudo chmod 777 home/amnesia/Desktop/file
this:
sudo chmod 777 /home/amnesia/Desktop/file
you left a '/' slash
better to use will be:
sudo chmod 777 ~/Desktop/file
| chmod: cannot access 'file' : No such file or directory error when the file exists |
1,434,136,955,000 |
Currently setting up xpra, which wants to run an X instance as non-root using the dummy driver, but the system Xorg binary is SUID. Since the system auto-updates, I would prefer not making and maintaining a non-SUID copy of the binary. I'm also trying to avoid using a hack like copy-execute-delete, e.g. in the tmp directory (would prefer to make it a clean one-liner, which I instinctively believe should be possible, though there may be some subtle security hole this capability would open). Symlinks would be acceptable, though AFAIK they don't provide permission bit masking capabilities.
My current best solution is a nosuid bind mount on the bin directory, which seems to do the trick, but as above I'd still prefer a solution that doesn't leave crunk in my system tree/fstab (e.g. some magic environment variable that disables suid the same way a nosuid mount does, or some commandline execute jutsu that bypasses the suid mechanism).
Any thoughts?
|
If X is dynamically linked, you could call the dynamic linker like:
/lib/ld.so /path/to/X
(adapt ld.so to your system (like /lib/ld-linux.so.2).
Example:
$ /lib64/ld-linux-x86-64.so.2 /bin/ping localhost
ping: icmp open socket: Operation not permitted
| Running setuid binary temporarily without setuid? |
1,309,376,541,000 |
I have been told that noexec is a standard setting for /home folder for development environments. Can someone provide some references?
Using noexec on /home prevents applications like IDEs, editors, etc. from working properly as expected.
|
I have been told that noexec is a standard setting for /home folder for development environments.
That's an opinion I've not seen anywhere else ever.
No, there's nothing "standard" about it. Standards imply standardization and I've not seen ISO standards or RFCs talking about any flags specific to /home.
In fact most Linux distros don't even (offer to) allocate /home as a separate partition and if it's not then you cannot use any specific mount options with it.
| Is noexec a standard setting for home? |
1,309,376,541,000 |
I am trying to get the size of an user's folder named allysek and I am using this command du -hLlxcs allysek. I know I don't have permissions to some of the locations.
In the end, I get an output as follows,
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-mjyger/PS-NOVA/IMR90.NOMe-seq.bam’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-mfter/PS-NOVA/IMR90.NOMe-seq.bam.bai’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-iuhgi/PS-NOVA/colon.WGBS.bam’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-kh/PS-NOVA/colon.WGBS.bam.bai’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-h/PS-NOVA/dbNOVA_135.hg19.sort.vcf’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-master/PS-NOVA/hg19_rCRSchrm.fa’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-master/PS-plot/DKO1.NOMe-seq.bam’
du: cannot access ‘/export/mite-09/bc/users/allysek/charlet/PS-tools-master/PS-plot/DKO1.NOMe-seq.bam.bai’
896M /export/mite-09/bc/users/allysek
896M total
So my question is, does the 896M total include sizes of items which I wasn't able to access as well?
|
Simply not.
Look this example
du -shc *
4,0K AUDIO_TS
4,4G VIDEO_TS
4,4G total
chmod 000 * #don't use this in wrong dir!
du -shc *
du: cannot read directory 'VIDEO_TS': Permission denied
du: cannot read directory 'AUDIO_TS': Permission denied
4,0K AUDIO_TS
4,0K VIDEO_TS
8,0K total
| Does 'du' command count the size of unaccessible folders? |
1,309,376,541,000 |
In the following situation ls -alh
total 0
drwxrwx--- 1 user http 20 Nov 30 08:08 .
drwxrws--- 1 user http 310 Nov 30 08:07 ..
drwx------ 1 http http 10 Nov 30 08:08 empty-subdir
drwx------ 1 http http 12 Nov 30 08:08 non-empty-subdir
where two subdirectories (not owned by me) exist, which I list as:
sudo ls empty-subdir -alh
total 0
drwx------ 1 http http 10 Nov 30 08:08 .
drwxrwx--- 1 user http 20 Nov 30 08:08 ..
sudo ls non-empty-subdir -alh
total 0
drwx------ 1 http http 12 Nov 30 08:08 .
drwxrwx--- 1 user http 20 Nov 30 08:08 ..
drwx------ 1 http http 0 Nov 30 08:08 subdir
The difference between the two subdirectories being that the non-empty non-empty-subdir contains a folder.
My question is whether it is by design that trying to rm -rf remove the subdirectories I get results:
$ rm empty-subdir -rf
$ rm non-empty-subdir -rf
rm: cannot remove 'non-empty-subdir': Permission denied
$ ls -alh
total 0
drwxrwx---+ 1 user http 10 Nov 30 08:14 .
drwxrws---+ 1 user http 310 Nov 30 08:07 ..
drwx------+ 1 http http 12 Nov 30 08:08 non-empty-subdir
It seems that the user with write permissions to a directory is allowed to remove an entry for a file, or an empty subdirectory of some other user, but not a non-empty subdirectory.
An ideal answer to this question would provide information such as:
a confirmation that the outlined behaviour is reproducible on other machines (and not mere quirks of my screwed up box)
a rationale to explain that behaviour (e.g. are there use cases?)
an overview if there are differences between systems (BSD, Linux....)
Update:
With respect to the comment by Ipor Sircer, I did retest the scenario, without any ACL features and it is the same. I therefore modified the question to remove the +es from the listings as not to give rise to an idea that the behaviour mightbe related to ACLs.
|
One can only remove a directory (with the rmdir() system call) if it's empty.
rm -r dir removes the directory and all the files in it, starting with the leaves of the directory tree and walking its way up to the root (dir).
To remove a file (with rmdir() for directories and unlink() for other types of files, or *at() variants), what matters it not the permission of the file itself but those of the directory you're removing the file from (beware the t bit in the permissions, like for /tmp, adds further complications to that).
Before all, you're not really removing the file, you're unlinking it from a directory (and when it's the last link that you're removing, the file ends up being deleted as a consequence), that is, you're modifying the directory, so you need modifying (write) permissions to that directory.
The reason you can't remove non-empty-dir is that you can't unlink subdir from it first, as you don't have the right to modify non-empty-dir. You would have the right to unlink non-empty-dir from your home directory as you have write/modification permission to that one, only you can't remove a directory that is not empty.
In your case, as noted by @PeterCordes in comments, the rmdir() system call fails with a ENOTEMPTY (Directory not empty) error code, but since you don't have read permission to the directory, rm cannot even find out which files and directories (including subdir) it would need to unlink from it to be able to empty it (not that it could unlink them if it knew, as it doesn't have write permissions).
You can also get into situations where rm could remove a directory if only it could find out which files are in it, like in the case of a write-only directory:
$ mkdir dir
$ touch dir/file
$ chmod a=,u=wx dir
$ ls -ld dir
d-wx------ 2 me me 4096 Nov 30 19:43 dir/
$ rm -rf dir
rm: cannot remove 'dir': Permission denied
Still, I am able to remove it as I happen to know it only contains one file file:
$ rm dir/file
$ rmdir dir
$
Also note that with modern Unices you could rename that non-empty-dir, but on some like Linux or FreeBSD (but not Solaris), not move it to a different directory, even if you also had write permission to that directory, as (I think and for Linux, as suggested by the comment for the relevant code) doing so would involve modifying non-empty-dir (the .. entry in it would point to a different directory).
One could argue that removing your empty-dir also involves removing the .. and . entries in it, so modifying it, but still, the system lets you do that.
| Are another user's non-empty subdirectories safe from deletion in my directory? |
1,309,376,541,000 |
I have written a bash script for use on my ubuntu box. Now I would like to prevent running this script under my own user and only able to run it as root (sudo).
Is there a possibility to force this. Can I somehow let my script ask for root permissions if I run it under my own username?
|
I have a standard function I use in bash for this very purpose:
# Check if we're root and re-execute if we're not.
rootcheck () {
if [ $(id -u) != "0" ]
then
sudo "$0" "$@" # Modified as suggested below.
exit $?
fi
}
There's probably more elegant ways (I wrote this AGES ago!), but this works fine for me.
To use this function consistently in a script, you should pass it the arguments received by the script originally.
Usage: rootcheck "${@}" (rootcheck alone will not pass any arguments to the rootcheck function)
| How do I force the user to become root |
1,309,376,541,000 |
Using chmod I could set the permissions for a file, but if the parent ( .. ) directory had conflicting permissions, what would happen?
And if I create a new file, using touch or something similiar, how are the initial permissions calculated? Are permissions inherited it from ..?
And why can't I do anything in directory when I removed the executable permission flag?
$ mkdir temp;
$ chmod -x temp;
$ touch temp/a;
$ ls temp;
touch: cannot touch `temp/a': Permission denied
|
There is -strictly speaking- no such thing in UNIX as "conflicting permissions": access permissions on an filesystem entry (directory, file, etc.) determine what you can or can not do on that object. Permissions on other filesystem entries do not enter into the picture, with the exception of the "x" bit on all ancestors directories in the path to a file (up to /) -- see 3.
The default permission on a newly created file are determined by the permissions that the creating program allows (the mode argument to the open or creat system calls) and the current process umask. Specifically, any bit that is set (1) in the "umask" is reset (0) in the newly-created file permissions: in C-like notation: file_permissions = open_mode & ! umask. Read man 2 creat (look for O_CREAT) and man umask for the details.
The "x" (executable) bit on a directory controls whether you can traverse that directory: traversing a directory means being able to cd into it and access files contained in it. Note that the ability to list the contents of the directory is controlled by the "r" bit.
Further reading:
http://www.hackinglinuxexposed.com/articles/20030417.html on file permissions
http://www.hackinglinuxexposed.com/articles/20030424.html on directory permissions
| How are file permissions calculated? |
1,309,376,541,000 |
Example:
# show starting permissions
% stat -c '%04a' ~/testdir
0700
# change permissions to 2700
% chmod 2700 ~/testdir
# check
% stat -c '%04a' ~/testdir
2700
# so far so good...
# now, change permissions back to 0700
% chmod 0700 ~/testdir
# check
% stat -c '%04a' ~/testdir
2700
# huh???
# try a different tack
% chmod g-w ~/testdir
% stat -c '%04a' ~/testdir
0700
Bug or feature?
Why does chmod 0700 ~/testdir fail to change the permissions from 2700 to 0700?
I've observed the same behavior in several different filesystems. E.g., in the latest one, the relevant line of mount's output is
/dev/sda5 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
Also, FWIW
% stat -c '%04a' ~/
0755
|
Assuming you’re using GNU chmod, this is documented in the manpage:
chmod preserves a directory's set-user-ID and set-group-ID bits unless you explicitly specify otherwise.
You can set or clear the bits with symbolic modes like u+s and g-s, and you can set (but not clear) the
bits with a numeric mode.
This is allowed in POSIX:
For each bit set in the octal number, the corresponding file permission bit shown in the following table shall be set; all other file permission bits shall be cleared. For regular files, for each bit set in the octal number corresponding to the set-user-ID-on-execution or the set-group-ID-on-execution, bits shown in the following table shall be set; if these bits are not set in the octal number, they are cleared. For other file types, it is implementation-defined whether or not requests to set or clear the set-user-ID-on-execution or set-group-ID-on-execution bits are honored.
The reasoning for the behaviour in GNU chmod is given in the release notes for coreutils 6.0:
chmod, install, and mkdir now preserve a directory's set-user-ID and
set-group-ID bits unless you explicitly request otherwise. E.g.,
chmod 755 DIR and chmod u=rwx,go=rx DIR now preserve DIR's
set-user-ID and set-group-ID bits instead of clearing them, and
similarly for mkdir -m 755 DIR and mkdir -m u=rwx,go=rx DIR. To
clear the bits, mention them explicitly in a symbolic mode, e.g.,
mkdir -m u=rwx,go=rx,-s DIR. To set them, mention them explicitly
in either a symbolic or a numeric mode, e.g., mkdir -m 2755 DIR,
mkdir -m u=rwx,go=rx,g+s DIR. This change is for convenience on
systems where these bits inherit from parents. Unfortunately other
operating systems are not consistent here, and portable scripts
cannot assume the bits are set, cleared, or preserved, even when the
bits are explicitly mentioned. For example, OpenBSD 3.9 mkdir -m 777 D preserves D's setgid bit but chmod 777 D clears it.
Conversely, Solaris 10 mkdir -m 777 D, mkdir -m g-s D, and
chmod 0777 D all preserve D's setgid bit, and you must use
something like chmod g-s D to clear it.
There’s more on the topic in #8391, including the further rationale that the leading 0 is ambiguous (it could indicate either cleared bits, or an octal value, in the user’s mind). The coreutils manual also has a dedicated section, Directories and the Set-User-ID and Set-Group-ID Bits; this reveals that there are GNU extensions to allow clearing the bits in question:
chmod =700 ~/testdir
chmod 00700 ~/testdir
both clear the bits (but are non-portable).
| Permissions remain 2700 after `chmod 0700` |
1,309,376,541,000 |
So there's a user rtorrent:torrent which is in group media-agent.
Here is the command I'm trying to get working:
rtorrent@seedbox:/shared/storage$ cd books
bash: cd: books: Permission denied
Even though the folder has permission 664:
rtorrent@seedbox:/shared/storage$ ls -al
total 44
drwxrwxrwx 11 media-agent media-agent 4096 Aug 15 15:05 .
drwxrwxrwx 8 root root 4096 Aug 15 01:12 ..
drw-rw-r-- 3 media-agent media-agent 4096 Aug 15 15:15 books
drw-rw-r-- 2 media-agent media-agent 4096 Aug 15 15:03 cartoons
drw-rw-r-- 4 media-agent media-agent 4096 Aug 15 01:10 games
drw-rw-r-- 3 media-agent media-agent 4096 Aug 15 00:47 libraries
drw-rw-r-- 5 media-agent media-agent 4096 Aug 12 16:54 media-center
drw-rw-r-- 2 media-agent media-agent 4096 Aug 6 15:31 other
drw-rw-r-- 8 media-agent media-agent 4096 Aug 15 01:10 personnal
drw-rw-r-- 5 media-agent media-agent 4096 Aug 15 01:10 software
drw-rw-r-- 2 media-agent media-agent 4096 Aug 6 18:38 sync
Here is the group setup:
rtorrent@seedbox:/shared/storage$ getent group | grep 'media-agent'
torrent:x:1005:vinz243,www-data,ftpuser,media-agent,nodejs,rtorrent
media-agent:x:1007:vinz243,plex,deluge,rtorrent,root,nodejs
nodejs:x:1008:media-agent
|
To be able to cd into a directory you need x permissions. Your books directory doesn't have that:
drw-rw-r-- 3 media-agent media-agent 4096 Aug 15 15:15 books
Indeed none of those directories have x permissions.
You can recursively fix permissions with something like
find . -type d -exec chmod a+x {} \;
You may need to be the media-agent user (or root) to do that.
| Why can't I access a directory even though I'm in the owner group? [duplicate] |
1,309,376,541,000 |
I have a script that gathers debugging info from the running environment and I need to figure out were I can save that info.
It may be called anytime:
at boot
when the system is running
at shutdown, etc...
and by any user or process / service.
I need a folder that is accessible at all time to EVERYTHING.
Does that exist already? If not how can I make it happen?
Since this is for debugging purposes I don't care about security, it'll all be removed before hitting prod.
|
/tmp, but the data stored there will be deleted upon reboot
| Is there a folder accessible to all process and users at all times? |
1,309,376,541,000 |
EDIT: I believe this is actually a duplicate of https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04
I used the top answer from that page and it worked.
I've just installed a new Linux Mint 18 MATE, and am trying to install Mysql. I did this as follows:
sudo apt-get install mysql-server
which has installed
mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrappe
and this went through a few "gui" screens prompting me for passwords. I just hit enter for each, which I thought was like saying "No password".
But now, I thought i'd be able to get into it with mysql -u root, but it says
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
I tried a reboot just in case. Is the problem that I'm not using the right password, or is it something more fundamental? If it's the password, how to I find out what it is/reset it? Thanks, Max
EDIT: Following f35's answer below, i did the following:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
mysql -u root
then in mysql, i try to change the password but it doesn't recognise the field name: I do a desc to see what is in there:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD("password") where User='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
Not sure what to do next - also, what is the syntax for setting no password? Is it just set password=''?
NOTE: I can also log in with the debian-sys-main user but am still not sure how to change the root user's password.
My mysql version is:
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)
|
1) you can try to reconfigure the mysql-server :
sudo dpkg-reconfigure mysql-server
2) check if you have the debian-sys-maint passwd
cat /etc/mysql/debian.cnf
and check for :
user = debian-sys-maint
password = xxxxGx0fSQxxGa
debian-sys-maint has all privileges on the mysql server
3) if it do not solve the problem, you can reset the passwd :
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NewPasswd") where User='root';
mysql> flush privileges;
mysql> quit
sudo service mysql stop
sudo service mysql start
mysql -u root -p
| After fresh install of mysql-server, can't log in with `mysql root -u` |
1,309,376,541,000 |
lets say we want that only user tutu can read the file
/home/grafh/file.txt
what is the configuration that need to do in order to enable that?
file owner must be stay as root ( and only user tutu can read the file )
|
You have two possibilities, using the the classical DAC (Discretionary Access Control, the usual rwx rights) of using files ACL (Access Control Lists).
Using DAC permissions
If tutu has not its own group (check groups tutu output), you must create a new group and make tutu the only member of this group.
root@host:~# addgroup tutu
root@host:~# usermod -G tutu tutu
Then change the file permissions to allow read access to the members of the tutu group:
root@host:~# chgrp tutu /home/grafh/file.txt
root@host:~# chmod 640 /home/grafh/file.txt
This file will remain owned by root, but be readable (but not writeable) by tutu and not by the other other users.
Using ACL permissions
ACLs are additional rights which come in addition to the DAC permissions seen above. There are meant to solve situation which cannot be easily solved using the historical Unix DAC permission system.
To allow tutu to read the file:
root@host:~# setfacl -m u:tutu:r /home/grafh/file.txt
| Linux + how to give only specific user to read the file |
1,309,376,541,000 |
I'm using a Chromebook and would like to navigate inside the Android container via the shell. The container is mounted at the path /run/containers/android_XXXXX. When trying to cd into the directory, I'm told Permission Denied. I've tried running the command as sudo, but for some reason the cd command becomes inaccessible. I've ran chmod u+x on the directory, but no dice.
What steps can I take from here?
I've ran stat on the directory, which returns the following:
File: ‘android_XXXXXX/’
Size: 80 Blocks: 0 IO Block: 4096 directory
Device: fh/15d Inode: 59640 Links: 3
Access: (0700/drwx------) Uid: (655360/ UNKNOWN) Gid: (655360/ UNKNOWN)
Context: u:object_r:tmpfs:s0
Access: 2016-10-31 04:04:52.680000040 +0000
Modify: 2016-10-31 04:04:52.200000040 +0000
Change: 2016-10-31 04:44:54.990001186 +0000
Birth: -
|
The directory is drwx------ so only someone whose uid is 655350 (which is not listed in the password file) can read it or enter it.
sudo cd not being able to find the cd command is expected, it is a builtin to the shell. If it wasn't builtin then it wouldn't work. Say your current shell has a process ID of 54000, you ran the /bin/cd command, it might be PID 54309. It would change the directory for process 54309, and then exit. process 54000 would still be in its original directory.
chmod u+x alters user (owner) permission.
What you want is sudo chmod go+rx /run/containers/android_XXXXX
| Permission Denied: cd into directory |
1,309,376,541,000 |
This tutorial says the following:
For a directory, write permission allows a user to delete the
directory, modify its contents (create, delete, and rename files in
it), and modify the contents of files that the user can read.
To test this, I created a directory named subdir that doesn't have the w permission bit, and I placed it inside a directory named dir that have the w and the x permission bits set:
d-wx------ 3 robert robert 4096 2017-12-16 9:07 dir
d--------- 3 robert robert 4096 2017-12-16 9:07 subdir
And I was able to delete subdir from the robert account.
So does the tutorial I have linked to give wrong information, or am I missing something?
|
It's wrong. To delete something you need write permissions on the directory containing it. That also goes for directories themselves: to delete a directory, you need (at a minimum) write permissions on the parent directory. You may need write permissions on the directory as well, but that's not enough by itself.
Write permissions on the directory itself are needed when the directory is not empty. In that case, you need to clear out the directory first by deleting everything in it, so you need write permissions on all sub-directories as well (recursively). Then you can delete the directory itself if you have write permissions on the parent.
| Does the "w" permission bit on a directory allow you to delete the directory? |
1,309,376,541,000 |
how do you find all files and directories without sticky bit?
I have a bunch of old files that I need to delete so I use: find . -mtime +3 -a \( -type f -o -type d \)
But then this find command will still find files with sticky bit permission: drwxrwxrwt
I want to make sure my find expressions does not find these files. Or ... should I just be lazy and ignore "operation not permitted" errors (maybe this is the sticky bit's intent/purpose... let's you delete files without worrying about accidently deleting files that you need)?
|
If you want to find stuff with sticky bit set, you need -perm parameter, version with slash checks for any of the bits - but we're only going to supply one bit, that is the octal version of sticky bit:
find . -perm /1000
Now you want to do the reverse, so negate the condition:
find . \! -perm /1000
And adjusted for your command:
find . -mtime +3 -a \( -type f -o -type d \) \! -perm /1000
| how do you find all files and directories without sticky bit? |
1,309,376,541,000 |
$ cp --no-preserve=mode --parents /sys/power/state /tmp/test/
$ cp --no-preserve=mode --parents /sys/bus/cpu/drivers_autoprobe /tmp/test/
The second of the two lines will fail with
cp: cannot make directory ‘/tmp/test/sys/bus’: Permission denied
And the reason is that /tmp/test/sys is created without write permission (as is the original /sys); a normal mkdir /tmp/test/sys2 would not have done this:
$ ls -la /tmp/test/
total 32
drwxr-xr-x 3 robert.siemer domain^users 4096 Oct 11 13:56 .
drwxrwxrwt 13 root root 20480 Oct 11 13:56 ..
dr-xr-xr-x 3 robert.siemer domain^users 4096 Oct 11 13:56 sys
drwxr-xr-x 2 robert.siemer domain^users 4096 Oct 11 13:59 sys2
How can I instruct cp to not preserve the mode, apart from --no-preserve=mode, which does not work as I believe it should...?
Or which tool should I use to copy a list of files without preserving “anything” except symlinks?
|
In case you are using GNU coreutils. This is a bug which is fixed in version 8.26.
https://lists.gnu.org/archive/html/bug-coreutils/2016-08/msg00016.html
So the alternative tool would be an up-to-date coreutils, or for example rsync which is able to do that even with preserving permissions:
$ rsync -a --relative /sys/power/state /tmp/test
$ rsync -a --relative /sys/bus/cpu/drivers_autoprobe /tmp/test/
Though I see rsync has other problems for this particular sysfs files, see
rsync option to disable verification?
Another harsh workaround would be to chmod all the dirs after each cp command.
$ find /tmp/test -type d -exec chmod $(umask -S) {} \;
(The find/chmod command above would also not work for any combination of existing permissions and umask.)
BTW you could report this bug to your Linux-Distribution and they might fix your 8.21 package via maintenance updates.
| Why does cp --no-preserve=mode preserves the mode? Alternative tools available? |
1,309,376,541,000 |
I have been trying to find setuid executables using a `one liner'.
The line I first tried was:
find / -perm /u+s -type f
Then I found a line which is similar but gives different results:
find / -perm /6000 -type f
These look identical as far as I can tell, but the first one doesn't show as many results as the second one (mostly ones with weird groups are missing). Why, what is different?
|
Most people aren't aware but the Unix permissions are actually not just User, Group, and Others (rwx). These 3 triads are the typical permissions that allow users, groups, and other users access to files & directories. However there is also a group of bits that precede the User bits. These bits are referred to as "Special Modes".
It's more of a shorthand notation that you don't have to explicitly set them when dealing with a tool such as chmod.
$ chmod 644
Is actually equivalent to:
$ chmod 0644
Here's the list of bits:
excerpt wikipedia article titled: chmod
Flag Octal value Purpose
---- ----------- -------
S_ISUID 04000 Set user ID on execution
S_ISGID 02000 Set group ID on execution
S_ISVTX 01000 Sticky bit
S_IRUSR, S_IREAD 00400 Read by owner
S_IWUSR, S_IWRITE 00200 Write by owner
S_IXUSR, S_IEXEC 00100 Execute/search by owner
S_IRGRP 00040 Read by group
S_IWGRP 00020 Write by group
S_IXGRP 00010 Execute/search by group
S_IROTH 00004 Read by others
S_IWOTH 00002 Write by others
S_IXOTH 00001 Execute/search by others
Your Question
So in your first command you're looking for u+s, which would work out to be bit 04000. When you use the numeric notation you're asking for bits 04000 AND 02000. This would give you files with user or group setuid bits set.
Further Reading
I highly suggest anyone that wants to understand the permissions better in Unix, to read the Wikipedia page about chmod. It breaks it down very simply and is a excellent reference when you forget.
References
chmod Tutorial
| Find and differences between -perm /6000 and -perm /u+s |
1,309,376,541,000 |
I just realised that I can move a file that I do not own and don't have write permissions on. I have write permissions to the directory, so I am guessing that is why I could move it, but in this instance, is there anyway of protecting the source file?
The permissions for the file are as follows;
cgi-bin> ls -al
drwxrwxrwx 3 voyager endeavor 512 Feb 1 10:45 .
drwxrwxrwx 6 voyager endeavor 512 Feb 1 09:38 ..
-rwxr-xr-x 1 voyager endeavor 22374 Feb 1 10:45 webvoyage_link.cgi
cgi-bin> whoami
moorc
cgi-bin> groups
lrsn endeavor
cgi-bin> rm webvoyage_link.cgi
rm: webvoyage_link.cgi: override protection 755 (yes/no)? yes
This last one is a big surprise to me to. How can I delete a file that I don't have access to. There is obviously something I'm missing.
|
Move (mv) is essentially an attribute-preserving copy followed by a deletion (rm), as far as permissions are concerned.1 Unlinking or removing a file means removing its directory entry from its containing directory. You are writing to the directory, not the file itself, hence no write permissions are necessary on the file.
Most systems support the semantics of the sticky bit on directories (chmod +t dir/), which when set only allows file owners to remove files within that directory. Setting the sticky bit on cgi-bin/ would mean moorc can no longer unlink files in cgi-bin that belong to voyager.
1 In general, when the destination is in the same filesystem as the source, there is no physical copy. Instead, a new link is made to the file in the destination directory, but the same general concept still holds that the file itself does not change.
For more reading, look at this article explains how file and directory permissions (including the sticky bit) affect system calls.
Postscript
I ran across an amusing analogy I really liked in a comment by @JorgWMittag on another question on this site.
Excerpt
It is identical to how an actual, "real-life" directory works, which is why it's called "directory", and not, for example, "folder", which would behave quite differently. If I want to delete someone from my phone directory, I don't go to her house and kill her, I simply take a pen and strike through her number. IOW: I need write access to the directory, and no access to her.
The analogy does break down a bit if you try to stretch it, because there's no effective way to describe the situation where the filesystem implementation automatically frees a file's disk blocks once the number of directory entries pointing to it drops to zero and all of its open handles are closed.
| mv file without write permission to the source file |
1,309,376,541,000 |
I stumbled upon Lynis - a security auditing tool for linux - and ran it on my Raspberry Pi to see if I could harden it a bit more. I got one warning in the Authentication group that confuses me.
- sudoers file [ FOUND ]
- Permissions for directory: /etc/sudoers.d [ WARNING ]
- Permissions for: /etc/sudoers [ OK ]
- Permissions for: /etc/sudoers.d/010_pi-nopasswd [ OK ]
- Permissions for: /etc/sudoers.d/010_at-export [ OK ]
- Permissions for: /etc/sudoers.d/README [ OK ]
- Permissions for: /etc/sudoers.d/pihole [ OK ]
However further down in the Result section it says:
-[ Lynis 2.7.5 Results ]-
Great, no warnings
Suggestions (5):
----------------------------
[...]
Also none of the Suggestions are referring to this Warning.
These are the permissions for the mentioned directory:
$ ls -l /etc/ | grep sudo
-r--r----- 1 root root 669 Nov 13 2018 sudoers
drwxr-xr-x 2 root root 4096 Dec 28 2018 sudoers.d/
Does anyone know why I get this warning and where I might find more detailed information?
|
Lynis expects /etc/sudoers.d to be unreadable by “others”, i.e. rwx[r-][w-][x-]---. If you run
chmod 750 /etc/sudoers.d
the warning will disappear.
The information should have been logged in the Lynis log file...
| Why do I get a warning for the sudoers.d when doing an audit with Lynis? |
1,309,376,541,000 |
Situation:
I am using Bash with Linux subsystem for Windows(10); I am logged in as root.
All folders and files in my current directory have rwxrwxrwx, and the same is true for descendant files and folders.
There is no system file in my current directory nor in the
descendants.
None of folders is synchronized with git.
Problem:
I cannot change the name of one particular directory. However I can do
this for every single other directory or file - whether in the current
directory, or inside the un-mv-able directory in question.
I can copy a whole directory to another one and then freely change its name, or I can copy its contents to the folder with the desired name, and those solutions are acceptable, but using just mv would be easier. For the sake of knowledge - as a bash and Linux beginner - I really would like to understand the problem.
Additional info as requested
root@MARVIN:/mnt/h/testing# mv test1.pl otherName
mv: cannot move ‘test1.pl’ to ‘otherName’: Permission denied
root@MARVIN:/mnt/h/testing# lsattr test1.pl
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/css
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/fonts
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index.html
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index2.html
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index3.html
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index4.html
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index5.html
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/js
lsattr: Inappropriate ioctl for device While reading flags on test1.pl/notes.txt
Given various operations I was doing on partition directory resides on, I guess it is not read-only, but for the record:
root@MARVIN:/mnt/h/testing# mount
rootfs on / type rootfs (rw,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204320k,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
none on /run/shm type tmpfs (rw,nosuid,nodev,relatime)
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755)
Solution
The directory was in fact blocked by Atom editor (installed on Windows not WSL).
Details
The directory in question is directory A.
If one of files Aa, Ab, Ac is opened in the editor, I can mv Dir A.
If one of files AAa ... ABc is opened I get Permission denied.
If contents of Dir A are visible it Atom project browser, I can mv it.
If contents of Dir AA or Dir AB are visible in Atom p. b., I get Permission denied.
|
I think that a service or a program of windows is perhaps using or accessing the same file , i used to have the same problem when i first installed the linux subsystem on windows 10.
| Permission denied when trying to 'mv' a directory [closed] |
1,309,376,541,000 |
I have a group manager and an user user1.
user1 will create a directory by example in the webserver path /var/www/user1Project.
How to allow the group manager to r/w in any directory owned by user1 ?
I already tried to add group manager to user1. But it did not solved my problem. A user from manager group is not allowed to write in user1Project. I do not know why.
|
This is quite special and you could not manage this by using the legacy permissions architecture of an unixoid system. The closest approach to your intention is using ACLs. Issue the following command (optionally as superuser):
setfacl -d -R -m g:manager:rwx /dir/of/user1
setfacl -R -m g:manager:rwx /dir/of/user1
The first command sets the default permissions to the directory so that they apply to newly created files (by user1). The second command sets the actual rights of the folders and files recursively.
Note, that the ACL infrastructure does not apply to the Apache Webserver. Apache only cares about the legacy permissions (user/group/others permission). So inside the webfolder every file/folder must be in the www-data group and every file must have at least read permissions for www-data. Folders should have the execute permissions for www-data for the Index searching.
Update:
To force the newly created files inside a directory to inherit the group of this directory set the gid bit of the directory:
chmod g+s /web/directory
Newly created files inside /web/directory will then inherit the group of /web/directory
| Allow group to r/w in folder owned by a specific user |
1,309,376,541,000 |
I read here that chmod -R 777 / is a very bad idea, because it overwrites permissions on files and deactivates the setuid, setgid, and sticky bits.
However I was thinking that chmod -R ugo+rwx / would not overwrite the permissions but add them, if not there already present, and that it would be therefore much safer than the aforementioned command. It also doesn't turn off any of the special bits, if I'm not mistaken.
Am I right? Or are those commands basically the same and both would destroy my system?
I don't intend on doing it, just asking for general culture.
|
You would strip all security from your system making it extremely vulnerable. Lots of programs would stop functioning due to insecure permissions. You are technically right it would append those rather than over write so you would keep SGID and SUID permissions. I have an old Ubuntu machine I no longer need so I figured I would test this. After running chmod -R ugo+rwx / sudo stopped working due to insecure perms on /usr/lib/sudo/sudoers.so . ssh stopped working because I was using rsa keys which also required strict permissions. I couldn't reboot the machine in the OS because sudo was broken however the power button worked just fine. I was surprised because the server actually booted up just fine, I could probably fix it with single user mode but I am just going to reinstall. So to answer your question, no. While chmod -R ugo+rwx / is technically different than chmod -R 777 / it is not safer because they both break your system.
| Is `chmod -R ugo+rwx /` less dangerous than `chmod -R 777 /`? |
1,309,376,541,000 |
I have been wanting to read systemd-journal by running/using journalctl -b . Now if I run it as a user I get the following :-
$ journalctl -b
Hint: You are currently not seeing messages from other users and the system
Users in the 'systemd-journal' group can see all messages. Pass -q to
turn off this notice.
No journal files were opened due to insufficient permissions.
After this I ran a grep in /etc/group to see if such a group exists.
$ sudo grep systemd-journal /etc/group
systemd-journal:x:102:
systemd-journal-remote:x:128:
then I tried to add the user to that group :-
$ sudo useradd -G systemd-journal shirish
useradd: user 'shirish' already exists
You can see what it says.
I used the id command to find which groups shirish belongs to
$ id shirish
uid=1000(shirish) gid=1000(shirish) groups=1000(shirish),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev),110(lpadmin),113(scanner),119(bluetooth),131(kvm),132(libvirt)
As can be seen I do not shirish being member of systemd-journal.
|
You don't use useradd to add a user to a group. You use useradd to create a user, hence the error message. Try:
# usermod -a -G systemd-journal shirish
or
# gpasswd -a shirish systemd-journal
In either case, you need to log in again to make it take effect. A quick-and-dirty way of doing this in a running shell is:
$ exec su - shirish
| user exists when trying to add user to systemd-journal group |
1,309,376,541,000 |
I hit again on this strange behaviour of the system. I'm running Debian 6.0.6 and had quite some troubles executing a script directly from CD/DVD. Finally I had to use:
sh /media/cdrom/command
to run it. What is the big deal of having to resort to sh?! What if the script relies on bash features? Really annoying and not much added to security in my opinion
Does anybody know of a good reason for that behaviour?
PS:
if you try to run it directly with ./... you get an error that does not suggest any hint to the issue (filesystem mounted noexec):
bash: ./media/cdrom/command: No such file or directory
If you run it as bash /media/cdrom/command you get the same error (I think verification of mount options are verified by bash even for commands passed as parameters on the command line.
Permanent solution is to add exec to the mount options in /etc/fstab such as:
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec 0 0
|
Filesystems are often mounted noexec,nosuid by default to boost the security a bit. Hence even though you see the executable bit on the file set, kernel will refuse to run it. By calling it in the form of interpreter path/to/script you are requesting the system to run interpreter, which in turn receives path/to/script as an argument and parses it thus bypassing the filesystem imposed restriction (you might be able to achieve the same effect with compiled executables with: /lib/ld-linux.so.1 path/to/executable).
Hence one option is mount -o exec .... You might want to put the option into /etc/fstab - usually by replacing the defaults option with defaults,exec. However, unless you really know what you are doing, I would advise against this.
As for the BASH specifics, I believe bash will interpret those even when running as sh. And you are definitely free to invoke it as bash path/to/script.
| Why do I have to use sh to execute scripts from CD/DVD media? |
1,309,376,541,000 |
I have a directory with a big load of sub directories. I own all of them, and the permissions are all 777.
pascal@azazel /box $ ls -al
total 147872
drwxr-xr-x 293 root root 12288 aoû 22 19:44 .
drwxr-xr-x 25 root root 4096 jun 28 18:49 ..
drwxrwxrwx 7 pascal pascal 4096 aoû 4 2010 131082
[...]
I want to rename the directories:
pascal@azazel /box $ mv 131073 NewName
mv: impossible de déplacer « 131073 » vers « NewName »: Permission non accordée
The message is in French, basically it said that I don't have the permission to rename (move) the directory.
What is happening?
|
Renaming a file (whatever its type, including directories) means changing its name in the directory where it is located. In fact, renaming and moving inside the filesystem are the same operation; the file is detached from its old name and attached to its new name, which requires modifying both the source and the destination directory (for renaming inside one directory, the source and target directories are the same). The upshot is that you need write permission on the containing directory, /box in your example.
These are exactly the same permissions you'd need to copy the file then remove the original, by the way.
| Can't rename a directory that I own |
1,309,376,541,000 |
Following on from another user's question I've bumped into a quirk of Linux filesystem permissions that I can't easily rationalize:
sudo mkdir ~/foo ~/foo/bar
sudo touch ~/baz
mkdir ~/my_dir
chown 700 ~/my_dir
# this is fine
mv ~/baz ~/my_dir
# renaming is fine
mv ~/foo ~/bob
# Moving caused: Permission denied
mv ~/bob ~/my_dir/
For clarity foo foo/bar baz are owned by root. my_dir is owned by my own user and of course ~ is owned by my own user. I can rename and move a file owned by another user. I can rename a directory owned by another user, but I can't move a directory owned by another user.
This seems a very specific restriction and I don't understand what danger is being protected against or what underlying mechanism means that it can only work this way.
Why can other users' directories not be moved?
|
This is one of the situations documented to lead to EACCES:
oldpath is a directory and
does not allow write permission (needed to update the
.. entry).
You can’t write inside bob, which means you can’t update bob/.. to point to its new value, my_dir.
Moving files doesn’t involve writing to them, but moving directories does.
| Why can't you move another user's directory when you can move their file? |
1,309,376,541,000 |
Consider the following folder structure:
.
├── test1
│   ├── nested1
│   ├── testfile11
│   └── testfile12
└── test2
├── nested1 -> /path/to/dir/test1/nested1
└── testfile21
test2/nested1 is a symlink to the directory test1/nested1. I would expect, if it were the cwd, .. would resolve to test2. However, I have noticed this inconsistency:
$ cd test2/nested1/
$ ls ..
nested1 testfile11 testfile12
$ cd ..
$ ls
nested1 testfile21
touch also behaves like ls, creating a file in test1.
Why does .. as an argument to cd refer to the parent of the symlink, while to (all?) others refers to the parent of the linked dir? Is there some simple way to force it to refer to paths relative to the symlink? I.e. the "opposite" of readlink?
# fictional command
ls $(linkpath ..)
EDIT: Using bash
|
The commands cd and pwd have two operational modes.
-L logical mode: symlinks are not resolved
-P physical mode: symlinks are resolved before doing the operation
The important thing to know here is that cd .. does not call the syscall chdir("..") but rather shortens the $PWD variable of the shell and then chdirs to that absolute path.
If you are in physical mode, this is identical to calling chdir(".."), but when in logical mode, this is different.
The main problem here: POSIX decided to use the less safe logical mode as default.
If you call cd -P instead of just cd, then after a chdir() operation, the return value from getcwd() is put into the shell variable $PWD and a following cd .. will get you to the directory that is physically above the current directory.
So why is the POSIX default less secure?
If you crossed a symlink in POSIX default mode and do the following:
ls ../*.c
cd ..
rm *.c
you will probably remove different files than those that have been listed by the ls command before.
If you like the safer physical mode, set up the following aliases:
alias cd='cd -P'
alias pwd='pwd -P'
Since when using more than one option from -L and -P the last option wins, you still may be able to get the other behavior.
Historical background:
The Bourne Shell and ksh88 did get directory tracking code at the same time.
The Bourne Shell did get the safer physical behavior while ksh88 at the same time did get the less safe logical mode as default and the options -L and -P. It may be that ksh88 used the csh behavior as reference.
POSIX took the ksh88 behavior without discussing whether this is a good decision.
BTW: some shells are unable to keep track of $PWD values that are longer than PATH_MAX and drive you crazy when you chdir into a directory with an absolute path longer than PATH_MAX. dash is such a defective shell.
| How is .. (dot dot) resolved in bash when cwd is a symlink to a directory [duplicate] |
1,309,376,541,000 |
Trying lots of different Linux distributions on all kinds of hardware, I find myself typing commands like this quite often:
sudo dd if=xubuntu-13.10-desktop-amd64.iso of=/dev/sdc bs=10240
Needless to say, sooner or later I will mistype the destination and wipe a harddrive instead of the intended USB drive. I would like not to use sudo every time here.
On my system, a fairly modern Ubuntu, permissions on /dev/sdc are like: (when a stick is present):
$ ls -al /dev/sdc*
brw-rw---- 1 root disk 8, 32 Apr 6 22:10 /dev/sdc
How do I grant my regular user write access to random USB sticks but not other disks present in my system?
|
I think you can use UDEV to do what you want. Creating a rules file such as/etc/udev/rules.d/99-thumbdrives.rules you'd simply add a rule that will allow either a Unix group or user access to arbitrary USB thumb drives.
KERNEL=="sd*", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", OWNER="<user>", GROUP="<group>", MODE="0660"
Would create the device using the user <user> and group <group>.
Example
After adding this line to my system.
KERNEL=="sd*", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", OWNER="saml", GROUP="saml", MODE="0660"
And reloading my rules:
$ sudo udevadm control --reload-rules
If I now insert a thumbdrive into my system, my /var/log/messages shows up as follows:
$ sudo tail -f /var/log/messages
Apr 13 11:48:45 greeneggs udisksd[2249]: Mounted /dev/sdb1 at /run/media/saml/HOLA on behalf of uid 1000
Apr 13 11:51:18 greeneggs udisksd[2249]: Cleaning up mount point /run/media/saml/HOLA (device 8:17 is not mounted)
Apr 13 11:51:18 greeneggs udisksd[2249]: Unmounted /dev/sdb1 on behalf of uid 1000
Apr 13 11:51:18 greeneggs kernel: [171038.843969] sdb: detected capacity change from 32768000 to 0
Apr 13 11:51:39 greeneggs kernel: [171058.964358] usb 2-1.2: USB disconnect, device number 15
Apr 13 11:51:46 greeneggs kernel: [171066.053922] usb 2-1.2: new full-speed USB device number 16 using ehci-pci
Apr 13 11:51:46 greeneggs kernel: [171066.134401] usb 2-1.2: New USB device found, idVendor=058f, idProduct=9380
Apr 13 11:51:46 greeneggs kernel: [171066.134407] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Apr 13 11:51:46 greeneggs kernel: [171066.134410] usb 2-1.2: Product: USBDrive
Apr 13 11:51:46 greeneggs kernel: [171066.134412] usb 2-1.2: Manufacturer: JMTek
Apr 13 11:51:46 greeneggs kernel: [171066.135470] usb-storage 2-1.2:1.0: USB Mass Storage device detected
Apr 13 11:51:46 greeneggs kernel: [171066.136121] scsi17 : usb-storage 2-1.2:1.0
Apr 13 11:51:46 greeneggs mtp-probe: checking bus 2, device 16: "/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2"
Apr 13 11:51:46 greeneggs mtp-probe: bus: 2, device: 16 was not an MTP device
Apr 13 11:51:47 greeneggs kernel: [171067.139462] scsi 17:0:0:0: Direct-Access JMTek USBDrive 7.77 PQ: 0 ANSI: 2
Apr 13 11:51:47 greeneggs kernel: [171067.140251] sd 17:0:0:0: Attached scsi generic sg2 type 0
Apr 13 11:51:47 greeneggs kernel: [171067.142105] sd 17:0:0:0: [sdb] 64000 512-byte logical blocks: (32.7 MB/31.2 MiB)
Apr 13 11:51:47 greeneggs kernel: [171067.144236] sd 17:0:0:0: [sdb] Write Protect is off
Apr 13 11:51:47 greeneggs kernel: [171067.145988] sd 17:0:0:0: [sdb] No Caching mode page found
Apr 13 11:51:47 greeneggs kernel: [171067.145998] sd 17:0:0:0: [sdb] Assuming drive cache: write through
Apr 13 11:51:47 greeneggs kernel: [171067.153721] sd 17:0:0:0: [sdb] No Caching mode page found
Apr 13 11:51:47 greeneggs kernel: [171067.153728] sd 17:0:0:0: [sdb] Assuming drive cache: write through
Apr 13 11:51:47 greeneggs kernel: [171067.159028] sdb: sdb1
Apr 13 11:51:47 greeneggs kernel: [171067.164760] sd 17:0:0:0: [sdb] No Caching mode page found
Apr 13 11:51:47 greeneggs kernel: [171067.164768] sd 17:0:0:0: [sdb] Assuming drive cache: write through
Apr 13 11:51:47 greeneggs kernel: [171067.164775] sd 17:0:0:0: [sdb] Attached SCSI removable disk
Apr 13 11:51:47 greeneggs kernel: [171067.635474] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
Apr 13 11:51:47 greeneggs udisksd[2249]: Mounted /dev/sdb1 at /run/media/saml/HOLA on behalf of uid 1000
Now checking out the device files under /dev shows the following:
$ ls -l /dev/sd*
brw-rw----. 1 root disk 8, 0 Apr 13 09:17 /dev/sda
brw-rw----. 1 root disk 8, 1 Apr 13 09:17 /dev/sda1
brw-rw----. 1 root disk 8, 2 Apr 13 09:17 /dev/sda2
brw-rw----. 1 saml saml 8, 16 Apr 13 11:51 /dev/sdb
brw-rw----. 1 root disk 8, 17 Apr 13 11:51 /dev/sdb1
So it would seem to have worked.
Being more explicit
The above will work but will likely have these rules getting applied to every block device which isn't quite what we want. To narrow its focus a bit you can use ATTRS{..}==... attribute rules to restrict the application to specific hardware. In my case I only want it to be applied to a single USB thumbdrive.
Step #1 - uniquely id device
So to start we can use this command once we've mounted the particular thumb drive so that we can use udevadm to scrutinize it, groping it for its particular attributes.
Here I'm focusing on looking at the "manufacturer" and "product" attributes.
$ udevadm info -a -p $(udevadm info -q path -n /dev/sdb)|grep -iE "manufacturer|product"
ATTRS{manufacturer}=="JMTek"
ATTRS{idProduct}=="9380"
ATTRS{product}=="USBDrive"
ATTRS{idProduct}=="0020"
ATTRS{manufacturer}=="Linux 3.13.7-100.fc19.x86_64 ehci_hcd"
ATTRS{idProduct}=="0002"
ATTRS{product}=="EHCI Host Controller"
NOTE: ATTRS{..}==.. attributes are attributes to parent devices in the hierarchy of where this device's device file is ultimately deriving from. So in our case the block device being added, /dev/sdb is coming from a USB parent device, so we're looking for this parent's attributes, ATTRS{manufacturer}=..., for example.
So in this example I'm selecting the manufacturer "JMTek" and the product "USBDrive".
Step #2 - modify .rules flie
So with these additional bits in hand let's add them to our original .rules file.
KERNEL=="sd*", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ATTRS{manufacturer}=="JMTek", ATTRS{product}=="USBDrive", OWNER="saml", GROUP="saml", MODE="0660"
Step #3 - Trying it out
Now when we reload our rules and unmount/remove/reinsert our USB thumbdrive again we get this rule:
$ ls -l /dev/sdb*
brw-rw----. 1 saml saml 8, 16 Apr 13 12:29 /dev/sdb
brw-rw----. 1 root disk 8, 17 Apr 13 12:29 /dev/sdb1
However if I insert a completely different device:
$ ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 Apr 13 12:41 /dev/sdb
brw-rw----. 1 root disk 8, 17 Apr 13 12:41 /dev/sdb1
References
ArchLinux Wiki UDEV Topic
| Writing raw images safely to USB sticks |
1,309,376,541,000 |
When moving or copying files as root I often want to set the ownership for those files based on the owner of the directory I am moving the files to.
Before I go off and write a script that parses the rsync output for all the files that were copied over and then goes through those setting chown on each file, is there a better/existing way to do this?
As an example, say I need to copy/move/sync the folder tmp/ftp/new-assests/ to ~user1/tmp/ and to ~user2/html-stuff/ the originals are owned by the user _www and I want the target files and the folder containing them and any other folders to be owned by user1 and user2, respectively and the target directories have existing files in them.
Yes, the users could copy the fils themselves if they had read access to that folder, but that is irrelevant in this case. Let’s assume these are all nologin users and they do not have access to the source file, if that helps.
|
Using rsync:
rsync -ai --chown=user1 tmp/ftp/new-assests/ ~user1/tmp/
This would copy the directory to the given location and at the same time change the ownership of the files to user1, if permitted.
The general form of the argument to --chown is USER:GROUP, but you may also use just USER to set a particular user as owner, as above, or just :GROUP to set a particular group (the : is not optional if you leave the user ID out).
| Setting ownership when copying or syncing files |
1,309,376,541,000 |
I tried to run
mount /home/user/nvme0n1 -U 8da513ec-20ce-4a2d-863d-978b60089ad3 -t ext4 -o umask=0000
and the response is:
mount: /home/user/nvme0n1: wrong fs type, bad option, bad superblock
on /dev/nvme0n1, missing codepage or helper program, or other error.
However, when I remove the umask option, the SSD is mounted as desired.
What should I do? How can I start debugging the problem? I want the device to have mode=777.
|
You're mounting an ext4 filesystem:
... -t ext4 -o umask=0000
Per the ext4(5) man page, the ext4 filesystem does not have a umask mount option.
I want the device to have mode=777.
If you need different permissions on files and/or directories, you can set file/directory permissions on the files/directories themselves. See
What are the different ways to set file permissions etc on gnu/linux.
| mount with umask does not works |
1,309,376,541,000 |
I understand there are 12 permission bits of which there are 3 groups of 3 bits for each of user, group, and others, which are RWX respectively. RW are read and write, but for X is search for directories and execute for files.
Here is what I don't get:
What are the 3 remaining mode bits and are they all stored in the inode?
I know the file directory itself is considered a file as well, since all things in UNIX are files (is this true?), but since UNIX systems use ACL to represent the file system, then the file system is a list of filename-inode_number pairs. Where does a file directory store it's own inode number and filename?
|
stat /bin/su shows on one system:
Access: (4755/-rwsr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
There's the octal representation 4755 of all 12 mode bits. The number corresponds to the bits:
octal 4 7 5 5
bits 100 111 101 101
sst uuu ggg ooo
ug rwx rwx rwx
Where uuu, ggg and ooo are the permission bits for the user, group and others. The remaining group (the first one in order) contains the setuid (su), setgid (sg) and sticky (t) bits.
The setuid and sticky bits are often not mentioned, since they're zero for most files. They're still there for every file, saved along with the others.
If we really get down to it, some filesystems and interfaces store the file type along the mode bits, in the still-higher bits. The above only accounts for 12 bits, so with a 16-bit field, there's 4 left over. See, for example, the description of st_mode in stat(2).
| What are the final 3 bits in the UNIX permission mode bits? |
1,309,376,541,000 |
If a file has ACL entries for two groups, giving them different permissions, like this:
group:admin:rw-
group:staff:r--
what permissions does a user have if he belongs to both groups? Which entry takes precedence? Experiment seems to show that the most restrictive permissions apply. If so, what's the best way to deal with situations where I really want members of one group to have elevated privileges, even if they belong to other, more restricted groups too?
|
From the standard:
In words, Common Access Determination Algorithm is to be interpreted as
follows (this description is a loose paraphrase of the common access
determination algorithm which is specified in detailed pseudocode in
ACL Managers ):
Match (in the sense defined in the pseudocode in ACL Managers )
the incoming PAC against the ACL's access ACLEs (in the
top-to-bottom order shown, namely: UO, U, FU, GO/G/FG, O, FO, AO),
stopping at the first such match (except that all matches are
considered "simultaneously" in the case of the indicated group-like
ACLEs), and note the permissions granted by the matched ACLE (or,
in the case of the group-like ACLEs, the union of the permissions
granted by all the matched ACLEs).
Mask (that is, intersect) the acquired permissions against the
permissions in the ACL's mask ACLEs, as necessary (namely, mask
with MASK_OBJ permissions if the match occurred in the center
column1, and/or mask with UNAUTHENTICATED permissions if the PAC
is unauthenticated). (If the ACL Manager doesn't support these two
mask ACLEs, this step is a null operation.)
(emphasis in original, footnote added)
That is, if there is a file with user and group root and permissions 0600 called acl-test, containing the single line read possible, then:
$ getfacl acl-test
# file acl-test
# owner: root
# group: root
user::rw-
group::---
other::---
Now if I (as user fox) attempt to cat this:
$ cat acl-test
cat: acl-test: Permission denied
Group permissions are unioned
I happen to be in the groups users and wheel, so we can add specific ACLs for these groups:
# setfacl -m g:users:--- -m g:wheel:r-- acl-test
$ cat acl-test
read possible
This is because the group entries (considered simultaneously) allow read permission to one of my groups. These can be combined:
# setfacl -m g:users:-w- acl-test
$ getfacl acl-test
# file: acl-test
# owner: root
# group: root
user::rw-
group::---
group:wheel:r--
group:users:-w-
mask::rw-
other::---
$ printf '%s\n' 'write possible' >> acl-test
$ cat acl-test
read possible
write possible
So now I can both read and write the file, even though the groups that allow these permissions are not the same group.
User-specific permissions override all groups
Since user rules apply before group rules, we can still restrict a given user from reading and/or writing contents:
# setfacl -m u:fox:--- acl-test
$ getfacl acl-test
# file: acl-test
# owner: root
# group: root
user::rw-
user:fox:---
group::---
group:wheel:r--
group:users:-w-
mask::rw-
other::---
$ cat acl-test
cat: acl-test: Permission denied
A mask, if set, overrides almost everything
If a file is meant to be truly read-only to anyone but the owner:
# setfacl -x u:fox -m g::rw- -m m:r-- acl-test
$ getfacl acl-test
# file: acl-test
# owner: root
# group: root
user::rw-
group::rw- #effective:r--
group:wheel:r--
group:users:-w- #effective:---
mask::r--
other::---
$ printf '%s\n' 'now writing is impossible' >> acl-test
bash: acl-test: Permission denied
# printf '%s\n' 'owner can still write' >> acl-test
Amusingly, the mask does not override the others permissions, so:
# setfacl -x g:users -x g:wheel -m o:rw- -n acl-test
$ getfacl acl-test
# file: acl-test
# owner: root
# group: root
user::rw-
group::rw- #effective:r--
mask::r--
other::rw-
$ printf '%s\n' 'others can write now' >> acl-test
# chown :users acl-test
$ printf '%s\n' 'but not members of the owning group' >> acl-test
bash: acl-test: Permission denied
1 The "center column" refers to this image and contains everything except UO and O, so the owning user and others are unaffected by a mask. All groups and non-owning users with defined rules are affected.
| Precedence of ACLS when a user belongs to multiple groups |
1,309,376,541,000 |
I have an (s|g)uid file world-writable:
ls -lh suid_bin.sh
-rwsr-srwx 1 root root 168 mai 23 16:46 suid_bin.sh
logged with a non-root user account. I use vi (or another editor) to modify "suid_bin.sh". After saving the new content, (s|g)uid bits are unset:
ls -lh suid_bin.sh
-rwxr-xrwx 1 root root 168 mai 23 16:46 suid_bin.sh
Why? Is there a way to keep (s|g)uid bits after modification?
|
Unix permissions allow writing to file if accidentally someone will set group or world writable bit on setuid file, but disallow changing owner and group ids on such files by strangers.
So after modification kernel drops setuid/setgid bits from file to ensure there is no malicious code was written to file.
root user of course can restore setuid bit, but ordinary user, if he, by someone's mistake gained write access to privileged executable will not be able to exploit it.
And, knowing parts of kernel in that area I am not sure you can disable that without editing source code of kernel and recompiling.
Note that setuid scripts in Linux do not gain setuid status after execution because actually kernel starts the script interpreter, without setuid status, with the full path to script as it's last parsed argument, and then interpreter reads the script as an ordinary file. But this can vary on other Unix systems.
| why suid bit is unset after file modification |
1,309,376,541,000 |
I have a situation where I need to find the files having World Write (WW) permission 666 and I need to re mediate such files with 664 .. for this I have used this command
find /dir/stuct/path -perm -0002 -type f -print > /tmp/deepu/permissions.txt
when I execute the command I get the files which have WW permissions.. Now my requirement is like
find /dir/stuct/path -perm -0002 -type f chmod 664
Is my syntax correct?
|
Think about your requirement for a moment.
Do you (might you possibly) have any executable files (scripts or binaries)
in your directory tree?
If so, do you want to remove execute permission (even from yourself),
or do you want to leave execute permission untouched?
If you want to leave execute permission untouched, you should use chmod o-w to remove (subtract) write permission from the others field only.
Also, as Anthon points out, the find command given in the other answer
executes the chmod program once for each world-writable file it finds.
It is slightly more efficient to say
find top-level_directory -perm -2 -type f -exec chmod o-w {} +
This executes chmod with many files at once, minimizing the number of execs.
P.S. You don’t need the leading zeros on the 2.
| How to chmod the files based on the results from find command |
1,309,376,541,000 |
This are the permissions on the RHEL5 machine:
[root@server1 belmin]# ls -la | egrep '\.(bash_profile)?$'
drwx------ 9 belmin belmin 4096 Sep 16 14:29 .
drwxr-xr-x 40 root root 4096 Sep 2 15:32 ..
-rw-r--r-- 1 belmin belmin 801 Aug 25 2011 .bash_profile
However I am receiving an error when doing a mv operation:
[root@server1 belmin]# mv .bash_profile{,.backup-20140916}
mv: cannot move `.bash_profile' to `.bash_profile.backup-20140916': Operation not permitted
Saw this similar question but that's about an NFS mount, this is an ext3 mount:
[root@server1 belmin]# df -P .
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 28794584 7901184 19430684 29% /
[root@server1 belmin]# mount | grep sda3
/dev/sda3 on / type ext3 (rw)
Selinux is enabled but I do not see any relevant audit message in syslog.
Any suggestions?
|
Check if immutable flag is set on .bash_profile:
lsattr .bash_profile
You can remove it with:
chattr -i .bash_profile
HTH, Cheers
| Root is receiving "operation not permitted" error when trying to move a a users .bash_profile |
1,309,376,541,000 |
I have a cifs mount that is mounted from /etc/fstab. But I would quite like creation of files/dirs on that share to ignore my umask. Is that possible? It seems that cifs does not support the umask=000 option (source: man mount.cifs).
My current best option is to set my system-wide umask to 000, but I'd rather not do this as I'd like to keep the local machine a bit more locked down. The silly thing is that my previous NAS did this fine, so maybe it's a server-side change that's required?
|
As suggested in my question, it was a server-side change that needed making. I added these lines to /etc/smb.conf on the server:
create mask = 0666
force create mode = 0666
directory mask = 0777
force directory mode = 0777
And now it works fabulously.
| How to make a cifs/smb mount ignore umask? |
1,309,376,541,000 |
I work on the application that uses Unix domain socket for IPC. The common way as I know is to place the socket file inside /var/run. I work with Ubuntu 18.04 and I see that var/run is a symlink for /run. Unfortunately the folder is accessible for root only:
ls -Al /
drwxr-xr-x 27 root root 800 Apr 12 17:39 run
So only root has write access for this folder and that makes it impossible to use Unix domain sockets for regular users.
First of all I can't understand why? And how to use Unix domain sockets for non-root users? I can use the home folder of course, but I prefer to use some correct and common method.
|
There's nothing wrong with creating the socket in a dotfile or dotdir in the home directory of the user, if the user is not some kind of special, system user. The only problem would be with the home directory shared between multiple machines over nfs, but that could be easily worked around by including the hostname in the name of the socket.
On Linux/Ubuntu you could also use "abstract" Unix domain sockets, which don't use any path or inode in the filesystem. Abstract unix sockets are those whose address/path starts with a NUL byte:
abstract: an abstract socket address is distinguished (from a pathname socket) by the fact that sun_path[0] is a null byte (\0).
The socket's address in this namespace is given by the additional
bytes in sun_path that are covered by the specified length of the
address structure. (Null bytes in the name have no special significance.) The name has no connection with filesystem pathnames. When
the address of an abstract socket is returned, the returned addrlen
is greater than sizeof(sa_family_t) (i.e., greater than 2), and the
name of the socket is contained in the first (addrlen - sizeof(sa_family_t)) bytes of sun_path.
When displayed for or entered by the user, the NUL bytes in a abstract Unix socket address are usually replaced with @s. Many programs get that horribly wrong, as they don't escape regular @s in any way and/or assume that only the first byte could be NUL.
Unlike regular Unix socket paths, abstract Unix socket names have different semantics, as anybody can bind to them (if the name is not already taken), and anybody can connect to them.
Instead of relying on file/directory permission to restrict who can connect to your socket, and assuming that eg. only root could create sockets inside some directory, you should check the peer's credential with getsockopt(SO_PEERCRED) (to get the uid/pid of who connected or bound the peer), or the SCM_CREDENTIALS ancillary message (the get the uid/pid of who sent a message over the socket).
This (replacing the usual file permission checks) is also the only sane use of SO_PEERCRED/SCM_CREDENTIALS IMHO.
| Unix domain sockets for non-root user |
1,309,376,541,000 |
We have a file foobar not owned by me, but it is in my group:
$ ll
total 4,0K
-rw-rw-r-- 1 root hbogert 4 jan 19 12:27 foobar
I can touch it and it will update all times:
$ stat foobar
File: 'foobar'
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 4869333 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 1000/ hbogert)
Access: 2017-01-19 12:27:04.499412133 +0100
Modify: 2017-01-19 12:27:04.499412133 +0100
Change: 2017-01-19 12:27:04.499412133 +0100
Birth: -
$ touch foobar
$ stat foobar
File: 'foobar'
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 4869333 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 1000/ hbogert)
Access: 2017-01-19 12:32:04.375412133 +0100
Modify: 2017-01-19 12:32:04.375412133 +0100
Change: 2017-01-19 12:32:04.375412133 +0100
Birth: -
However, when I just want to change the modification time, it fails:
$ touch -m foobar
touch: setting times of 'foobar': Operation not permitted
Is this expected behaviour?
|
The behaviour is expected, if rather non-obvious. At least on my system, touch does
utimensat(0, NULL, NULL, 0)
in the first case (touch file), and
utimensat(0, NULL, [UTIME_OMIT, UTIME_NOW], 0)
in the second (touch -m file). The first call is short-hand for "set the access and modification times to the current time"; the second says "leave the access time alone and change the modification time to the current time".
POSIX says
Only a process with the effective user ID equal to the user ID of the file, or with write access to the file, or with appropriate privileges may use futimens() or utimensat() with a null pointer as the times argument or with both tv_nsec fields set to the special value UTIME_NOW. Only a process with the effective user ID equal to the user ID of the file or with appropriate privileges may use futimens() or utimensat() with a non-null times argument that does not have both tv_nsec fields set to UTIME_NOW and does not have both tv_nsec fields set to UTIME_OMIT.
(times is the third argument to utimensat()). touch file falls under the first set of access restrictions: any write access to the file allows the access and modification times to be changed to "now". touch -m file falls under the second set of access restrictions: you need to be root or the owner of the file to be able to change the access and modification times to values which are not either both "now" or both "unchanged".
There are other ways of changing the access and/or modification times to "now" on files you don't own but can read or write:
reading a file will update the access time only;
writing a file (without reading it) will update the modification time only.
| Why can touch change only all times, or nothing when not owner |
1,309,376,541,000 |
How can I get a list which users are authorized to a folder and which permissions they have?
I tried already the most common ones like 'ls', 'namei' or 'getfacl'
|
When you
ls -ld */
you get a list (-l) of your directories (-d) in the current path. You may see the access rights of owner, group and others.
For more details regarding the access rights you may check:
This link
When you check the output from the ls command you can see the owner of the file or directory and next to it the group owner of the file or directory. If for example the group is called "logistics" you can view the members of this group with the following command:
grep 'logistics' /etc/group
| List of user permissons for a specific folder |
1,455,517,269,000 |
I wrote a script to change permissions on all files in a directory:
#!/bin/bash
files=`find "$1"`
for f in $files; do
chown "$2" "$f"
chmod 600 "$2"
done
Obviously, the second argument to chmod should be "$f" instead of "$2". However, when I ran the script (on a small directory) I also forgot to include the second argument, which should have been "dave:dave". Now, all the files in the directory are completely messed up:
~ $ ll Documents/
ls: cannot access Documents/wiki.txt: Permission denied
ls: cannot access Documents/todo.txt: Permission denied
ls: cannot access Documents/modules.txt: Permission denied
ls: cannot access Documents/packages.txt: Permission denied
total 0
-????????? ? ? ? ? ? modules.txt
-????????? ? ? ? ? ? packages.txt
-????????? ? ? ? ? ? todo.txt
-????????? ? ? ? ? ? wiki.txt
Running sudo chown dave:dave Documents/* and sudo chmod 600 Documents/* throws no errors, but the files remain unchanged. I know I can sudo cat each file into a new file, but I'm curious how to fix the permissions on the original files.
|
In addition to the answers given in the comments, you should also note that your script will break on any filenames with spaces in them.
You can do all of this in a single command using find, rather than trying to parse a list of filenames output from find. Much more robust; handles filenames regardless of special characters or whitespace.
find "$1" -type f -exec chown "$2" {} \; -exec chmod 600 {} \;
Note that if the chown fails on a given file, the chmod will not be run on that file. That's probably the behavior you want anyway.
Since you already ran an erroneous command that removed execute permissions from your "Documents" directory, you need to add back execute permissions:
chmod u+x Documents
If there are more directories that erroneously had execute permissions removed, you should be able to fix them with:
find Documents -type d -exec chmod u+x {} \;
I don't think you'll need this, though, as once execute permissions were removed from "Documents" then none of its subdirectories would be accessible, so execute permissions wouldn't have been removed from them.
| Fix files with ????????? permissions |
1,455,517,269,000 |
Having the following directory structure
[sr@server directory]$ tree
.
├── folder1
│ ├── fileA
│ └── fileB
└── folder2
└── fileC
2 directories, 3 files
I want to set a default facl on folder1 and folder2 that, for the user jim has the following permissions
.
├── folder1 --x
│ ├── fileA r--
│ └── fileB r--
└── folder2 --x
└── fileC r--
I.E. all files have r-- and all folders have --x
Any files created under folder1 or folder2 should be given the r-- permission for user jim, any folders should be given the --x permission for user jim
I can set the permissions so folders created have r-x and files have r-- but I can't figure out a way to set the default permissions so folders don't get the read permission.
While I can manually set the permissions for the currently existing files I want those permissions to apply as defaults to all newly created files and folders.
setfacl version 2.2.49 on RHEL 6.4
|
What you request is not supported by Linux's ACLs.
setfacl -m u:jim:r-X (capital X) gives Jim permission to read all files including directories, and to execute only directories and files that are executable by their owner.
Making directories non-readable has very limited usefulness. If you tell us what you're trying to accomplish, we might be able to offer a better solution.
| setfacl default --x on directories and r-- on files for user |
1,455,517,269,000 |
I want to find all files which have a higher permission than e.g. 640. Perhaps this would work with a find and exec command. But my knowledge isn't sufficient for such a task.
|
I think what you're after is
find -perm -640 ! -perm 640
i.e search files that have at least all the permissions in 640 and that don't have 640 as the permission bits. Or, in other words, amongst the files that are readable and writable by their owner and readable by the group, search files that are executable or writable by someone other than the owner or world-readable (assuming no ACLs). You may want to add -type f to restrict to regular files, or at least ! -type d -o -type d -perm 750 ! -perm 750 to allow directories to have execution permission.
If you want to match files whose permission bits, interpreted as an integer, are higher than 0o640 (which doesn't really make any sense), you're going to have to enumerate several cases. If you look at the bitwise representation, there are two ways for a number between 0 and 0o777 to be larger than 0o640: either the 0o100 bit is set in addition to the 0o600 bits, or the 0o640 bits are set. Remove the final ! -perm 640 if you want permissions 0o640 to match.
find -perm -700 -o -perm -640 ! -perm 640
| find files which have a higher permission than xxx |
1,455,517,269,000 |
In fact, I would like to ask more general question -- "what does write permission for a directory allow you to do exactly?" -- but let's approach it with a concrete example.
It is a long question, if you are in a hurry read the bold -- it should cover the main part.
Different sources (nice question, one more, grymoire's) say something similar to the following on the directory permissions:
r, read -- reading of the directory's content (filenames inside)
w, write -- changing the directory's attributes (e.g. modification time) and creating/renaming/removing entries inside
x, search -- accessing files inside, you have access to the inode of the file, hence you can reach it's actual content
My problem is with the description of w. What directory's attributes does it give you access to? I cannot create/rename/remove a file inside a directory with only write permission:
I make a directory (tdir/) and a file inside (afile), chmod -x-r tdir/, mv tdir/afile tdir/af, rm tdir/afile, touch tdir/newfile -- all fail with permission denial, unless I set x permission to the directory as well.
And x alone doesn't give you the permission to create/rename/remove files inside the directory.
In order to do that you need both x and w.
But touch tdir does change the modification time of the directory with w only.
I would rephrase the sources above this way for the compliance with the issue: a directory's r allows you to see the filenames inside, but no access to the actual file (to the inode); x gives you access to the inodes of the files (which means you can see their permissions and, according to it, have access to the contents), but you still cannot change anything in the directory; directory is actually some sort of a file and to change something in it you need the w permission.
Thus, when you are changing something in the directory you need w permission. If your change requires inodes of the files in the directory -- you need x as well.
It explains why you cannot remove a file inside a directory with w only: when removing a file you need to reduce the link count of the inode by 1 -- you need to know the inode -- thus you need x for the directory.
But why do you need x for creating (you could ask the system to create a file without exposing the inode?) and renaming/moving the file (when you move a file you don't change it in any way, you only change the records inside the directories and their inode counts?)?
Maybe it is just an implementation thing? I.e. indeed you don't need the inode for renaming/creating files -- you need only filenames and w permission; but inode and filename constitute one record in the directory; thus changing the filenames = changing the records = kind of accessing the inodes.
And also what attributes do directories have besides modification time, permissions and files records? What else in the directory can you change with w only?
|
x gives you access to the inodes of the files (which means you can see their permissions and, according to it, have access to the contents), but you still cannot change anything in the directory; directory is actually some sort of a file and to change something in it you need the w permission.
Yes.
But why do you need x for creating (you could ask the system to create a file without exposing the inode?) and renaming/moving the file (when you move a file you don't change it in any way, you only change the records inside the directories and their inode counts?)?
Without x, you can only affect the directory itself — you're seeing the directory from the outside. Without x, the directory entries are out of bounds for you. If you want to add, remove, or modify (e.g. rename) an entry in the directory, you need to be able to access that entry.
The permissions on a file determine what you can do with the file's content. The permissions on the directory determine what you can do with the directory entry for the file, since the directory entries are the directory's content.
Write permission in a directory lets you create and remove entries. Renaming counts as atomically creating an entry and removing another one. Beyond that, directories have the same metadata as regular files. Write permission also lets you change the directory's last modification and last access timestamps. To change a directory's permissions, group ownership or access control lists (where supported), you need to own it. To change its user ownership, most unix variants require root.
| Write-only permission for a directory doesn't allow to rename (move) files inside? |
1,455,517,269,000 |
I'm trying to fully grasp the concept of setuid and setgid, and I'm not quite sure in what way permissions are actually elevated. Let me provide an example:
Users
userA (groups: userA groupA)
userB (groups: userB groupB GroupC)
Executable
Permission owner group filename
-rws-----x userA groupD file
-rwsrws--x userA groupD file2
If userB executes file and file2, what group permission will the executables have? What I'm not completely sure about, is whether the executable gains user/group permissions of both the caller and the file owner, or if permissions are "replaced".
I know this is a silly example, as setuid and setgid will normally be used to envoke "all-powerful" applications, but I hope this example will be better at actually conceptualizing how setuid and setgid works.
|
setuid sets the effective uid euid.
setgid set the effective gid egid.
In both cases the callers uids and gids will stay in place. So roughly you can say that you will get that uid/gid in addition to the callers uid and (active) gid.
Some programs can differentiate that very well.
If you log into a system, then su to root and then issue a who am i you will see your "old" account.
su is one of these suid-binaries, that will change the euid.
| setuid and setgid confusion |
1,455,517,269,000 |
The problem: I set my umask for my user to be 0077. Now I use sudo instead of su when I need super-user access, and the problem is that whenever I execute a software installation using sudo with something like sudo pip3 install sympy, all the software installed by that gets the permission masked by 0077, meaning all these libs are not reachable by any user!!
The question: How can get all sudo calls to have the mask 0022 while my user calls have a mask of 0022?
Note: I did add the line Defaults umask = 0022 in sudo visudo and still didn't work. Is this everything to be done?
How do I set my umask: I have the line umask 0077 added to ~/.bashrc and ~/.profile.
|
This seems to have been overlooked:
Defaults umask_override
which does what was asked (see the sudoers manpage):
umask_override
If set, sudo will set the umask as specified by sudoers without modification. This makes it possible to specify a more permissive umask in sudoers than the user's own umask and matches historical behavior. If umask_override is not set, sudo will set the umask to be the union of the user's umask and what is specified in sudoers. This flag is off by default. If set, sudo will run the command in a pseudo-pty even if no I/O logging is being gone. A malicious program run under sudo could conceivably fork a background process that retains to the user's terminal device after the main program has finished executing. Use of this option will make that impossible. This flag is off by default.
| Set sudo umask apart from the user calling it |
1,455,517,269,000 |
Is there a way to invoke unzip (from Info-ZIP) on a Linux system without having it restore the permissions stored in the zip file? The zip files I'm restoring are enormous, so going back over the contents with something like "chmod -R" will take a while. I do not control the source of the archives, so my only choice is to handle the permissions on extraction.
|
Restoring permissions is a feature of unzip (from the man page, version 6.00):
Dates, times and permissions of stored directories are not restored
except under Unix. (On Windows NT and successors, timestamps are now
restored.)
and there is no option to switch if off.
It might be that an older version of unzip did not support restoring permission, but investigating that route is probably more cumbersome than trying to change the latest unzip source to do what you want.
If running chmod -R is unacceptable you can take a look at using Python's zipfile library, it is easy to use and gives you full control over the way you write the files that you extract from the zip file.
| Unzip (Info-ZIP) Permissions |
1,455,517,269,000 |
I'm using ACL to control access to individual roots of webs for different instances of Apache and different groups of admins. I've got a Unix group admins-web22 for admins of a particular website and user apache-web22 for a particular instance of apache. These are the permissions set on the root directory of the web:
# file: web22
# owner: root
# group: root
user::rwx
user:apache-web22:r-x
group::rwx
group:webmaster:rwx
group:admins-web22:rwx
mask::rwx
other::---
default:user::rwx
default:user:apache-web22:r-x
default:group::rwx
default:group:admins-web22:rwx
default:mask::rwx
default:other::r-x
There is a user fred which is a member of admins-web22. This user has full read-write access to the directory (as stated above). This works correctly. However, this user is unable to grant write permissions to user apache-web22 for some files and directories, which is important (e.g., the web admin wants to set an upload directory for Drupal). The setfacl command gives "Operation not permitted.".
My question is, who can grant privileges using setfacl, and how can I let users of group admins-web22 change permissions (for apache-web22) themselves?
I'm running Debian Wheezy and it's an ext4 partition if it's important.
|
The setfacl manual page explains who can grant privileges:
The file owner and processes capable of CAP_FOWNER are granted the right to modify ACLs of a file. This is analogous to the permissions required for accessing the file mode. (On current Linux systems, root is the only user with the CAP_FOWNER capability.)
So fred can only use setfacl on files he owns. Depending on your exact security requirements, you may be able to allow members of admins-web22 to run setfacl as apache-web22 (using sudo), which would allow them to change the ACLs on files owned by apache-web22....
| Who can change ACL permissions? |
1,455,517,269,000 |
I'm trying to debug a program which is not logging the information I need. Fortunately, it does write temporary files which should contain the information. These files are written to a directory like: program/temp/{someGUID} on one of ten machines. Neither {someGUID} nor which machine will contain the temp files is known in advance of the run. After the run is complete, the temporary files are deleted. The time from beginning to end is too fast for manual intervention.
I kick off the runs through a client program, but it is the server which writes the files. I am unable to manipulate the server program and once a run is kicked off I am unable to stop it. I do have root access to the all the machines on which the temp files could be written. I'm running CentOS 6.
Is there a way to allow the server user to write files to the temp directory but not remove them? It would probably crash the run, but it would give me the information I need. Is there a way to copy the contents of the temp folder right after they are written/before they are deleted? Must I install a program for recovery of deleted files?
|
List the files accessed by a program mentions several ways to log the program's file accesses (strace, LD_PRELOAD, LoggedFS, audit), but no convenient way to grab the file contents.
A convenient way to save all the program's output is copyfs. CopyFS creates a view of a directory tree that retains all past versions of all files that ever existed in that directory tree. Note that it can be used without root access. Mount the directory containing the temporary files:
mkdir versions
copyfs-mount $PWD/versions $PWD/program/temp
program_to_debug
fusermount -u program/temp
ls versions
| View temporary files which exist for milliseconds |
1,455,517,269,000 |
I've just installed Devuan GNU/Linux chimaera, and a bunch of packages manually. Also installed python-is-python3.
I now run, for example:
pip install pymonetdb
and I get:
Defaulting to user installation because normal site-packages is not writeable
Collecting pymonetdb
Downloading pymonetdb-1.6.2-py2.py3-none-any.whl (74 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 74.6/74.6 kB 867.9 kB/s eta 0:00:00
Installing collected packages: pymonetdb
Successfully installed pymonetdb-1.6.2
I'm wondering why I'm getting the message about site-packages not being writeable. Is it because I'm not the root user? But if that's the case, it shouldn't even try to write to some root-only folder. And if it's not because I'm non-root - what directory has inappropriate permissions, for me to fix (or have the root user fix)?
|
I'm wondering why I'm getting the message about site-packages not being writeable.
It's because pip defaults to trying to install to the system-wide directories ("site-packages").
Is it because I'm not the root user?
Yes.
But if that's the case, it shouldn't even try to write to some root-only folder.
Indeed, it should not: It knows it's run by a non-root user, and knows it will therefore almost certainly fail, and should thus not default to trying to install to user-specific directories in this case (if not always). But - it still does try and fail and complain, which is silly, but that's what the developers thought they should be doing for some reason.
You could avoid the warning by running it like so:
pip install --user some_package_name
... but IMHO what should really happen is for someone to file a bug report about this and lean on the developers not to try and fail.
| Defaulting to user installation because normal site-packages is not writeable |
1,455,517,269,000 |
If you look at the permission set of the passwd command, you will see this:
user@apple:~$ ls -l /bin/passwd
-rwsr-xr-x 1 root root 59976 Nov 24 2022 /bin/passwd
/bin/passwd has the SUID bit set and its owner is the root user. This means running the command passwd will run the command with the permissions of the root user.
Given that passwd already has root user privileges, why does it say this when I try to change the password of another user, test:
user@apple:~$ passwd test
passwd: You may not view or modify password information for test.
Running the same command, but with sudo, lets me change the password though. Why is that?
|
In this particular implementation the passwd command needs to run as the root user to be able to change anyone's password.
The passwd application has a piece of code that checks whether you are the root user or not, and if not then it refuses to let you change anyone else's password. If you are root, then you can change anyone's password.
For example, if you are logged in as alice, and run passwd bob then although the code will run as root it will refuse to let you change bob's password. However, if alice runs sudo passwd bob then because the sudo command runs its arguments as root rather than as alice, the passwd application will let you change anyone's password.
Lines from src/passwd.c, obtained (on Debian) with apt source passwd:
static bool amroot; /* The caller's real UID was 0 */
…
/*
* The program behaves differently when executed by root than when
* executed by a normal user.
*/
amroot = (getuid () == 0);
…
/*
* If the UID of the user does not match the current real UID,
* check if I'm root.
*/
if (!amroot && (pw->pw_uid != getuid ())) {
(void) fprintf (stderr, _("%s: You may not view or modify password information for %s.\n"), Prog, name);
SYSLOG ((LOG_WARN, "%s: can't view or modify password information for %s", Prog, name));
closelog ();
exit (E_NOPERM);
}
| Why should I use `sudo` with the `passwd` command to change the password of another user? |
1,455,517,269,000 |
I'm using Amazon Linux. I have set global read permissions on a file, but I can't seem to access it as a normal user:
[myuser@mymachine ~]$ ls -al /usr/java/jboss/standalone/deployments/myproject.war/css/reset.css
ls: cannot access /usr/java/jboss/standalone/deployments/myproject.war/css/reset.css: Permission denied
[myuser@mymachine ~]$ sudo ls -al /usr/java/jboss/standalone/deployments/myproject.war/css/reset.css
-rwxrwxr-x 1 jboss jboss 771 Oct 29 18:51 /usr/java/jboss/standalone/deployments/myproject.war/css/reset.css
[myuser@mymachine ~]$ whoami
myuser
Notice that when I run "sudo" I am able to access it. I would like to keep the file owned by the jboss user. How can I get the file accessible to my (or anyone else's user) in read mode?
|
You need to check permissions of each element in the path, not just the file permissions. Each directory must have access 'x' (which means execute for files but traverse for directories) for the user wishing to run the command.
| Getting "Permission denied" even though I have set global read permissions on a file |
1,455,517,269,000 |
I have one IBM AIX server (serverA) which is connected to the san storage. I have created a volume group and also file system (jfs2) and mounted to directory /profit.
After that I created a NFS share for that directory and started the NFS daemon.
Over at another server, which is IBM AIX also (serverB), I created a mount point /profit and mounted the nfs share from serverA to serverB using the below command:
mount 192.168.10.1:/profit /profit
On serverB, I am able to access the directory and list the files in it. But the strange thing is, on serverA, the directory and files are under the oracle user ownership. But in serverB, i see them as a different user.
When I touch a file in that directory at serverB, on serverA, I see it as another user id.
Any clue how I can fix this?
Below is the file listing from serverB
$ ls -l
total 0
-rwxrwxrwx 1 root system 0 Mar 16 15:00 haha
-rwxrwxrwx 1 radiusd radiusd 0 Mar 16 15:19 haha2
-rwxrwxrwx 1 radiusd radiusd 0 Mar 16 15:31 haha3
-rw-r--r-- 1 oracle oinstall 0 Mar 17 2011 hahah3
drwxrwxrwx 2 radiusd radiusd 256 Mar 16 14:40 lost+found
On serverA it looks like below:
# ls -l /profit
total 0
-rwxrwxrwx 1 root system 0 Mar 16 15:00 haha
-rwxrwxrwx 1 oracle dba 0 Mar 16 15:19 haha2
-rwxrwxrwx 1 oracle dba 0 Mar 16 15:31 haha3
-rw-r--r-- 1 10 sshd 0 Mar 17 16:01 hahah3
drwxrwxrwx 2 oracle dba 256 Mar 16 14:40 lost+found
Below is the /etc/exports file from serverA
# more /etc/exports
/profit -vers=3,sec=sys:krb5p:krb5i:krb5:dh,rw
Thanks.
|
Remember that each of the NFS client systems will determine the username by looking up the numerical UID locally using the local system's /etc/passwd, or in your centralized user database. The NFS server only stores the UID in numerical format, and does not know about usernames. This is also true for group names vs. GIDs.
In your case, serverA and serverB must have different usernames listed in /etc/passwd
To test this, use ls -n to display user and group IDs numerically, rather than converting to a user or group name in a long (-l) output. If the ls -n option is not available on AIX, consult the manpage for this feature.
To see the username-to-uid mapping, do one of the following on both serverA and serverB.
grep $THEUSERID /etc/passwd
Or, it's a good habit to use getent, since it works with /etc/password, and directory services (LDAP, etc.):
getent passwd $THEUSERID
The UIDs should be the same on both systems, but the usernames will be different.
| Why is file ownership inconsistent between two systems mounting the same NFS share? |
1,455,517,269,000 |
My TeX Live installation has a file called .texlive2015 and was originally set to drwx------T. I changed it, and I want to change it back, but I can't get the 'T' back. How do I get it back?
|
This 'T' indicates the sticky bit. You can use something like chmod a+t to set it.
| How do you set the 'T' bit? |
1,455,517,269,000 |
I use dd a lot. I live in a contant fear of making a mistake one day, for example writing on sda (computer disk) instead of sdb (USB disk) and then erasing everything I have on my computer.
I know dd is supposed to be a power user tool but still, it doesn't make sense to me that you can basically screw your whole computer by hitting the wrong key.
Why ins't there a security measure that prevent dd from writing on the disk it gets the command from ? Not sure how anyone would do this on purpose.
Please note that I didn't tried this myself, I've only read about it, so I could be wrong about all that.
|
It's reasonable to ask why the dd command doesn't first check whether its target contains a mounted filesystem, and then prompt for confirmation or require a special flag. One simple answer is that it would break any scripts that expect to be able to use dd in this way, and that aren't designed to handle interactive input. For instance, it can be reasonable to modify the partition table of a raw device while a partition of that same device is mounted; you just have to be careful to only modify the first sector.
There are a huge number of Linux systems out there in the wild, and it's impossible to know what kind of crazy setups people have come up with. So the maintainers of dd are very unlikely to make a backwards-incompatible change that would cause problems for an unknown number of environments.
| Why is dd not protected against writing on the active disk ? |
1,455,517,269,000 |
When I create a file, the permission is 644 (user rw, group r, other r).
How can I make the default file generated to have permission as 664?
|
There is a process flag in Unix/Linux called umask, interpreted as an octal number it says which permissions to take off a newly created file. The flag is inherited by child processes. Setting it for the shell makes all processes started later to use this value.
Permissions as bits are 1 for x, 2 for w and 4 for r, which can be combined into an octal digit. For example, r-x is 4 + 1 = 5. There are 3 sets of permissions (user, group, others). So the 664 is rw-rw-r--.
When creating a "normal" file, base permissions are 666 (nicely daemonic, isn't it?), when creating an executable it is 777. From this the umask is taken off, 002 would give 664 for a regular file.
The shells have builtin commands called umask to set the umask. You can run them interactively, but most often they are executed in some startup file for the shell to make it permanent. In the case of bash(1), this should be done in ~/.bashrc. In Fedora it is set system-wide in /etc/bashrc.
Before changing the default setting, carefully consider implications, as relaxing permissions could allow undesirable access to your files. Allowing anybody in your group writing your files is risky!
| Set the default permission when creating a file |
1,455,517,269,000 |
How can I run chmod +x on the script I'm creating in vi/vim so that it is executable? I tried :r chmod +x % but it didn't work.
|
You need
:! chmod +x %
The ! is used to run your commands in a shell.
| Make script executable from vi/vim |
1,455,517,269,000 |
I am attempting to copy a file into a directory where my user account is not the directory owner but belongs to a group that is the directory group owner. These are the steps I have taken:
Create a group and add me to that group
stephen@pi:~ $ sudo groupadd test-group
stephen@pi:~ $ sudo usermod -a -G test-group stephen
stephen@pi:~ $ grep 'test-group' /etc/group
test-group:x:1002:stephen
Create a file and list permission
stephen@pi:~ $ touch example.txt
stephen@pi:~ $ ls -l example.txt
-rw-r--r-- 1 stephen stephen 0 Feb 9 10:46 example.txt
Create a directory, modify the group owner to the new group and alter permission to the directory to grant write permission to the group
stephen@pi:~ $ sudo mkdir /var/www/testdir
stephen@pi:~ $ sudo chown :test-group /var/www/testdir/
stephen@pi:~ $ sudo chmod 664 /var/www/testdir/
stephen@pi:~ $ sudo ls -l /var/www
total 8
drwxr-xr-x 2 root root 4096 Oct 31 12:17 html
drw-rw-r-- 2 root test-group 4096 Feb 9 10:48 testdir
Copy the newly created file into this directory
stephen@pi:~ $ cp example.txt /var/www/testdir/straight-copy.txt
cp: failed to access '/var/www/testdir/straight-copy.txt': Permission denied
To me, this should have been successful; I'm a member of the group that has ownership of this directory, and the group permission is set to rw. Ultimately, I want any files that are copied into this directory to inherit the permission of the parent directory (/var/www/testdir).
I can copy with sudo, but this does not inherit the owner or permission from the parent directory, nor does it retain the original ownership (probably as I'm elevated to root to copy):
Copy with sudo and list ownership/permission of file
stephen@pi:~ $ sudo cp example.txt /var/www/testdir/straight-copy.txt
stephen@pi:~ $ sudo ls -l /var/www/testdir/
total 0
-rw-r--r-- 1 root root 0 Feb 9 11:06 straight-copy.txt
Please is someone able to explain to me what is happening?
|
When you did:
sudo usermod -a -G test-group stephen
Only the group database (the contents of /etc/group in your case) was modified. The corresponding gid was not automagically added to the list of supplementary gids of the process running your shell (or any process that has stephen's uid as their effective or real uids).
If you run id -Gn (which starts a new process (inheriting the uids/gids) and executes id in it), or ps -o user,group,supgrp -p "$$" (if supported by your ps) to list those for the shell process, you'll see test-group is not among the list.
You'd need to log out and log in again to start new processes with the updated list of groups (login (or other logging-in application) calls initgroups() which looks at the passwd and group database to set the list of gids of the ancestor process of your login session).
If you do sudo -u stephen id -Gn, you'll find that test-group is in there as sudo does also use initgroups() or equivalent to set the list of gids for the target user. Same with sudo zsh -c 'USERNAME=stephen; id -Gn'
Also, as mentioned separately, you need search (x) permission to a directory be able to access (including create) any of its entries.
So here, without having to log out and back in, you could still do:
# add search permissions for `a`ll:
sudo chmod a+x /var/www/testdir
# copy as the new you:
sudo -u stephen cp example.txt /var/www/testdir/
You can also use newgrp test-group to start a new shell process with test-group as its real and effective gid, and it added to the list of supplementary gids.
newgrp will allow it since you've been granted membership of that group in the group database. No need for admin privilege in this case.
Or sg test-group -c 'some command' to run something other than a shell. Doing sg test-group -c 'newgrp stephen' would have the effect of adding only adding test-group to your supplementary gids while restoring your original (e)gid.
It's also possible to make a copy of a file and specify owner, group and permissions all at once with the install utility:
sudo install -o stephen -g test-group -m a=r,ug+w example.txt /var/www/testdir/
To copy example.txt, make it owned by stephen, with group test-group and rw-rw-r-- permissions.
To copy the timestamps, ownership and permissions in addition to contents, you can also use cp -p. GNU cp also has cp -a to copy as much as possible of the metadata (short for --recursive --no-dereference --preserve=all).
| Copying a file into a directory where I am a member of the directory group |
1,455,517,269,000 |
If for benchmarking purposes one has to use hdparm or dd directly on the device, I wonder what the correct way would be to do this safely.
Let's say the disk in question is /dev/sda:
root@igloo:~# ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 May 29 08:23 /dev/sda
brw-rw---- 1 root disk 8, 1 May 29 08:23 /dev/sda1
I really don't want to write to sda under any circumstances. So would it be advised to do chmod o+r /dev/sda* and run dd or hdparm on it as a normal user?
|
chmod o+r /dev/sda* is quite dangerous, as it allows any program to read your whole disk (including e.g. password hashes in /etc/shadow, if your root partition is on sda)!
There are (at least) two ways to do this more safely:
Add all users that need to read the disk to the disk group and run chmod g-w /dev/sda* to prevent write access for that group.
Change the group of /dev/sda* to a group that only contains the users that need to read the disk, e.g. chgrp my-benchmarkers /dev/sda* and prevent write access for this group with chmod.
Please note that the group and permission changes on device nodes in /dev are only temporary until the device in question is disconnected or the computer is rebooted.
One problem could be that hdparm needs write access for most of its functionality. You must check if everything you want works with read-only access.
EDIT: It looks like hdparm doesn't need write access. It rather needs the CAP_SYS_RAWIO capability to perform most ioctls.
You can use setcap cap_sys_rawio+ep /sbin/hdparm to give this capability to hdparm. Please note that this allows anyone who can execute hdparm and has at least read access to a device file to do practically anything hdparm can do on that device, including --write-sector and all other hdparm commands the man page describes as "VERY DANGEROUS", "EXTREMELY DANGEROUS" or "EXCEPTIONALLY DANGEROUS". Wrapper scripts might be a better solution.
If not you either have to give write access or write wrapper scripts that can be executed by your users as root using sudo rules.
| Giving read permissions to device file of disk |
1,455,517,269,000 |
I'm making a deb package to install a custom application. I changed all files/folders ownership to root in order to avoid the warnings I was getting during installation, and in Ubuntu all runs smoothly, as Ubuntu changes the ownership of the files/folders to the user installing the package.
But when I'm installing on Debian, root remains the owner. The application uses a folder to write data, and here is the problem. Running as a standard user, the app does not have permission to write on the folder.
Now, how should I deal with this problem? Should I make a post install script on the deb package, doing the chmod o+w? Should I package the directory already with those permissions set?
Or is there any way of setting the owner of the files to the user that installs the app automatically (like Ubuntu does)?
|
I'm not sure what the behaviour is in Ubuntu, but in general for a .deb package containing files or directories with non-standard permissions you need to ensure those permissions are set after dh_fixperms is run. If you're using a dh-style rules, you can do this as follows:
override_dh_fixperms:
dh_fixperms
chmod 777 yourfolder
or
execute_after_dh_fixperms:
chmod 777 yourfolder
You can also do this in a postinst:
if [ "$1" = "configure" ]; then
chmod 777 yourfolder
fi
but the rules approach is simpler (at least, I prefer doing that rather than relying on maintainer scripts).
| How to change folder permissions during package installation |
1,455,517,269,000 |
I logged in using my username ravbholua:
ravbholua@ravbholua-Aspire-5315:~$ echo $LOGNAME
ravbholua
I create file named a1:
ravbholua@ravbholua-Aspire-5315:~$ echo>a1
ravbholua@ravbholua-Aspire-5315:~$ ll a1
-rw-rw-r-- 1 ravbholua ravbholua 1 Oct 8 09:57 a1
As expected the above file has me (ravbholua) as owner.
Next I create a2 using sudo with echo command:
ravbholua@ravbholua-Aspire-5315:~$ sudo echo>a2
ravbholua@ravbholua-Aspire-5315:~$ ll a2
-rw-rw-r-- 1 ravbholua ravbholua 1 Oct 8 09:57 a2
The owner is me only, i.e. ravbholua.
Now I create a3 using sudo again but with vim command:
ravbholua@ravbholua-Aspire-5315:~$ sudo vim a3
ravbholua@ravbholua-Aspire-5315:~$ ll a3
-rw-r--r-- 1 root root 10 Oct 8 09:57 a3
Oh! how come the owner changes now. It's not me but root.
Why such variation with echo and vim!
It's a surprise that with change of commands how can the owner of the created file changes.
|
The second example runs echo under sudo, but the redirection happens under the original shell.
sudo bash -c "echo > a4"
| Who is file owner if the file is created using sudo command? |
1,455,517,269,000 |
I'm creating a server and client situation where i want to create a pipe so they can communicate.
I created the pipe in the server code with
mkfifo("fifo",1755);:
1 for only user that created and root to be able to delete it or rename it,
7 for give read, write and exec to user, and
5 for both group and other to only give them read and exec.
The problem is that later in the server code I open the fifo to read from it open("fifo",O_RDONLY); but when i execute it, it shows me an perror that denies me acess to the fifo.
I went to see the permissions of the pipe fifo and it says
p-wx--s--t so:
p stands for pipe,
- means the user has no read. I don't know how when I gave it with the 7,
s group executes has user. I don't how if i gave 1 so supposedly it should give to user and others the ability to only read and execute and others have t that was expected.
Do I have a misunderstanding of the permissions?
|
You cannot simply exec a binary from a pipe: Is there a way to execute a native binary from a pipe?. Also I don't think the sticky bit on executables is worth anything on modern systems.
I created the pipe in the server code with mkfifo("fifo",1755);
I went to see the permissions of the pipe fifo and it says p-wx--s--t so:
Your error is to have written the 1755 permission without the leading 0, which means that 1755 has been treated as a decimal instead of octal (1755 & ~022 = 03311 = p-wx--s--t; where 022 is your umask)
| Why doesn't mkfifo with a mode of 1755 grant read permissions and sticky bit to the user? |
1,455,517,269,000 |
I have a directory that have the r permission bit:
dr-------- 3 robert robert 4096 2017-12-17 03:47 dir
This directory has two files and one directory:
file 1.txt file 2.txt subdir
When I run the command ls dir (from the robert account), I get an error alongside the content of the directory:
ls: cannot access dir/file 1.txt: Permission denied
ls: cannot access dir/file 2.txt: Permission denied
ls: cannot access dir/subdir: Permission denied
file 1.txt file 2.txt subdir
Why does ls display an error even though it is able to display the contents of directory without any problem?
|
ls calls readdir() (or getdents()) on the directory itself, which amounts to "reading" the directory. I think some Unixes implement this as actual calls to read(), as if the directory was a file. That works, since you have read permission to the directory, but it only gives the names of the files.
In addition to that, ls often wants to find the types of the files (to show different types with different colors, or to put the trailing slashes and asterisks etc. with ls -F). But finding the type generally requires calling stat() on the files themselves, and that requires access (+x) permission to the directory, in the same way actually opening the files would require. And you don't have that.
| "ls" is giving a "Permission denied" error even though it worked? [duplicate] |
1,455,517,269,000 |
I have a strange issue with directory permissions.
From within a C++ app, I create a folder with:
mkdir( "foldername", 777 );
But I got into an issue when attempting to create a file in that folder, fopen() returned NULL, and errno told me Permission denied.
So I checked, and indeed, I had the following permissions on the folder that got created: dr----x--t
(The root folder has drwxrwxr-x)
I checked, and this unusual t means "temporary", but I have no clue on what that means.
chmod 777 foldername from the shell does the job and sets attributes to drwxrwxrwx, but I can't do it manually each time.
Question: any clue on what is going on ? Why doesn't my app correctly sets the folders attributes ? What is the meaning of this 'temporary' attribute ?
(system is Ubuntu 12.04)
|
t is not "temporary", it means that the sticky bit is set. From man ls:
t [means that the] sticky bit is set (mode 1000), and is searchable or executable. (See chmod(1) or sticky(8).)
The sticky bit is set here because you set decimal 777 (octal 1411), not octal 777 (decimal 511). You need to write 0777 to use octal, not 777.
You should also note that the ultimate effect of the mode argument to mkdir also involves ANDing against your umask. From man 2 mkdir:
The argument mode specifies the permissions to use. It is modified by the process's umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777).
I would suggest that if this affects you, you chmod after mkdir instead of using the mode argument.
A final word of warning: mode 777 is almost never what you really want to do. Instead of opening up the directory globally to all users, consider setting a proper mode and owner/group on the directory. If you need more complicated rules, consider using ACLs.
| Issue on created folder permissions: temporary flag |
1,455,517,269,000 |
Is there a way to protect a file in such a way that even root cannot delete it or rewrite it after creating it?
I have a file which is created by root under /var/log/ and I want to restrict all users (including root) so that they can just read this particular file after it has been created.
|
No there is no way to do this, to my knowledge. The answer about chflags pertains to BSD variants. A similar command for Linux is chattr.
http://en.wikipedia.org/wiki/Chattr
The concept of the root user is that they can do anything on the system.
| File protection in Unix |
1,455,517,269,000 |
I recently built a very simple test environment with openSUSE.
As I tried to configure a shared directory, without using ACLs, but with SetGID on that directory instead for some reason, I noticed that the default umask for every user is set to 022 (i.e. 755 on directories & 644 on files).
This is done in /etc/login.defs.
I am used to a umask 002 (i.e. 775 directories / 664 files) for normal users and 022 for the root-user instead.
Shall I change the umask value for useradd in the above mentioned file, if I want to set it as default for all future useradds and how can I change the umask for all existing users on my system (except the root account, of course)?
|
Answering the question in your subject: OpenSuSE uses the traditional Unix umask setting, instead of the Debian-inspired one adopted by some other Linux distributions.
Editing /etc/login.defs should be sufficient to change it; this will not affect users currently logged in, nor is there any way for you to force such a change to programs that are currently running. It will also not affect users who have overridden it in their ~/.profile (or .bash_profile, .login, etc. as per their shell).
useradd is not involved with this; it is a per-process setting and the default is set during login (hence login.defs and not /etc/default/useradd).
| Why is the default umask value for useradd in openSUSE set to 022? |
1,455,517,269,000 |
I've got a file on remote machine (saying that, cause I don't know who the heck created it), that I've to remove.
user@machine:~/folder$ ls
lift_proto.db.lock.db
And permissions are like this:
user@machine:~/folder$ ls -al
total 12
drwxrwxrwx 2 root root 4096 2012-03-06 20:57 .
drwxr-xr-x 26 user group 4096 2012-03-06 20:53 ..
-rw-r--r-- 1 root root 126 2012-03-06 20:57 lift_proto.db.lock.db
Trying to delete:
user@machine:~/folder$ sudo rm lift_proto.db.lock.db
And nothing happens:
user@machine:~/folder$ ls
lift_proto.db.lock.db
I've seen that question, but this doesn't helped a lot:
user@machine:~/folder$ lsattr
-----------------e- ./lift_proto.db.lock.db
Moreover, I've successively tried to change ownership of file to user and permissions to 777, but then I'm deleting that file and it is still here back with root ownership and old permissions.
My last guess that somebody somehow syncing that file from elsewhere (btw, is there any way to see that?), if not (e.g. you're seeing that there is something with attrs or etc), how can I delete that?
UPDATE 1:
-f flag of rm doesn't solve problem
UPDATE 2:
Here is the output of stat before and after:
user@machine:~/folder$ stat lift_proto.db.lock.db
File: `lift_proto.db.lock.db'
Size: 126 Blocks: 8 IO Block: 4096 regular file
Device: 900h/2304d Inode: 20054245 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-03-06 21:30:40.600796566 +0400
Modify: 2012-03-06 21:30:40.600796566 +0400
Change: 2012-03-06 21:30:40.600796566 +0400
user@machine:~/folder$ sudo rm -f lift_proto.db.lock.db
user@machine:~/folder$ stat lift_proto.db.lock.db
File: `lift_proto.db.lock.db'
Size: 126 Blocks: 8 IO Block: 4096 regular file
Device: 900h/2304d Inode: 20054245 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-03-06 21:32:36.621421452 +0400
Modify: 2012-03-06 21:32:36.621421452 +0400
Change: 2012-03-06 21:32:36.621421452 +0400
UPDATE 3
strace output
user@machine:~/folder$ sudo strace rm -f lift_proto.db.lock.db
execve("/bin/rm", ["rm", "-f", "lift_proto.db.lock.db"], [/* 14 vars */]) = 0
brk(0) = 0x8c9000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967443000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=42930, ...}) = 0
mmap(NULL, 42930, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967438000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\355\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1572232, ...}) = 0
mmap(NULL, 3680296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc966ea3000
mprotect(0x7fc96701d000, 2093056, PROT_NONE) = 0
mmap(0x7fc96721c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x179000) = 0x7fc96721c000
mmap(0x7fc967221000, 18472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc967221000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967437000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967436000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967435000
arch_prctl(ARCH_SET_FS, 0x7fc967436700) = 0
mprotect(0x7fc96721c000, 16384, PROT_READ) = 0
mprotect(0x60e000, 4096, PROT_READ) = 0
mprotect(0x7fc967445000, 4096, PROT_READ) = 0
munmap(0x7fc967438000, 42930) = 0
brk(0) = 0x8c9000
brk(0x8ea000) = 0x8ea000
open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2027984, ...}) = 0
mmap(NULL, 2027984, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc966cb3000
close(3) = 0
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc967442000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fc967442000, 4096) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=373, ...}) = 0
mmap(NULL, 373, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967442000
close(3) = 0
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26048, ...}) = 0
mmap(NULL, 26048, PROT_READ, MAP_SHARED, 3, 0) = 0x7fc96743b000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MEASUREMENT", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MEASUREMENT", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=23, ...}) = 0
mmap(NULL, 23, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc96743a000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_TELEPHONE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TELEPHONE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=59, ...}) = 0
mmap(NULL, 59, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967439000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_ADDRESS", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_ADDRESS", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=155, ...}) = 0
mmap(NULL, 155, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967438000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_NAME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NAME", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=77, ...}) = 0
mmap(NULL, 77, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967434000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_PAPER", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_PAPER", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=34, ...}) = 0
mmap(NULL, 34, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967433000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES", O_RDONLY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
close(3) = 0
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=57, ...}) = 0
mmap(NULL, 57, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967432000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_MONETARY", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MONETARY", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=286, ...}) = 0
mmap(NULL, 286, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967431000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_COLLATE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_COLLATE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1170770, ...}) = 0
mmap(NULL, 1170770, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967313000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_TIME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TIME", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2454, ...}) = 0
mmap(NULL, 2454, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967312000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_NUMERIC", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NUMERIC", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mmap(NULL, 54, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc967311000
close(3) = 0
open("/usr/lib/locale/en_US.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=256324, ...}) = 0
mmap(NULL, 256324, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc9672d2000
close(3) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
unlinkat(AT_FDCWD, "lift_proto.db.lock.db", 0) = 0
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
|
The file is an H2 file lock, from a lift-based (web) application. H2 uses an interesting file locking protocol, the file will be re-created pretty much immediately if that database is in use.
(The filename matches the default persistence database name for that framework.)
You need to stop whatever app server is running that database to get rid of that file if you want it gone. (But do you really?)
Your strace output clearly shows that the unlink is successful.
unlinkat(AT_FDCWD, "lift_proto.db.lock.db", 0) = 0
An inode number can be re-used. Filesystems could use whatever allocation strategy they want, but nothing prevents them from reallocating the same inode number.
On an idle ext3 filesystem:
$ touch a
$ stat -c %i a
593358
$ rm a
$ touch a
$ stat -c %i a
593358
$ touch a b
$ stat -c %i a b
593358
593362
$ rm a b
$ touch b a
$ stat -c %i a b
593362
593358
| Unable to delete file, even as root |
1,636,902,417,000 |
We are using LDAP authentication and probably another things that I did not understand well, in our company so maybe the following questions are result of this. I have found strange behavior of chown command, and I do not know if this is normal. Here is my scenario:
GID of user mark is SK001936 and owner grup of home dir of mark is SK001778, as you can see they are not the same.
The group SK001778 is allowed all operations (rwx) with home dir of user mark as owner (mark) has:
[mark@machine ~]$ id
uid=48447(mark) gid=41795(SK001936) groups=40119(SUB_SK001936_PPS),41795(SK001936)
[mark@machine ~]$ ls -lad .
drwxrwxr-x 6 mark SK001778 4096 Oct 10 13:30 .
GID of user michael and mark are both SK001936:
[michael@machine mark]$ id
uid=40570(michael) gid=41795(SK001936) groups=40119(SUB_SK001936_PPS),41795(SK001936)
[mark@machine ~]$ id
uid=48447(mark) gid=41795(SK001936) groups=40119(SUB_SK001936_PPS),41795(SK001936)
user michael cannot create file in home dir of user mark.
It is the matter of that michael do not belongs to group (SK001778) which has the full (rwx) access to mark's home directory:
[michael@machine mark]$ touch michael
touch: cannot touch `michael': Permission denied
Under normal circumstances the user cannot issue the chown even if he is the owner of the file.
However in this example the owner of home directory (mark) is able to change the owner group of his own home directory (and thus allows the users belonging to this group access to his home dir):
[mark@machine ~]$ chown mark:SK001936 .
The group which now has access to mark home dir is thus the same group as GID of michael, hence the michael is now allowed to create/delete files/folders in mark's home dir:
[michael@machine mark]$ touch michael
mark is unable to change back the group ownership of his home dir (remember only root is allowed to issue chown accoring to this: why-cant-a-normal-user-chown-a-file):
[mark@machine ~]$ chown mark:SK001778 .
chown: changing ownership of `.': Operation not permitted
My question is: how is possible that mark was able to change the group ownership of his home dir even when si declared that chown can be issued only by root. The box is RedHat 5.6.
|
When you use chown in a manner that changes only the group, then it acts the same as chgrp. The owner of a file or directory can change the group to any group he is a member of.
It works like that because both the chown and chgrp commands use the same underlying chown syscall, which allows changing both owner and group. The syscall is what applies the permission check. The only difference between the chown and chgrp commands is the syntax you use to specify the change you want to make.
Mark can't change the group back to SK001778 because he isn't a member of group SK001778 (and he isn't root, which isn't restricted by group membership).
| Seems that chown is allowed to non root user |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.