Assign permission using the symbolic method

Hello everyone In this Article we are going to learn How to assign permissions to files and directories in Linux using the symbolic method in a very simple and easy step-by-step approach

Assign permission using the symbolic method

Assign permission using the symbolic method

When root user makes the directory as

# mkdir /Directory

To view the permission of the directory we can execute ls command with the -ld options command

# ls -ld /Directory
Screenshot 5 4
  1. d – denote that it is a directory
  2. rwx – This Field denotes the owner of the folder. eg -The user who made this folder.
  3. r-x – Group permission on the folder eg. the users who are inside of the root group having this permission.
  4. r-x – other permission – User who made folder instead of that user everyone else comes in other category of permission.
  5. ( . ) tell ACL permission if there is ( + ) instead of ( . ) then ACL (Access Control List ) is added on this folder
  6. The number of links to the directory here number of links is 1.
  7. Owner of the directory
  8. Group owner of the directory
  9. Size of the directory
  10. Creation of Date and Time of the directory
  11. Name of the directory.

We can change ownership to other users as well ex. harry user after giving the ownership to harry user he can able to read and execute the file.

We have created one user name as harry let’s se what are the operations we can perform on /Directory/ do when user harry is logged in

As we can see from above that another user has r-x permission soo user harry will able to list the content of the directory by using ls command and can able to go inside the directory by using cd command but cannot able to make anything inside the /Directory/

User harry is able to List the content

Screenshot 1 4

User harry is able to go inside the /Directory/ directory using cd command

Screenshot 2 4

User harry cannot able to create any file or directory inside the /Directory/

Screenshot 3 5

When root Create makes the file as

# touch /File.txt

# ls -l – To view the permission of the file we can execute the ls command with the -l option command.

Screenshot 6 4

Total is 11 attribute to read the permission

  1. ( ) It means that this is a file
  2. rw- This Field denotes the owner of the file. eg -The user who made this file.
  3. r- – Group permission on the file eg. the users who are inside of the root group having this permission
  4. r- – Other permission – User who made folder instead of that user everyone else comes in other category of permission.
  5. ( . ) tell ACL permission if there is ( + ) instead of ( . ) then ACL (Access Control List ) is added on this file
  6. The number of links to the file here number of links is 1.
  7. Owner of the File
  8. Group owner of the File
  9. Size of the file
  10. Creation of Date and Time of the file
  11. Name of the file.

We have created one user name as harry let’s se what are the operations we can perform on /File.txt/ do when user harry is logged in.

As we can see from above that other user harry has ( r– ) permission

Soo user harry will able to view the content of the directory by using the (cat) command and cannot able to edit any file and cannot able to run the file as a script.

Screenshot 4 5

But the harry user cannot able to write anything on file

Screenshot 5 5

User harry cannot able to execute the /File.txt file as a script

The root can do anything on file and folder because it is a superuser in respect of permission..

How to add or remove permission from files and directories

We can use chmod command with the o+r then we can give the write permission to the other user on /Directory/

# chmod o+r /Directiory/ 
Screenshot 9 3

We can use chmod command with the o-r then we can remove the read permission to the other user on /Directory/

# chmod o-r /Directory/
Screenshot 8 3

How to assign the permission using the chmod command.

To assign the permissions in linux we can use different methods as below

Assign permissions on owner of the files/directory

  • To change the permission for the owner of the directory/file to the read permission then we can use u+r option in chmod command where u is for permission for the owner of the file/directory.
#chmod u+r /Directory-File 
  • To change the permission for the owner of the directory/file to the write permission then we can use u+w option in chmod command where u is for permission for the owner of the file/directory.
#chmod u+w /Directory-File 
  • To change the permission for the owner of the directory /file to the execute permission then we can use u+x option in chmod command where g is for permission for the group owner of the file/directory.
# chmod u+x /Directory-File

Assign permissions on group owner of the files/directory

  • To change the permission for the group of the directory/file to the read permission then we can use g+r option in chmod command where g is for permission for the group owner of the file /directory.
# chmod g+r /Directory-File
  • To change the permission for the group of the directory/file to the write permission then we can use g+w option in chmod command where g is for permission for the group owner of the file/directory.
# chmod g+w /Directory-File
  • To change the permission for the group of the directory/file to the execute permission then we can use g+x option in chmod command where g is for permission for the group owner of the file/directory.
# chmod g+x /Directory-File 

Assign permissions to other users of the files/directory

  • To change the permission for the other user of the directory/file to the read permission then we can use o+r option in chmod command where o is for permission for the other user of the file/directory.
# chmod o+r /Directory-File 
  • To change the permission for the other user of the directory/file to the write permission then we can use o+w option in chmod command where o is for permission for the other user of the file/directory.
# chmod o+w /Directory-File 
  • To change the permission for the other user of the directory/file to the execute permission then we can use o+x option in chmod command where o is for permission for the other user of the file/directory.
# chmod o+x /Directory-File 

How to give permsiion on other way

  • # chmod u=rwx /tutdevops/ – setting the new permission on user and replacing the exiting permission on file / folder
  • # chmod g=rwx /tutdevops/ – setting the new permission on group and replacing the exiting permission on file / folder
  • # chmod o=rwx /tutdevops/ – setting the new permission on other user and replacing the exiting permission on file/folder

If we want to assign the permission only to harry the user, not to any other user then we can do this task in 2 ways.

1 – Add the harry user to the root user group then automatically all the permission that is assigned to the root group user is applied to the harry user also.

Right now harry user can only execute the folder

harry cannot able to make the File inside /Directory.

Screenshot 10 3

Now we want harry user to do create and execute into the folder.

To do this task just add the harry user in a root group .

The permission on the /Directory is as follow for the root group

Screenshot 14 1

#usermod -G root harry – With the help of this command user harry will be added to the root user group and get the same permission as the root group had.

Screenshot 11 3

Now harry user can able to make the file inside of directory .

Screenshot 13 1

Second method too assign harry user as read permission

2. – Create one new group and make that created group as a group owner of /Directory1/ and add user harry to a new group then also we can assign the permission only to the harry user only.

# groupadd newgroup – With the help of this command we can add the group in linux system.

How to change group owner of the file/directory

With the help of chgrp command we can change the group owner for the File/Directory

# chgrp newgroup /Directory1/ 

Where newgroup is the name of the new group that we created

#ls -ld /Directory1/ – This command is use to list the permission on /Directory1/

Screenshot 15 1

# usermod -aG newgroup harry – With the help of this command we can add harry user to the newgroup that we created now the harry user had the same permission what is assigned to newgroup

Screenshot 16 1

Now what ever the permission that is assign to the newgroup that is assign to harry user as well

How to change owner of a File/Directory

With the help chown command we can change the owner of file/folder.

 # chown harry /Directory
Screenshot 17 1

How to change Owner and group in single command

To change the Owner and group for a file/directory in a single command then we can execute the below command.

#chown root:root /Directory1/

Screenshot 18 1

Conclusion

If you want to learn Linux in the most simple language then please click on this link.

This is the complete Introduction of how we can add and remove permissions from files and directories in Linux and what are the permissions are there in the Linux kernel if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on DevOps Articles

Leave a Comment