Deleting User Accounts
Occasionally, it is necessary to remove a user account from your Red Hat Linux system. This can be done with either the userdel command or the Red Hat User Manager window.
Deleting user accounts with userdel
The userdel command takes a single argument, which is the login name of the account to delete. If you supply the optional -r option, it also deletes the user's home directory and all the files in it. To delete the user account with login name mary, you would type this:
# userdel mary
To wipe out her home directory along with her account, type this:
# userdel -r mary
Files owned by the deleted user but not located in the user's home directory will not be deleted. The system administrator must search for and delete those files manually. The find command comes in very handy for this type of thing. I won't describe all the capabilities of the find command (that would take a very fat chapter of its own). I do, however, provide a few simple examples of how to use find to locate files belonging to a particular user, even when those files are scattered throughout a file system. You can even use the find command to delete or change the ownership of files, as they are located. Table 11-4 has a few examples of the find command in action.
There are a few common things about each invocation of the find command. The first parameter is always the directory to start the recursive search in. After that come the file attributes to match. You can use the -exec parameter to run a command against each matching file or directory. The {} characters designate where the matching filename should be filled in when find runs the -exec option. The \; at the end simply tells Linux where the command ends. These are only a few of find's capabilities. I encourage you to read the online man page to learn more about find. (Type man find to view the page.)
Deleting user accounts with Red Hat User Manager
To delete a user from the Red Hat User Manager window, simply click the line representing the user account, then click the Delete button.
The information about the user is removed from the /etc/passwd file; thus, the user can no longer log in.
The home directory and all files owned by the user will still exist. However, a listing of files previously owned by that user (ls –l) will show only the former user's UID, but no name, as the owner.
See the description in the previous section for information about how to find and remove files previously owned by the user.
Tip | You may want to transfer the ownership of the files from the old user to the new user (if, for example, a new employee is taking over the work of an employee that is leaving the company). In that case, after you delete the old user, you can create a new user account using the same UID as the old account (with a new password, of course). The new user will immediately have ownership of all files owned by the deleted user. |