As per the title, I have to create a file, for example:
/home/john/file.ini
I created a user and a group, myuser
and mygroup
, and set them to be the owner and group of this file.ini
:
chown myuser:mygroup file.ini
I have another user named mymain
. This user must be able to read this file. How can I change the permissions to allow this?
Important: I want to allow only the "mymain" user to read this file, NOT all other users.
So myuser (the owner of the file) and mymain should have access.
Best Answer
In the traditional Unix file permission system that's not possible: a file has only a single owner. You could create a group containing just the two users that should have access and make that the owning group of the file (and give the desired permissions to that group). This approach has some administrative overhead, however (not every user can create a group and place other users in it).
Many (most) modern filesystems support ACLs, however and they aren't too hard to use. If you want to use POSIX ACLs to give another user read (
r
) and write (w
) permissions then you can use this command:Two caveats:
acl
package (sudo apt-get install acl
)ext4
, for example, that simply means appending,acl
to the mount options in/etc/fstab
).