Basic User Management Labs
Lab: who
Lab: what
Lab: last
- List all user login, logout, and system reboot occurrences:
- List system reboot info only:
Lab: lastb
Lab: lastlog
Lab: id
- View info about currently active user:
- View info about another user:
Lab: groups
- View current user’s groups:
- View groups of another user:
Lab: user authentication files
- list of the four files and their backups from the /etc directory:
ls -l /etc/passwd* /etc/group* /etc/shadow* /etc/gshadow*
- View first and last 3 lines of the passwd file
head -3 /etc/passwd ; tail -3 /etc/passwd
- verify the permissions and ownership on the passwd file:
- View first and last 3 lines of the shadow file:
head -3 /etc/shadow ; tail -3 /etc/shadow
- verify the permissions and ownership on the shadow file:
- View first and last 3 lines of the group file:
head -3 /etc/group ; tail -3 /etc/group
- Verify the permissions and ownership on the group file:
- View first and last 3 lines of the gshadow file:
head -3 /etc/gshadow ; tail -3 /etc/gshadow
- Verify the permissions and ownership on the gshadow file:
Lab: useradd and login.defs
- use the cat or less command to view the useradd file content or display the settings with the useradd command:
- grep on the/etc/login.defs with uncommented and non-empty lines:
grep -v ^# /etc/login.defs | grep -v ^$
Lab: Create a User Account with Default Attributes (root)
- Create user2 with all the default directives:
- Assign this user a password and enter it twice when prompted:
- grep for user2: on the authentication files to examine what the useradd command has added:
cd /etc ; grep user2: passwd shadow group gshadow
- Test this new account by logging in as user2 and then run the id and groups commands to verify the UID, GID, and group membership information:
Lab: Create a User Account with Custom Values
- Create user3 with UID 1010 (-u), home directory /usr/user3a (-d), and shell /bin/sh (-s):
useradd -u 1010 -d /usr/user3a -s /bin/sh user3
- Assign user1234 as password (passwords assigned in the following way is not recommended; however, it is okay in a lab environment):
echo user1234 | passwd --stdin user3
- grep for user3: on the four authentication files to see what was added for this user:
cd /etc ; grep user3: passwd shadow group gshadow
- Test this account by switching to or logging in as user3 and entering user1234 as the password. Run the id and groups commands for further verification.
Lab: Modify and Delete a User Account
- Modify the login name for user2 to user2new (-l), UID to 2000 (-u), home directory to /home/user2new (-m and -d), and login shell to /sbin/nologin (-s).
usermod -l user2new -m -d /home/user2new -s /sbin/nologin -u 2000 user2
- Obtain the information for user2new from the passwd file for confirmation:
grep user2new /etc/passwd
- Remove user2new along with their home and mail spool directories (-r):
- Confirm the user deletion:
grep user2new /etc/passwd
Lab: Create a User Account with No-Login Access (root)
- Look at the current nologin users:
- Create user4 with non-interactive shell file /sbin/nologin:
useradd -s /sbin/nologin user4
- Assign user1234 as password:
echo user1234 | passwd --stdin user4
- grep for user4 on the passwd file and verify the shell field containing the nologin shell:
- Test this account by attempting to log in or switch:
Lab: Check User Login Attempts (root)
- execute the last, lastb, and lastlog commands, and observe the outputs.
- List the timestamps when the system was last rebooted (last).
Lab 5-2: Verify User and Group Identity (user1)
- run the who and w commands one at a time, and compare the outputs.
- Execute the
id
and groups
commands, and compare the outcomes. Examine the extra information that the id command shows, but not the groups command.
Lab 5-3: Create Users (root)
- create user account user4100 with UID 4100 and home directory under /usr.
useradd -m -d /usr/user4100 -u 4100 user4100
- Create another user account user4200 with default attributes.
- Assign both users a password.
passwd user4100
passwd user4200
- View the contents of the passwd, shadow, group, and gshadow files, and observe what has been added for the two new users.
cat /etc/passwd
cat /etc/shadow
cat /etc/group
cat /etc/gshadow
Lab: Create User with Non-Interactive Shell (root)
- Create user account user4300 with the disability of logging in.
useradd -s /sbin/nologin user4300
- Assign this user a password.
- Try to log on with this user and see is displayed on the screen.
- View the content of the passwd file, and see what is there that prevents this user from logging in.