Creating and Managing User Accounts
Tutorial Overview
This tutorial explains how to create, manage, and configure user accounts on a Debian-based system. You’ll learn how to add new users, set their initial configurations, and assign group memberships.
Prerequisites
- Root or sudo access.
Steps
Step 1: Create a New User
1. Open a terminal.
2. Use the adduser command to create a new user. Replace newuser with the desired username:
sudo adduser newuser
3. You will be prompted to set a password for the new user. Choose a strong password and re-enter it to confirm.
4. After setting the password, you’ll be prompted to enter additional information (full name, room number, etc.). Fill in the information as needed or press Enter to skip each field.
5. Confirm the information by typing Y or Yes when prompted.
Step 2: Assign the New User to Groups
1. Check which groups the user currently belongs to:
groups newuser
- This will show the user’s current group memberships, typically including a primary group with the same name as the user.
2. To add the user to a new group (e.g., sudo for administrative privileges), use the usermod command:
sudo usermod -aG sudo newuser
- -aG appends the user to the specified group(s) without removing them from existing groups.
3. Verify that the user has been added to the new group:
groups newuser
- You should see sudo in the output, indicating the user has sudo privileges.
Step 3: Configure Additional User Settings
1. Set an Expiry Date for the User Account (optional):
- To expire the account after a specific date, use the following command. Replace YYYY-MM-DD with the desired date:
sudo chage -E YYYY-MM-DD newuser
- You can verify the expiration date with:
sudo chage -l newuser
2. Force Password Reset at Next Login (optional):
- This is useful for temporary accounts or when security policies require users to set their own passwords:
sudo chage -d 0 newuser
3. Delete a User Account (if needed):
- To delete a user along with their home directory, use:
sudo deluser --remove-home newuser