Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give file permission to a specific user in a Group?

I have a Group 'g1' having 2 users Alice and Bob. I want to share a file 'file1' with both of them with different permissions.(for Alice read only and for Bob Read+write)

like image 625
Vijay Avatar asked Oct 12 '13 17:10

Vijay


People also ask

How do I give permission to specific users?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.

How do I chmod to a specific user?

To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.

How do I give permission to a folder in Linux for a specific user?

You can set permissions like read, write, or execute the folder through the “chmod” command in a terminal. You can use the “chmod” command to modify permission settings in two different ways: Absolute Mode (numeric mode) Symbolic Mode.


1 Answers

Assuming Bob can own the file the following should work for you.

$ chown Bob:g1 file1

First set the ownership of the file to Bob to allow for read+write access and set the group ownership to the g1 group.

$ chmod 640 file1 

Set the owner to a read and write and set the group to read only. This is a common permission structure on webservers. Note that the "world" has no permissions in this structure, but $ man chmod can provide further information on file permissions and get you where you are needing to go. Additionally if you need more control over your permissions across the whole system you may want to look into Posix ACLs or SE Linux as you did indicate you are on RedHat

like image 57
MattSizzle Avatar answered Nov 22 '22 11:11

MattSizzle