Administration – Modifying or deleting User Accounts

After a user account is created, you can change values for that account with the usermod command. Most options are the same ones you would use with useradd. For example:

Change user’s name in comment field
$ sudo usermod -c “Marvin Soto” msoto

Change default shell to sh
$ sudo usermod -s /bin/sh msoto

Lock the user account named marvin
$ sudo usermod -L marvin

Unlock user account named marvin
$ sudo usermod -U marvin

Note that the last two examples lock and unlock a user account, respectively. Locking a user account does not remove the user’s account from the system or delete any of the user’s files and directories. However, it does keep the user from logging in. Locking an account can be useful if an employee is leaving the company, but the work in that employee’s files needs to be passed to another person. Under those circumstances, locking the user instead of deleting it prevents the files owned by that user from appearing as belonging to an unassigned UID.

Because a regular user can’t use the useradd or usermod command, there are special commands for changing personal account information. Here are examples:

Change current user’s shell to /bin/sh
$ chsh -s /bin/sh

Change a user’s shell to /bin/sh
$ sudo chsh -s /bin/sh marvin

$ sudo chfn \
-o “B-205” \ Change office number
-h “212-555-1212” \ Change home phone number
-w “212-555-1957” Change office phone number

$ finger marvin
Login: marvin Name: Marvin G. Soto
Directory: /home/marvin Shell: /bin/bash
Office: B-205, 212-555-1212 Home Phone: 212-555-1957
On since Sat Aug 4 13:39 (CDT) on tty1 4 seconds idle
No mail.
No Plan.

The information changed above with the chfn command and displayed with finger are stored in the fifth field of the /etc/password file for the selected user. (The /etc/passwd file can only be edited directly by the root user, and should only be edited using the vipw command and extreme caution.)
On other versions of Linux, you can use the -f option to chfn to change your real or full name. On Linux, the permission to do this is turned off by default. You can change this by editing /etc/login.defs. Look for the following line:

CHFN_RESTRICT rwh

and change this to:

CHFN_RESTRICT frwh

Deleting User Accounts

With the userdel command, you can remove user accounts from the system, as well as other files (home directories, mail spool files, and so on) if you choose. Here are examples:

Delete user, not user’s home directory
# userdel marvin

Delete user, home directory, and mail spool
# userdel -r marvin

Advertisements

About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on September 23, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: