Linux Commands - Part 3

Suhail KhanSuhail Khan
2 min read

File Owner Ship

Change user ownership of a file

To check the owner of the file use command

ls -l

Here the owner of the file is skna user. Now let's change the owner using the chown command which takes the chown owner_name filename this will change the user ownership of the file. This command requires superuser permission

chown test file1.txt

Change Group Ownership of the file

In the above image, the group ownership of the file is to group skna now let's change it to demo using the same chown command which takes chown :group_name filename after colon just give the name of the group you want to change the ownership to.

chown :demo file1.txt

Changing User and Group Ownership of the file in one command

Now we will combine both the above and use it as a single command to change the user and group ownership of the file i.e chown user_name:group_name filename

We will change back the user and group ownership of the file to skna.

chown skna:skna file1.txt

Access Control Lists of a File or Directory

Viewing the access control list of File or Directory

Now let's see the access control list of our file or directory using the command getfacl filename/directoryname .

getfacl file1.txt

Setting an Access Control List

Now let's set the access control list for user test with read and write permission using command i.e setfacl -m u:user_name:rw- filename here u stand for user and -m stands for modify.

setfacl -m u:test:rw- file1.txt

You can see the output of ls -l command in which file1.txt has '+' sign after other permissions which means the access control list is set for that file.

And in the output of getfacl file1.txt you can see that the user test is added to the access control list with read and write permission.

Now let's set the access control list for the group demo with read permission using the command i.e setfacl -m g:group_name:r-- filename here g stands for a group

setfacl -m g:demo:r-- file1.txt

We can see that group demo is added to access control list with read permissions only.

1
Subscribe to my newsletter

Read articles from Suhail Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suhail Khan
Suhail Khan