Jinal Desai

My thoughts and learnings

Users, Groups, and Permissions

Linux Fundamentals Series: Users, Groups, and Permissions
  1. Introduction to Linux
  2. Getting Started with Linux
  3. Linux File System
  4. Users, Groups, and Permissions
  5. Linux Processes and Services
  6. Package Management in Linux
  7. Text Editors in Linux
  8. Shell Scripting Basics
  9. Linux Networking Fundamentals
  10. File and Data Backup
  11. System Administration Tasks
  12. Security in Linux
  13. Advanced Linux Shell Scripting
  14. Advanced Linux Networking
  15. Linux Server Administration
  16. Linux Virtualization and Containers
  17. Linux Cloud Services and Hosting
  18. Linux in DevOps: Empowering Modern Development Practices
  19. Mastering Linux Troubleshooting: Solving Common Challenges
  20. Mastering Linux: Advanced Tips and Tricks for Ultimate Productivity

Welcome to the fourth installment of our Linux Fundamentals series. In this article, we’ll explore the intricate world of users, groups, and permissions in the Linux operating system. These concepts are foundational for managing access control, security, and collaboration on Linux systems. 

Introduction

Linux is celebrated for its robust multi-user and multi-tasking capabilities, which allow multiple users to run processes concurrently. Users, groups, and permissions are vital components for governing user access, securing data, and maintaining order in a Linux environment.

Managing Users and Groups

User Accounts

In Linux, each user is assigned a unique User ID (UID) and a username. These credentials are used for authentication and to track user activities. To create a new user, use the `useradd` command:

sudo useradd -m username

Here, the `-m` flag creates a home directory for the new user. Replace `username` with the desired username.

Group Management

Groups serve as a mechanism for organizing and controlling user access to resources. To create a new group, you can employ the `groupadd` command:

sudo groupadd groupname

Adding a user to a group can be accomplished using the `usermod` command:

sudo usermod -aG groupname username

This command adds the user `username` to the group `groupname`, ensuring that they inherit the group’s permissions.

File Permissions and Ownership

File and Directory Ownership

Every file and directory in Linux is associated with an owner and a group. You can check file permissions and ownership using the `ls -l` command:

ls -l /path/to/file

An example output might look like this:

-rw-r–r– 1 user1 group1 12345 Sep 12 10:00 myfile.txt

In this example, `user1` is the owner, `group1` is the group, and `-rw-r–r–` represents the file permissions.

File Permissions

File permissions are represented by a 10-character string:

r w x r - - - -
| | | | | | | | |
| | | | | | | | +-- Other (world) can execute
| | | | | | | +---- Other can write
| | | | | | +------ Other can read
| | | | | +-------- Group can execute
| | | | +---------- Group can write
| | | +------------ Group can read
| | +-------------- Owner can execute
| +---------------- Owner can write
+------------------ Owner can read

To modify permissions, use the `chmod` command:

chmod permissions file_or_directory

For example, to allow the owner to execute a script, use:

chmod u+x script.sh

Advanced Permission Concepts

Special Permissions

Linux introduces special permissions such as the setuid (`s`), setgid (`S`), and sticky bit (`t`). These permissions can be set using `chmod` or `chown`.

– Setuid (`s`): When set on an executable file, the process runs with the permissions of the file’s owner. For example, `/bin/passwd` allows users to change their passwords, and it has the setuid permission to execute with root privileges.

chmod u+s executable_file

– Setgid (`S`): Similar to setuid, but the process runs with the group’s permissions. It’s often used for shared directories.

chmod g+s directory

– Sticky Bit (`t`): Prevents users from deleting or modifying files in a directory unless they are the owner of the file or the directory itself.

chmod +t directory

User Management Commands

Here are some essential user management commands:

– `useradd`: Create a new user.
– `userdel`: Delete a user.
– `passwd`: Change a user’s password.
– `usermod`: Modify user properties.
– `groupadd`: Create a new group.
– `groupdel`: Delete a group.
– `groups`: Display groups a user belongs to.
– `chown`: Change file ownership.
– `chmod`: Change file permissions.

Conclusion

Mastering users, groups, and permissions is fundamental for maintaining control, security, and collaboration in a Linux environment. Proper configuration of these elements ensures that the right users have the right access to resources, contributing to a well-organized and secure system. In the next article of our Linux Fundamentals series, we’ll explore advanced permission management and access control techniques. Stay tuned!

Leave a Reply

Your email address will not be published. Required fields are marked *