Skip to main content

Command Palette

Search for a command to run...

User/Group Management and Permissions/Ownership in Linux

Updated
2 min read
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 john
sudo passwd john

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 developers
sudo usermod -aG developers john

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

File Permissions

Permissions are represented as:

text-rwxr-xr--
  • 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 filename
chmod g-w filename
chmod o=rx filename

Numeric mode:

bashchmod 755 filename
chmod 644 filename

Practical Scenarios

  1. Creating a New User and Assigning to a Group

     bashsudo useradd john
     sudo passwd john
     sudo groupadd developers
     sudo usermod -aG developers john
     groups john
    
  2. Changing File Ownership and Permissions

     bashtouch example.txt
     sudo chown john:developers example.txt
     chmod 754 example.txt
     ls -l example.txt
    

Comprehensive Example

bashsudo useradd alice
sudo passwd alice
sudo groupadd engineers
sudo usermod -aG engineers alice
groups alice
touch project.txt
sudo chown alice:engineers project.txt
chmod 664 project.txt
ls -l project.txt

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.

5 views