Creating and Managing Users in Linux

Overview

User management is a fundamental Linux skill. Every action in Linux is performed by a user, and understanding how to create, modify, and delete users is essential for system administration.

Key Commands

Creating a User

sudo useradd username

Creates a new user account. The sudo command gives you administrator privileges.

Options:

  • -m - Creates a home directory for the user
  • -s /bin/bash - Sets the user's default shell
  • -G groupname - Adds user to a specific group
Example:
sudo useradd -m -s /bin/bash john
Creates user 'john' with a home directory and bash shell

Setting a Password

sudo passwd username

Sets or changes a user's password. Always set a password after creating a user!

Deleting a User

sudo userdel username

Removes a user account from the system.

Options:

  • -r - Also removes the user's home directory and mail spool

Viewing Users

cat /etc/passwd

Lists all users on the system. Each line contains user information.

Important Notes

  • Always use sudo: User management requires administrator privileges
  • Username rules: Use lowercase, no spaces, start with a letter
  • Set passwords: New users can't login without a password
  • Be careful with userdel: Deleting users is permanent!

Practice Levels