Managing Users, Groups, and Permissions
Effective user and group management, along with proper file and directory permissions, are essential for maintaining the security and integrity of a Linux system. In this section, we will explore the concepts and techniques for managing users, groups, and permissions in a Linux environment.
User Management
Linux users are the individuals who interact with the system. Each user has a unique username and a corresponding user ID (UID). The root user, with the UID of 0, has the highest level of privileges and is used for administrative tasks.
To manage users in Ubuntu 22.04, you can use the following commands:
## Create a new user
sudo useradd -m -s /bin/bash username
## Set a password for the user
sudo passwd username
## Modify user information
sudo usermod -a -G sudo username
## Delete a user
sudo userdel -r username
Group Management
Groups in Linux are used to organize users and manage permissions. Each user can be a member of one or more groups.
## Create a new group
sudo groupadd group_name
## Add a user to a group
sudo usermod -a -G group_name username
## Remove a user from a group
sudo gpasswd -d username group_name
## Delete a group
sudo groupdel group_name
File and Directory Permissions
Linux file system permissions are defined using a three-digit octal code or a set of rwx (read, write, execute) permissions. These permissions are assigned to the file or directory owner, the group, and others (everyone else).
## View file/directory permissions
ls -l
## Change file/directory permissions
sudo chmod 755 /path/to/file
sudo chmod u+x,g+r,o+r /path/to/file
## Change file/directory ownership
sudo chown username:group_name /path/to/file
graph TD
A[File/Directory] --> B[Owner Permissions]
A --> C[Group Permissions]
A --> D[Other Permissions]
B --> E[Read]
B --> F[Write]
B --> G[Execute]
C --> H[Read]
C --> I[Write]
C --> J[Execute]
D --> K[Read]
D --> L[Write]
D --> M[Execute]
By understanding and effectively managing users, groups, and permissions, you can ensure the security and accessibility of your Linux system, allowing users to perform their tasks while maintaining the overall integrity of the system.