Updated May 31, 2023
Introduction to Unix File Permissions
A security system designed in UNIX. Considering the multi-user operating system nature of UNIX allows multiple users to access the system simultaneously. Rendering the system vulnerable to external threats that may cause damage to the system and lead to misleading information, corrupting the data is termed as UNIX File Permissions. A concept that is very important and tremendously crucial to grant access to various users appropriately so that there’s no misuse on the user’s part, thus providing security to users of the system whose access to the system is regulated.
Unix File Permissions
Every file in Unix can have 3 types of owners.
They can be as below:
- User: A user is the default person who creates the file. This is the real owner of the file and has full rights and permissions to the created file.
- Group: A group can have many users included in it. The users in a group will have similar permissions for all the files to which the group has access. For example, if a project needs a particular group of people to access, you can add all these users to a group and then give them similar permissions. This can only read or read and write permissions. It saves the time of giving access to each user separately when similar accesses are to be given.
- Other: These users need access to a file though they are neither the owner nor a group member. This can be anybody else who needs access to some particular work. The permissions thus play an essential role in this case.
Permissions
A file can have three kinds of permissions. All three permissions can be given to all three types of owners based on the type of owner.
- Read: By assigning this kind of permission, you are giving a user the authority to open and read the file’s contents. You can see all its contents but do not have permission or rights to make any changes.
- Write: The write permission lets the user modify the file’s contents. By applying this, the user can read, modify, add, remove, and rename the files stored in a directory. Suppose a user has to write access to a file. The user can modify the file. They can also remove or rename any files if they wish to.
- Execute: An executable file on Windows can be easily run with its .exe file. But when it comes to Unix, a program cannot run until it has the execute permission. If your user id does not give the appropriate execute permission, you will not execute it. You can still modify or read the contents of the file.
Changing Permissions
To change the permissions of a file or directory, you can use the Chmod command. You can change the permissions in two ways. It is the symbolic mode and absolute mode.
Chmod in Symbolic Mode with Examples
If you are a beginner, this is the easiest way to change the file’s permissions. With this method, you can add, delete or specify the permission, which you can set as required.
- ‘+’: This adds the specified permissions to the intended file or directory.
- ‘-‘: This removes the specified permissions to the file or directory which is intended.
- ‘=’: This sets the specified permissions.
- ‘r”: This indicates read.
- ‘w’: This indicates you write.
- ‘x’: This indicates execute.
- ‘-‘: No permission.
Let us take an example:
- -rw-rw-r—as830b home
Here the first ‘-‘ indicates that we are selecting a file.
Adding a “d” at the beginning, such as “drwxr,” indicates that the given permissions are for a directory.
- -rw-rw-r—as830b home
The first part -rw suggests that the owner as830b can read and edit the file, but the user does not have to execute access since the access is set to ‘-‘.
The second part, rw-means that the user as830b can only read, write, or make changes to the file.
The third part, r- -, means the user can only read the file.
Chmod in Absolute Mode with Examples
When you are using this mode, you have to make use of the three-digit octal number. This means this corresponds to below:
- 0: Permission denied —
- 1: Execute –x
- 2: Write -w-
- 3: Execute and Write -wx
- 4: Read r – –
- 5: Read and execute r-x
- 6: Read and write rw-
- 7: Read and write and execute rwx
When you give the command “chmod 764 file.txt,” it grants the owner the permissions to read, write, and execute. The user group can read and write, while others can only read the file. Similarly, if the command changes to chmod 777 file.txt, the user can read, write and execute. The people in the user group can also do the same. In addition to this, the world will be able to make changes, edit and execute.
The owners can also be denoted symbolically as:
- U: user/owner
- G: group
- O: other
- A: all
You can use it as “chmod o=rwx file.txt,” which sets the permissions for others to read, write, and execute. Adding execute to the user group to execute can be set by using: chmod g+x file.txt.
Conclusion
Unix is a multiuser system that needs setting up permissions and ownership to files from a security perspective. It defines three user groups and provides three types of permissions that can be set as needed. This can be for any group or user which needs the specified permissions. The command ‘chmod’ enables setting and changing user and group permissions. This helps in ensuring that only authorized people see the contents. Thus, Unix maintains security and enables multiple users to access the data simultaneously.
Recommended Articles
We hope that this EDUCBA information on “Unix File Permissions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.