User Management and File Permissions in Linux

Managing user accounts and ensuring appropriate file permissions are fundamental tasks for system administrators. Let's explore how these processes work in a Linux environment to maintain security and organize access effectively.

Creating Users and Groups

When creating multiple users, organizing them into groups simplifies management. Every user added automatically creates a corresponding group:

sudo useradd -m raees

To verify user creation and associated shell:

cat /etc/passwd

Here, /bin/sh and /bin/bash indicate default shells for users like Raees and Ubuntu, respectively.

Creating a group:

sudo groupadd devops

Check existing groups:

cat /etc/group

Adding a user to a group:

sudo usermod -aG devops ubuntu

This command appends (-a) the user (ubuntu) to the group (devops).

Managing Multiple Users Efficiently

To add multiple users to a group in one command:

sudo gpasswd -M ubuntu,raees,mian devops

This simplifies group management by adding multiple users (ubuntu, raees, mian) to the devops group.

Understanding File Permissions

File permissions dictate who can read, write, or execute files. Each file/directory has three sets of permissions:

  • First dash (-): File type (- for regular file, d for directory, etc.)

  • Three dashes (---): Rights for the file owner.

  • Center three dashes: Rights for the group.

  • Last three dashes: Rights for other users.

Permission Table

Permissionsr (read)w (write)x (execute)Numeric Value
rwx1117
rw-1106
r-x1015
r--1004
-wx0113
-w-0102
--x0011
---0000

Changing File Permissions

Use chmod to change file permissions:

chmod 764 file/directory
  • 7 grants rwx (read, write, execute) to the user.

  • 6 grants rw- (read, write) to the group.

  • 4 grants r-- (read) to other users.

Verify permissions with:

ls -l file/directory

This command displays current permissions for files and directories.

Conclusion

Mastering user management and file permissions is essential for maintaining system security and organization. By creating users, organizing them into groups, and understanding and implementing appropriate file permissions, administrators ensure efficient management of resources and access control.

I hope this blog provides clarity and guidance on managing users and file permissions in Linux. Feel free to share your thoughts or ask questions in the comments below!

#LinuxAdministration #UserManagement #FilePermissions #SystemSecurity #TechTips

0
Subscribe to my newsletter

Read articles from Raees Yaqoob Qazi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Raees Yaqoob Qazi
Raees Yaqoob Qazi