Introduction
Linux is by far the most widely used corporate operating system. While administering a Linux machine or a Linux-based corporate PC housing multiple users, you might encounter situations where you have to control those users. Managing user permissions is a distinctive feature that Linux caters to its system admins. If you are new to Linux or manage user groups, this article will give you a crisp idea of how to use them. First thing first, let us understand what a Linux user is and what is group permission?
What are Linux Users?
All Linux and Unix systems can perform multitasking like other operating systems. Yet, there is a significant distinction between Linux and other operating systems. It's the concept of multiple users. Linux can render access and use its system resources to multiple users simultaneously. Thus, to sustain this multiuser design structure and make it work, we must incorporate some protection techniques.
What are file permission and group permission?
Multiple users share the same operating system. So, to protect the files and maintain proper accessibility, permissions play a significant role. Linux allows its users to add file permission for reading, writing, and executing a file.
A Linux group contains many users. These organizational units help in administering and organizing different user accounts. Through Linux groups, users can set certain privileges to read, write, and execute permission on specific resources shared between users in the Linux group.
Types of groups in the Linux Operating system
Linux comes with two different variations of groups. These are –
· The Primary Group: As soon as the user creates a file, its group gets assigned as primary. In this case, the group name remains the same as the username. It stores all its relevant information in the /etc/passwd file.
· The Secondary Group: This group is for those users with whom you want to share specific files by granting permissions. You can set the permissions to the group members only.
Reading, Writing, and Executing Permissions in Linux –
To give the permissions to the groups, one needs to have a clear idea of the various permission rights available for files or directories.
· Read permission: This permission allows a file to open for readability purposes only. Through this permission, users can only view the data without altering it. If a directory has permission to read, the user can only list the directory content.
· Write permission: This permission allows the user to modify any content from the file. If this permission is available with the directory, it will permit the user to edit the directory's content.
· Execute: It is powerful permission that authorizes the user to execute any script or program. If this permission is available with the system directory, users can switch to different locations - making it a current directory.
How to View File Permissions –
Sometimes it becomes essential to check the permission mode of the file in Linux. In such a situation, users can view the directory or file permission using the command:
ls -l < file/directory>.
How to create a group?
Creating a new group is easy. Use the 'groupadd' command along with the name of the group. The command syntax will look like this:
$sudo groupadd groupname
Add an Existing User to a Group –
You might encounter a situation where adding a user to a secondary group will make the group work on a single project or run a single program. In such a situation, you have to use the command 'usermod -a -G', along with the group and username.
The command syntax will look like this:
$ sudo usermod -a -G groupname username
Example,
$ sudo usermod -a -G devops karlos
Adding an Existing User to Multiple Groups –
A situation might arise where you might need to add a particular user to a handful of secondary groups. You can use a single command to perform this. You can do this by implementing the 'usermod' command served with a -G option. Also, you have to mention all the group names with a comma separating them.
The command syntax will look like this:
$ sudo usermod -a -G group1,group2,group3 username
Example,
$ sudo usermod -a -G devops,sudo,docker karlos
Remove a User from a Group –
You can use the 'gpasswd' command served with the -d option to remove a user from a secondary group. The command syntax will look like this:
$ sudo gpasswd -d username group
Conclusion
Linux is one of the most secure OS. Linux admins have the privilege to set rights and permissions for each user sharing the OS resources. The commands shown here are applicable for different distributions of Linux, such as Ubuntu, CentOS, RHEL, Debian, and Linux E2E Cloud uses Linux as its OS environment.
Introduction
Linux is by far the most widely used corporate operating system. While administering a Linux machine or a Linux-based corporate PC housing multiple users, you might encounter situations where you have to control those users. Managing user permissions is a distinctive feature that Linux caters to its system admins. If you are new to Linux or manage user groups, this article will give you a crisp idea how to use them. First thing first, let us understand what a Linux user is and what is group permission?
What are Linux Users?
All Linux and Unix systems can perform multitasking like other operating systems. Yet, there is a significant distinction between Linux and other operating systems. It's the concept of multiple users. Linux can render access and use its system resources to multiple users simultaneously. Thus, to sustain this multiuser design structure and make it work, we must incorporate some protection techniques.
What are file permission and group permission?
Multiple users share the same operating system. So, to protect the files and maintain proper accessibility, permissions play a significant role. Linux allows its users to add file permission for reading, writing, and executing a file.
A Linux group contains many users. These organizational units help in administering and organizing different user accounts. Through Linux groups, users can set certain privileges to read, write, and execute permission on specific resources shared between users in the Linux group.
Types of groups in the Linux Operating system
Linux comes with two different variations of groups. These are –
· The Primary Group: As soon as the user creates a file, its group gets assigned as primary. In this case, the group name remains the same as the username. It stores all its relevant information in the /etc/passwd file.
· The Secondary Group: This group is for those users with whom you want to share specific files by granting permissions. You can set the permissions to the group members only.
Reading, Writing, and Executing Permissions in Linux –
To give the permissions to the groups, one needs to have a clear idea of the various permission rights available for files or directories.
· Read permission: This permission allows a file to open for readability purposes only. Through this permission, users can only view the data without altering it. If a directory has permission to read, the user can only list the directory content.
· Write permission: This permission allows the user to modify any content from the file. If this permission is available with the directory, it will permit the user to edit the directory's content.
· Execute: It is a powerful permission that authorizes the user to execute any script or program. If this permission is available with the system directory, users can switch to different locations - making it a current directory.
How to View File Permissions –
Sometimes it becomes essential to check the permission mode of the file in Linux. In such a situation, users can view the directory or file permission using the command:
ls -l < file/directory>.
How to create a group?
Creating a new group is easy. Use the 'groupadd' command along with the name of the group. The command syntax will look like this:
$sudo groupadd groupname
Add an Existing User to a Group –
You might encounter a situation where adding a user to a secondary group will make the group work on a single project or run a single program. In such a situation, you have to use the command 'usermod -a -G', along with the group and username.
The command syntax will look like this:
$ sudo usermod -a -G groupname username
Example,
$ sudo usermod -a -G devops karlos
Adding an Existing User to Multiple Groups –
A situation might arise where you might need to add a particular user to a handful of secondary groups. You can use a single command to perform this. You can do this by implementing the 'usermod' command served with a -G option. Also, you have to mention all the group names with a comma separating them.
The command syntax will look like this:
$ sudo usermod -a -G group1,group2,group3 username
Example,
$ sudo usermod -a -G devops,sudo,docker karlos
Remove a User from a Group –
You can use the 'gpasswd' command served with the -d option to remove a user from a secondary group. The command syntax will look like this:
$ sudo gpasswd -d username group
Conclusion
Linux is one of the most secure OS. Linux admins have the privilege to set rights and permissions for each user sharing the OS resources. The commands shown here are applicable for different distributions of Linux, such as Ubuntu, CentOS, RHEL, Debian, and Linux E2E Cloud uses Linux as its OS environment.
Know more about E2E Cloud - https://www.e2enetworks.com/cloud-credits-request-rk/
Contact no - 9599620390