DEV Community

Asad
Asad

Posted on • Originally published at blog.automation-dev.us on

User/Group Management and Permissions/Ownership in Linux

Linux, as a multi-user operating system, requires effective user and group management to maintain system security and control access to resources. This document outlines key concepts and practices in user/group management and file permissions/ownership.

User Management

Types of Users

  1. Root User : Superuser with unrestricted system access. Home directory: /root.

  2. Regular Users : Non-privileged users with home directories in /home/username.

Creating Users

bashsudo useradd johnsudo passwd john
Enter fullscreen mode Exit fullscreen mode

User Configuration Files

  • /etc/passwd: User account information

  • /etc/shadow: Encrypted passwords and account expiration data

  • /etc/group: Group information

Group Management

Groups facilitate managing permissions for multiple users simultaneously.

Creating Groups and Adding Users

bashsudo groupadd developerssudo usermod -aG developers john
Enter fullscreen mode Exit fullscreen mode

Key Management Commands

  • useradd: Add new user

  • passwd: Set/change user password

  • usermod: Modify user account

  • groupadd: Add new group

  • groups: Display user's group memberships

  • deluser: Delete user

  • delgroup: Delete group

Permissions and Ownership

Linux uses a permission model to control file and directory access.

File Ownership

  • Owner: User who owns the file

  • Group: Group that owns the file

Change ownership:

bashsudo chown user:group filename
Enter fullscreen mode Exit fullscreen mode

File Permissions

Permissions are represented as:

text-rwxr-xr--
Enter fullscreen mode Exit fullscreen mode
  • First character: File type

  • Next three: Owner permissions

  • Following three: Group permissions

  • Last three: Others' permissions

Permissions include:

  • r: Read

  • w: Write

  • x: Execute

Changing File Permissions

Using chmod command:

Symbolic mode:

bashchmod u+rwx filenamechmod g-w filenamechmod o=rx filename
Enter fullscreen mode Exit fullscreen mode

Numeric mode:

bashchmod 755 filenamechmod 644 filename
Enter fullscreen mode Exit fullscreen mode

Practical Scenarios

  1. Creating a New User and Assigning to a Group

  2. Changing File Ownership and Permissions

Comprehensive Example

bashsudo useradd alicesudo passwd alicesudo groupadd engineerssudo usermod -aG engineers alicegroups alicetouch project.txtsudo chown alice:engineers project.txtchmod 664 project.txtls -l project.txt
Enter fullscreen mode Exit fullscreen mode

This comprehensive guide provides a solid foundation for managing users, groups, and file permissions in Linux environments, essential for maintaining system security and access control.

Top comments (0)