πŸ‘₯ Linux/Unix: User, Group & Security Management
Estimated reading: 3 minutes 53 views

πŸ‘₯ Linux/Unix: User & Group Management – useradd, usermod, groups, id Explained

🧲 Introduction – Why Learn User & Group Management in Linux?

User and group management is at the core of Linux system administration. It controls who can access the system, what they can do, and how resources are shared. With tools like useradd, usermod, groups, and id, you can easily manage users, assign roles, and control file permissions.

🎯 In this guide, you’ll learn:

  • How to create, modify, and manage users and groups
  • How to check group memberships and user identity
  • Practical examples with command outputs

πŸ‘€ 1. useradd – Add a New User

βœ… What is useradd?

useradd is the standard command to create new user accounts.

πŸ› οΈ Syntax:

sudo useradd [options] username

πŸ”Ή Common Options:

OptionDescription
-mCreate home directory
-sSpecify default shell
-GAdd to additional groups
-uSet user ID manually
-dSpecify home directory

πŸ§ͺ Example 1: Create a new user with home and bash shell

sudo useradd -m -s /bin/bash alice

πŸ“€ Output:
Creates /home/alice and assigns bash as the default shell.


πŸ§ͺ Example 2: Add user to sudo group

sudo useradd -m -G sudo bob

πŸ› οΈ 2. usermod – Modify Existing User

βœ… What is usermod?

usermod is used to change user attributes such as group membership, home directory, or login shell.

πŸ› οΈ Syntax:

sudo usermod [options] username

πŸ”Ή Common Tasks:

TaskCommand Example
Change login shellsudo usermod -s /bin/zsh alice
Add user to a groupsudo usermod -aG developers alice
Change home directorysudo usermod -d /new/home alice
Lock user accountsudo usermod -L alice
Unlock user accountsudo usermod -U alice

πŸ‘¨β€πŸ‘©β€πŸ‘§ 3. groups – Show Group Memberships

βœ… What is groups?

Displays the groups a user belongs to.

πŸ› οΈ Syntax:

groups [username]

πŸ§ͺ Example:

groups alice

πŸ“€ Output:

alice : alice sudo developers

🧠 Helpful to confirm if a user has sudo or team-specific access.


🧾 4. id – Display User and Group IDs

βœ… What is id?

Shows the user ID (uid), primary group ID (gid), and all groups a user belongs to.

πŸ› οΈ Syntax:

id [username]

πŸ§ͺ Example:

id bob

πŸ“€ Output:

uid=1001(bob) gid=1001(bob) groups=1001(bob),27(sudo)

🧠 Use this to programmatically check user identity in scripts.


🧠 Bonus: Related Commands

CommandDescription
addgroupDebian-specific alias for groupadd
groupaddAdd new group
groupdelDelete a group
passwdSet or change user password
deluser / userdelDelete user account

πŸ“Œ Summary – Recap & Next Steps

Managing users and groups is foundational for Linux security, multi-user access, and resource permissions. These tools help you enforce access policies, add team members, and automate user setup.

πŸ” Key Takeaways:

  • Use useradd -m -s /bin/bash to create new users with default shell and home.
  • Use usermod -aG to assign users to groups without overwriting existing ones.
  • Use groups or id to confirm access roles and identities.

❓ FAQs

❓ How do I add a user to multiple groups?
βœ… Use:

sudo usermod -aG group1,group2 username

❓ What’s the difference between useradd and adduser?
βœ… useradd is low-level and universal. adduser is a Debian-friendly interactive script that uses useradd underneath.

❓ Can I change a username?
βœ… Yes:

sudo usermod -l newname oldname

❓ How do I remove a user and their home directory?
βœ… Use:

sudo userdel -r username

❓ How do I temporarily disable a user account?
βœ… Use:

sudo usermod -L username

Share Now :

Leave a Reply

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

Share

πŸ”΅ Linux/Unix: User & Group Management (useradd, usermod, groups, id)

Or Copy Link

CONTENTS
Scroll to Top