Deleting User Accounts


Occasionally, it is necessary to remove a user account from your Linux system. This can be done with either the userdel command or the 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 task. 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.

Table 11-4: Using find to Locate and Change User Files

Find Command

Description

find / -user mary

Search the entire file hierarchy (start at /) for all files and directories owned by mary and print the filenames to the screen.

find /home -user mary -exec rm -i {} \;

Search for all files and subdirectories under /home owned by mary. Run the rm command interactively to delete each file.

find / -user mary -exec chown jenny {} \;

Search for all files and subdirectories under /home that are owned by user mary and run the chown command to change each file so that it is owned by jenny instead.

find / -uid 500 -exec chown jenny {} \;

This command is basically the same as the previous example, but it uses the user ID number instead of the user name to identify the matching files. This is useful if you have deleted a user before converting her files.

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 User Manager

To delete a user from the 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 who 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.




Red Hat Fedora Linux 3 Bible
Red Hat Fedora Linux 3 Bible
ISBN: 0764578723
EAN: 2147483647
Year: 2005
Pages: 286

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net