User Management¶
Prerequisites¶
- Root or sudo privileges
Quick Reference¶
| Action | Command |
|---|---|
| List users | cat /etc/passwd |
| User info | id <user> |
| Check Groups | groups <user> |
| Create User | useradd <user> |
| Set Password | passwd <user> |
| Add to Group | usermod -aG <group> <user> |
| Delete User | userdel -r <user> |
| Edit Sudoers | visudo |
| Lock Account | usermod -L <user> |
Procedure: Create a User¶
When to use: Adding a new person or service account to the system.
Steps:
-
Create the user (creates home dir and group by default):
useradd <username> -
(Optional) Create a system user (no home dir, system shell):
useradd -r -s /sbin/nologin <username> -
Verify user creation:
id <username>
Troubleshooting:
- If "user already exists": Check
/etc/passwd. - If permission denied: Ensure you are running as root or with sudo.
Procedure: Set or Change a Password¶
When to use: Setting an initial password for a new user or resetting a forgotten one.
Steps:
-
Set password interactively:
passwd <username> -
Force user to change password on next login:
chage -d 0 <username>
Troubleshooting:
- "Authentication token manipulation error": Often means the filesystem is read-only or SELinux issue, or shadow file corruption.
Procedure: Add a User to a Group¶
When to use: Granting permissions managed by group membership (e.g., wheel for sudo, docker for containers).
Steps:
-
Append (
-a) user to a secondary group (-G):Important: Always useusermod -aG <group_name> <username>-a(append). Omitting it removes the user from all other secondary groups! -
Verify membership:
groups <username>
Troubleshooting:
- Changes don't apply immediately: The user must log out and log back in for group changes to take effect.
Procedure: Configure sudo Access¶
When to use: Granting administrative privileges to a regular user.
Steps:
-
Add the user to the
wheelgroup (standard on RHEL/CentOS/Fedora):usermod -aG wheel <username> -
Alternatively, edit the sudoers file directly (safer syntax checking):
Add line:visudo<username> ALL=(ALL) ALL -
Verify access as the user:
Expected output:su - <username> sudo whoamiroot
Troubleshooting:
- "user is not in the sudoers file": Ensure they are in the
wheelgroup and the%wheelline in/etc/sudoersis uncommented.
Procedure: Set Up SSH Key Authentication¶
When to use: Enabling passwordless, secure login.
Steps:
-
Generate key pair (on client machine):
ssh-keygen -t ed25519 -
Copy public key to server:
ssh-copy-id <username>@<server_ip> -
Manually (if
ssh-copy-idunavailable):- Create folder:
mkdir -p ~/.ssh && chmod 700 ~/.ssh - Paste public key into
~/.ssh/authorized_keys - Set permissions:
chmod 600 ~/.ssh/authorized_keys
- Create folder:
Troubleshooting:
- "Permission denied (publickey)": Check directory permissions.
~/.sshmust be 700,authorized_keysmust be 600. Owner must be the user, not root. - SELinux: Run
restorecon -Rv ~/.sshto fix contexts.
Related Documentation¶
- Technologies: SSH
- Concepts: Users and Permissions