Creating a New Local User Account
To create a new user account, use the straightforward command “adduser.” For example, to create an account for a user named john, run:- A new user account named “john” is created.
- A new group named “john” is automatically generated and set as the primary group for the user.
-
A home directory is created at
/home/johnto store personal files, directories, and configuration settings. -
The default login shell is set to
/bin/bash, meaning every time john logs in, this shell is used. -
All files from
/etc/skelare copied into/home/john. To inspect these default files, you can use:
If you need more information on the options available with
adduser, try running adduser --help.Setting a User Password
If a new account hasn’t been assigned a password during creation, you can set one using the following command:Deleting a User Account
When it’s time to remove a user account, use thedeluser command. The basic command only removes the account but leaves the home directory intact:
Understanding /etc/passwd
The/etc/passwd file contains essential details about user accounts, including username, user ID (UID), group ID (GID), preferred shell, and home directory. You can view the contents with:
- The first numeric value, 1001, is the UID for john.
- The second numeric value, 1001, represents the GID for john’s primary group.
- The file also displays the home directory and preferred login shell.
adduser assigns the next available UID (typically starting at 1000) automatically. If you need to specify a UID manually—for instance, creating a user called smith with UID 1100—use:
-n option to ls.
Checking the Current User
To find out which user account you are currently logged in as, use:Creating a System Account
System accounts are typically reserved for running services and daemons rather than for interactive logins. These accounts often have UIDs lower than 1000. To create a system account (example: sysacc) without a home directory, execute:If you’re following along in a virtual machine, consider removing these test user accounts after practicing.
Modifying User Accounts
Theusermod command allows you to change various properties of an existing user account, such as the home directory, login name, and login shell.
Changing the Home Directory
To change the home directory for user “john” and move his existing files, use:--move-home option transfers the contents of the old directory (/home/john) to the new location.
Renaming a User
To change the username from john to jane, run:Changing the Login Shell
To modify jane’s login shell, execute:-s to achieve the same result.
Locking and Unlocking an Account
To disable password login for jane, lock her account with:Setting an Account Expiration Date
To set a specific expiry date for an account—for example, to have jane’s account expire on December 10, 2028—use:"").
Managing Password Expiration with chage
Password expiration ensures that users change their passwords periodically, which is different from account expiration. While account expiration disables login entirely, password expiration forces the user to change their password at the next login.Forcing an Immediate Password Change
To make jane’s password expire immediately (thus requiring a change at next login), run:Setting a Maximum Password Age
To enforce that jane updates her password every 30 days, execute:Be sure to clean up test accounts after you complete your exercises to maintain a secure system.
adduser command and its options, you can display the help menu by executing: