Find the list of instructions to control file access using file permissions in Ubuntu. Learn how to set permissions for users and groups with chown commands.
- Laptop/PC with Ubuntu OS installed
- Active Terminal
If you don’t have Ubuntu on your Laptop/PC and if you feel to install it, then please refer to this blog
In any project, all files may not have access to every developer, some authenticated files could have access only for the project manager. So for a well-organized project, the admin needs to set the permissions to protect the project data. Here is a clear explanation of how the file permissions work.
We can change the permissions in two methods,
- Numeric method and
- Symbolic method
1. Numeric Method
In this method, we have numbers from 0 to 7, and for every number, there is permission status. Look below the table for detailed information.
|0||No permission for anyone||-|
|3||Execute + Write||-wx|
|5||Read + Execute||r-x|
|6||Read + Write||rw-|
|7||Read + Write + Execute||rwx|
So with the combination of the above numbers, we can change the permissions for a file in this format user group others.
From the above screenshot consider the first permission, that is drwxr-xr-x 2 krishna krishna 4096 Nov 14 18:44
In the above diagram, you can see the division of different roles like user, others, and group. So with the combination of numbers in the above table, we can change the permissions.
Now we will give all the permissions for all the rolls to the user Krishna so that anyone can access the files and do the operations.
From the above table, the number that has been used to give all the three permissions is 7, now for all the rolls give the number 7 with the help of below command.
Command: chmod [user][group][others] fileName/userpath
So for our condition, the command is chmod 777 /home/krishna
The above code says that
The owner can read write and execute
User and group also can read write and execute
The world also can read, write and execute.
So this type of permission is not allowed for all types of files.
If you can observe the above screenshot, for the user krishna, the permissions have changed like this drwxrwxrwx 2 krishna krishna 4096 Nov 14 18:44 .
So if the user wants to protect his files from other people, he can change the permissions. In the above example, we have seen how to change the permissions for users, the same steps for files and directories also.
If you observe the below screenshot, the user navya is the admin of the current computer, that user has all the permissions and the user krishna is the created user by the user navya, the user krishna has respective given permissions.
So now, the project folder has access only for the user krishna but not the user navya, the user navya can only read the file and is unable to do any actions in the project folder.
2. Symbolic Method
The purpose of the symbolic method is also for changing the file/folder permissions but in a different way like using symbols.In symbolic mode, the available operations and available roles are
|+-> Adds permissions
- -> Removes permissions
|u -> user/owner
g -> group
o -> others
a -> all
|-x -> execute
-w- -> write
r- -> read
The command is chmod [role]= symbols+operations fileName
The symbolic code to change the group permissions for the available folder is chmod g+x folderName
Just observe the file permissions of the folder project, the user permissions have been updated like this drwxr-xr-- 2 navya navya 4096 Nov 16 08:04 project.
Finally, I want to conclude that, to protect the files from corruption or loss of data in the project we have to restrict the access of files/folders. So with these simple commands, you can update the permissions accordingly.
Is it possible to change the user of the file?
Yes, you can change the user of the file with the following command chown userName fileName/folderName.
Is it possible to change both the user and group of the file?
Yes, you can change the user of the file with the following command chown userName:groupName fileName/folderName
Can a created user login to the system and save files?
Yes, the user can log in with the respective credentials and save the files as he has respective permissions.