Skip to main content

User and Group Management

Now that you're comfortable navigating the file system and working with text files, it's time to learn how to manage the users and groups that interact with your Ubuntu system. In this lesson, you'll learn how to create, modify, and manage user accounts and groups—essential skills for any system administrator.

Learning Goals:

  • Create and manage user accounts
  • Understand and work with user groups
  • Set and change passwords
  • Switch between user accounts
  • Manage user privileges

Understanding Users and Groups

In Linux, every process and file is owned by a user and belongs to a group. This security model ensures that only authorized users can access specific resources.

info

Every user in Linux has a unique User ID (UID) and every group has a Group ID (GID). The first user created during installation (usually your account) typically has UID 1000, while system users have lower UIDs.

Viewing Current User Information

Let's start by checking who you are and what groups you belong to:

Check current user and groups
whoami
groups
id

The id command provides the most comprehensive information, showing your UID, GID, and all groups you belong to.

Creating and Managing Users

Creating New Users

To create a new user account, use the adduser command:

Create a new user
sudo adduser alice

You'll be prompted to set a password and fill in optional user information. The system automatically creates a home directory at /home/alice and sets up default configuration files.

Setting User Passwords

You can set or change passwords using the passwd command:

Change password
# Change your own password
passwd

# Change another user's password (requires sudo)
sudo passwd alice
warning

Always use strong passwords! A good password should be at least 12 characters long and include a mix of uppercase, lowercase, numbers, and special characters.

Working with User Groups

Creating Groups

Groups allow you to manage permissions for multiple users simultaneously:

Create a new group
sudo addgroup developers

Adding Users to Groups

To add a user to an existing group:

Add user to group
sudo usermod -aG developers alice

The -aG flags are important: -a means "append" (so you don't remove existing groups) and -G specifies the group to add.

Viewing Group Information

Check group members
getent group developers

Switching Between Users

Using su Command

The su (substitute user) command allows you to switch to another user:

Switch to another user
# Switch to alice (requires alice's password)
su - alice

# Switch back to your original user
exit

Using sudo for Privileged Access

Run command as another user
sudo -u alice whoami

Modifying and Deleting Users

Modifying User Properties

Use usermod to change user properties:

Modify user account
# Change user's home directory
sudo usermod -d /home/newhome alice

# Change user's login name
sudo usermod -l alice_new alice

# Change user's primary group
sudo usermod -g developers alice

Deleting Users

To remove a user account:

Delete user account
sudo deluser alice

# Remove user and their home directory
sudo deluser --remove-home alice

User Configuration Files

Several important files control user and group information:

View user accounts
cat /etc/passwd

Each line shows: username:password:UID:GID:description:home_directory:shell

Common Pitfalls

  • Forgetting the -a flag with usermod -G: This removes the user from all other secondary groups
  • Deleting users without backing up data: Always backup important files before deleting accounts
  • Using weak passwords: This creates security vulnerabilities
  • Not logging out of privileged sessions: Always exit from su or sudo sessions
  • Modifying system UIDs/GIDs: Changing system user IDs can break system functionality

Summary

In this lesson, you learned how to:

  • Create and manage user accounts with adduser and deluser
  • Work with groups using addgroup and usermod
  • Set and change passwords with passwd
  • Switch between users using su and sudo
  • Understand the key configuration files in /etc/

User and group management forms the foundation of Linux security and multi-user environments. These skills are essential for maintaining a secure and well-organized system.

Show quiz
  1. What command would you use to create a new user named "bob"?
  2. How do you add user "bob" to the "developers" group without removing him from his current groups?
  3. Which file contains encrypted password information for users?
  4. What's the difference between su username and su - username?
  5. Why is the -a flag important when using usermod -G?

Answers:

  1. sudo adduser bob
  2. sudo usermod -aG developers bob
  3. /etc/shadow
  4. su username switches user but keeps the current environment, while su - username provides a fresh login environment
  5. Without -a, the user would be removed from all other secondary groups and only belong to the specified group