Linux is a multi-user operating system with multiple users accessing the same system. System administrators are responsible for preventing a user from accessing another user’s confidential files. For these reasons, Linux divides authorization into two levels, Ownership and Permission. Show File OwnershipEach file and directory has three kinds of owners.
Owners are denoted with the following symbols:
Change the Ownership with chownTo display the ownership of the file index.html in /var/www/html directory, run the following command: ls -l /var/www/html/index.html You should get the following output: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html As you can see, the group and user owner of the file is www-data. A basic syntax to change the ownership of the file is shown below: chown owner:group filename To change the owner of the file index.html to root and group to root, run the following command: chown root:root /var/www/html/index.html You can use the -R option with the chown command to change the ownership of the directory recursively. For example, to change the ownership of the directory /var/www/html to www-data as the user and www-data as the group, run the following command: chown -R www-data:www-data /var/www/html/ This will change the ownership of all files and directories located inside /var/www/html/. File PermissionsEach file and directory has three types of permission:
Permissions are defined using octal permissions. These are nine characters created in three sets of three characters: --- --- --- rwx rwx rwx user group other Each letter denotes a particular permission:
Permissions are also represented in numeric form as shown below:
You can also use mathematical operators to add and remove permissions.
Change the Permissions with chmodChmod stands for change mode, and it is a basic syntax used to change the permissions of the file: chmod permissions filename To check the permissions of the file, run the following command: ls -l /var/www/html/index.html Output: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html As you can see, the owner of the file has read/write permissions, the group has read permission and the other has read permission. To add execute permissions to the user, run the following command: chmod u+x /var/www/html/index.html Now, verify the permissions with the following command: ls -l /var/www/html/index.html Output: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html1 To add write permissions to group and others, run the following command: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html2 Now, verify the permissions with the following command: ls -l /var/www/html/index.html Output: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html4 To remove the write permissions from others, run the following command: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html5 Now, verify the permissions with the following command: ls -l /var/www/html/index.html Output: -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html7 You can also set the permissions using the octal value. You can use the following values for each permission: 777 = rwxrwxrwx 765 = rwxrw-r-x 654 = rw-r-xr– For example, change the permissions of the file so that the user can read/write and execute, the group can read and execute and the others can only read the file. -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html8 Or -rw-r--r-- 1 www-data www-data 11510 Feb 3 20:25 /var/www/html/index.html9 ConclusionIn the above guide, you learned how ownership and permissions work in Linux. You also learned how to set and change the ownership and permissions of the files and directories. I hope you have now enough understanding of file ownership and permissions – try it today on your Linux VPS. What 3 types of file permissions are there in Linux?The Permission Types that are used are:. r – Read.. w – Write.. x – Execute.. What are the 3 types of permissions?Permission Types
Files and directories can have three types of permissions: read, write, and execute: Someone with read permission may read the contents of a file, or list the contents of a directory.
How many file permissions are there in Linux?File Permissions. All the three owners (user owner, group, others) in the Linux system have three types of permissions defined. Nine characters denotes the three types of permissions.
What are the different file permissions?There are four categories (system, owner, group, and world) and four types of access permissions (Read, Write, Execute and Delete).
|