Setting permissions for specific user and groups in Linux

How can I grant permission for files to a specific user or a specific group?

We have three groups: "g12" ("u1" and "u2), "g34" and "g56".

  • g12 - should only read the file.

  • g34 - should write and read it.

  • g56 - should have all permissions (rwx).

And others should not access the file at all.


You need to use Access Control Lists. They are a more advanced way of handling permissions than the default user/group/other way in Linux. See this page for example: Ubuntu Access Control Lists

An example from that page:

setfacl -m u:mike:rwx file or directory

I've only used these commands in a lab on an server adminstration course myself, but as far as I could see, it's a pretty easy way to do it.


As root:

chown u1:u1 f1.txt
chmod 400 f1.txt

This will ensure that the file is owned by user u1 (chown) and group u1 (assuming that user u1's default group is u1) and that only that user can read the file (chmod). If you would like the user to be able to write to the file, change 400 to 600.

You can add a second user to the default group of the first user with:

useradd -G u1 u2

The above command assumes that user u1's default group is also called u1 and the second user is u2.

Now we change the permissions on f1.txt to allow members of group u1 read access (the second "4" in 400 is group permissions):

chmod 440 f1.txt

Each of the three digits following the chmod command represents the permissions for the owner (first digit), the group (second digit), and all other users (third digit) on the system. A value of 1 is the execute permission, 2 is the write permission and 4 is the read permission. You add add these numbers together to "mix" these three types of permissions. Example, 4 (read) + 1 (execute) = 5, so to allow the owner and the group to read and execute the file but restrict access to everyone else you would use 550, to allow the owner to read and write to the file and the group and all other users to read the file, you would use 644.

There are other formats to setting permissions, type:

man chmod

at the command prompt for more details.


short answer is, you can't

you don't set permissions for groups or users, you set permissions for files. A file has an owner and a group, and you can set the "read" "write" and "execute" permissions seperately for one user, one group, and everyone else.

Can you give an example of what it is you're wanting to do?