Linux 113: Managing Users and Permissions
Managing users and controlling access permissions are foundational tasks for securing and organizing a Linux system. This article covers the essential commands and concepts for creating users, setting permissions, managing groups, and using advanced tools like sudo
, umask
, and ACLs
.
1. Understanding Users and Groups in Linux
- Users: Each person or service accessing the system.
- Groups: Collections of users with shared permissions.
- User IDs (UIDs) and Group IDs (GIDs) uniquely identify users and groups.
View current user:
List all users:
List all groups:
2. Creating and Managing Users
Create a New User
Set or Change Password
Delete a User
3. Creating and Managing Groups
Create a New Group
Add a User to a Group
Change a User’s Primary Group
List User’s Groups
4. File Permissions and Ownership
Every file and directory has:
- Owner
- Group
- Permissions: Read (
r
), Write (w
), Execute (x
)
Check Permissions
Example output:
Change Ownership
Change Permissions
Numeric Permission Format
Symbolic | Numeric |
---|---|
rwx | 7 |
rw- | 6 |
r-- | 4 |
--- | 0 |
Example:
5. The sudo
Command and Privilege Escalation
-
Grants temporary administrative privileges to a user.
Allow user alice
to use sudo
:
Configure permissions with:
6. Default Permissions and umask
umask
sets default file creation permissions.
Check current umask
:
Change it temporarily:
Set default umask
in /etc/profile
or ~/.bashrc
.
7. Using Access Control Lists (ACLs)
ACLs allow more fine-grained permissions than the standard owner/group/others model.
Install ACL Tools
Set ACL Permissions
View ACLs
8. Disabling User Accounts
Temporarily disable a user:
Re-enable:
Expire a user account:
9. Best Practices
- Avoid using the root account directly.
- Use groups to simplify permission management.
- Regularly audit users and permissions.
- Use
sudo
andvisudo
to restrict administrative actions. - Apply the principle of least privilege.
10. Conclusion
Proper user and permission management is key to maintaining system security and organization. With the right combination of users, groups, permissions, and tools like sudo
and ACLs
, you can maintain a secure and well-controlled Linux environment.
Next Steps:
- Automate user creation with scripts.
- Integrate Linux user management with LDAP or Active Directory.
- Monitor user activity using tools like
auditd
.
Stay tuned for the next article in the series:
Linux 114: Package Management with APT, YUM, and DNF