Rocky Linux Core Commands: Page 7

This page covers commands for managing users and groups on your Rocky Linux system.


31. useradd - Create a New User Account

Purpose: The useradd command is used to create a new user account on the system. It creates an entry in the system account files and optionally creates a home directory and copies skeleton files.

Syntax: sudo useradd [OPTIONS] USERNAME

Key Options:

Examples:

sudo useradd -m newuser
sudo useradd -m -s /bin/bash -c "John Doe" johndoe
sudo useradd -m -g developers -G sudo,webdev jane

32. passwd - Change User Password

Purpose: The passwd command is used to change a user's password. Users can change their own password, while the root user can change any user's password.

Syntax: passwd [OPTIONS] [USERNAME]

Examples:

passwd             # Change your own password
sudo passwd root   # Change the root user's password
sudo passwd newuser # Set or change password for 'newuser'

33. usermod - Modify a User Account

Purpose: The usermod command is used to modify an existing user account. You can change a user's home directory, shell, group memberships, and more.

Syntax: sudo usermod [OPTIONS] USERNAME

Key Options:

Examples:

sudo usermod -l newname oldname
sudo usermod -d /home/newhome -m username
sudo usermod -s /bin/zsh myuser
sudo usermod -aG admin,developers alice

34. userdel - Delete a User Account

Purpose: The userdel command is used to delete a user account from the system.

Syntax: sudo userdel [OPTIONS] USERNAME

Key Options:

Examples:

sudo userdel olduser
sudo userdel -r unusedaccount

35. groupadd - Create a New Group

Purpose: The groupadd command is used to create a new group on the system.

Syntax: sudo groupadd [OPTIONS] GROUPNAME

Examples:

sudo groupadd developers
sudo groupadd web_admins