Remove a User Account
This IT Pro Challenge virtual lab shows learners the proper steps for completely removing a user account from an Ubuntu Linux system. Learners will understand how to verify the status of a user account, lock a user account, copy a user's home directory to the root user's home directory, and then remove the user account.
In this IT Pro Challenge, learners will understand how to manage user accounts on an Ubuntu Linux system by verifying user account status, locking a user account, copying user files to a root /home directory, and removing the user account from the system. Through this process, participants will learn how to use the passwd command and its switches, the userdel and grep commands, and gain general familiarity with other basic Linux commands. The skills acquired in this lab are useful for those who want a career as a network or system administrator.
The scenario for this virtual lab is that you are a system administrator, and your job is to remove system access for an employee who has left the company. To do this, you first need to verify the user account information, delete the account, move the deleted user's files to the home directory of the root user and then remove the account from the system entirely.
Verify the current status of a user account
To begin, you need to verify the current status of a user account. To do this, you need to log into the Ubuntu Linux system as the root user and run the passwd -S [username] command for a provided user name. You should see [username] P MM/DD/YYYY 0 99999 -1 returned.
The passwd command can provide basic user information like account status or last password change, but it can also be used to lock an account and define password expiration periods.
In the above example, the "P" indicates the current account status of password protected. The date is the date of the last password change, the "0" indicates the password minimum age in days, the "99999" is the password maximum age in days, the "7" is the password warning period, and the "-1" is the password inactivity period in days.
Lock a user account
Now you will lock the user account by running the passwd -l [username] command, which sets the password expiry information. Then you need to set the account status to disabled by running the __passwd -S [username] __command again. You should see [username] L MM/DD/YYYY 0 99999 -1 returned. The "L" after the [username] indicates that the account status is locked.
Copy a user's home directory to the root user's home directory
Next, you will copy the user's home directory and all its contents to the root user's home directory, while preserving permissions, by running the cp -pR /home/msmith/ ~/ command. The "cp" command copies the files, the "-p" option preserves the file permissions, while the "-R" option lists the files recursively.
Once the files are copied, you need to verify that all of the files have been preserved before you delete the original user directory by running the ls -lR [username] command.
Remove a user account from the system
Finally, you will remove the user from the system by running the __userdel -r [username] __command. Then, you will use the ls /home command to list the contents of the /home directory and then search for the user account that you just removed in the /etc/passwd file by using the grep [username] /etc/passwd command. You should see that the user name is now a number, but the user's copied files and original permissions remain.
By taking this virtual lab, you will be able to verify the status of a user account, disable that user account, copy user data to another location, delete the user account, home directory, and files for a particular user, and remove the user account from the system.