Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Adding Users

So you need to add a user. What do you do? Your choices are to use adduser and useradd.

adduser

adduser is a command line tool for adding user accounts. It is interesting because it manages both /etc/passwd and /etc/group to implement User Private Groups (UPGs; see Chapter 16), a strategy in which each user is made a member of a group that only he or she belongs to. Using UPGs simplifies the process of sharing files between users, and for this reason alone, adduser should be the program you use for adding accounts to your system. If you installed OpenLinux using the standard install option as you were instructed, adduser should already be on your system. If it is not, you can install it from your CD.

To add a new user, just type adduser username, like this:

     [root@digital alberto]# adduser flower

     Looking for first available UID... 502
     Looking for first available GID... 502

     Adding login: flower...done.
     Creating home directory: /home/flower...done.
     Creating mailbox: /var/spool/mail/flower...done.

     Don’t forget to set the password.

This command swiftly found the next available UID and GID and created entries for them in /etc/passwd and /etc/group. It created the home directory /home/flower, copied all the startup files from /etc/skel, and then created a mailbox.

Although this is the bulk of the work, optional details about the user, such as the user’s real name, were not set. To set those details, you can use the chfn command. See the section “Changing Your Personal Information: chfn” in Chapter 17, “Command Toolbox: Useful Shell Commands and Shortcuts.”

A more important detail that is not set by default is the account password. To set a password for the account, see the section “Changing Your Password: passwd” in Chapter 17.

Something to keep in mind when adding users is that the username should be kept at eight or fewer characters. Longer usernames are not handled properly by the system and/or other programs.

Useradd

Useradd is similar to adduser; the only problem is that it doesn’t manage the groups database, nor does it implement the UPG scheme, which can simplify much of what you do in the long run. To add an account through useradd, just type the following:

     useradd -m username

The -m option creates the home directory. The password for the account still must be set, as must the real name for the user and other user information.

Modifying Users: usermod

As time goes by, some users will need certain changes made to their accounts. The easy way to make changes is to use usermod, because it offers various options that you can set.

Moving a Home Directory

To move a home directory, use this syntax:

     usermod -d newdirpath -m login
      [root@digital root]# usermod -d /home/newflower -m flower

This option modifies the location of the home directory specified by the /etc/passwd file to point to the directory specified by the -d option. It also creates the home directory if it doesn’t exist. The -m option moves the contents from the old home directory into the new one.

If you are changing the name of the home directory, you’ll probably also want to change the login name for the user. This option only changes the home directory name; the login name remains as it was.

Changing a Login Name

To change a login name, type the following:

     usermod -l newlogin currentlogin
     [root@digital root]# usermod -l newflower flower

This option changes the login name for the user. All other information remains the same. Typically, when you change a login name, you’ll also want to change or move a home directory, as explained in the preceding section. In the example shown here, the login name flower is changed to newflower.

Changing Secondary Group Memberships

To change secondary group memberships, type this:

     usermod -d newdirpath -m login
     usermod -d /home/newflower -m flower
     [root@digital root]# groups flower
     flower : flower users
     [root@digital root]# usermod -G wheel,database flower
     [root@digital root]# groups flower
     flower : flower wheel database

The groups command prints a list of all the current group affiliations for a user. If you don’t provide a login name, it operates on the assumption that you want to know the group affiliations for the current user.

To change all secondary group affiliations (not the default group), provide a list of the group names separated by commas but with no spaces between them. If a group is omitted, that membership is removed. The sole exception is the primary group for the user.

Deleting Users: userdel

To delete a user from the system, you can use the userdel command. Userdel takes as an argument the login of the user. This will remove the named user from the /etc/passwd file. However, the user’s home account, mailbox, UPG, and other group affiliations will still be left behind. The syntax looks like this:

     [root@digital root]# userdel newflower

Typically, before you remove the user, you should back up the corresponding account and mailbox or ask the user to do so prior to removing the account. After you have taken the necessary precautions, use userdel to remove the user. Then use groupdel to remove the user’s UPG entry. You’ll also have to use a text editor to eliminate the removed login from all other entries in the /etc/group file.

If you are using UPGs and the default group for the user is the corresponding UPG, you can reduce the number of steps by typing the following:

     usermod -G username username

This will remove all group affiliations for the user except the UPG (the default group). The default group is provided as an argument to -G because usermod requires it. After you have completed the previous step, you can type the following:

     userdel username

This deletes the user from the /etc/passwd file. You can finish the task by removing the UPG from the /etc/group. Finalize the removal by deleting the user’s home directory and his or her mailbox (make sure you backed them up first!), like this:

     rm -R /home/username /usr/spool/mail/username


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.