Linux permissions
Linux has a comprehensive permission system to ensure that the computer is secure. Each file and directory has three groups of permissions: owner, group and all users. Each of these groups has three types of permissions: read write and execute. Using the right permissions is a necessity for servers and other devices connected to the internet.
Groups
There are three different groups:
- owner - The permissions for the owner apply to the owner of the directory or file.
- group - The permissions for group apply to a specified group.
- other - The permissions for other apply to all other users.
Types
Each of these groups has three basic permission types:
- read (r) - This permission allows the user to read the contents of a file.
- write (w) - This permission allows the user to write or modify a directory or file
- execute (x) - This permission allows the user to execute a file or to view the contents of the directory
The permission of a file or directory is given with three numbers: owner, group and other respectively. Each of these numbers contains the read, write and execute permissions. The execute permission is represented by the number 1, the write permission by the number 2 and the read permission by the number 4. These numbers are summed up to form one digit. For example, if we want to combine a read and execute permission, the number would be 1 + 4 = 5.
Change permissions
The permissions can be altered by the chmod, chown and chgrp commands.
The permissions are changed with the chmod command. The chmod command expects at least two arguments: the three digit code and the name of the file.
chmod 777 file.txtSelect
The owner of the file is changed with the chown command. This commands also expects at least two arguments: the name of the new owner and the name of the file.
chown user file.txtSelect
The group of the file is changed with the chgrp command. This commands also expects at least two arguments: the name of the new group and the name of the file.
chgrp mygroup file.txtSelect
The -R option applies the command recursively:
chmod 644 mydirectory -RSelect