![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Complete Idiot's Guide to Linux
Adding UsersSo you need to add a user. What do you do? Your choices are to use adduser and useradd. adduseradduser 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. Dont 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 users 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. UseraddUseradd is similar to adduser; the only problem is that it doesnt 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: usermodAs 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 DirectoryTo 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 doesnt 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, youll 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 NameTo 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, youll 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 MembershipsTo 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 dont 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: userdelTo 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 users 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 users UPG entry. Youll 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 users home directory and his or her mailbox (make sure you backed them up first!), like this: rm -R /home/username /usr/spool/mail/username
|
![]() |
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. |