| < Day Day Up > |
Linux also provides the
useradd
,
usermod
, and
userdel
commands to manage
| Note |
For Red Hat distributions, you should use the Red Hat User Manager (redhat-config-users) to manage user accounts (see Chapter 4). You can access the Red Hat User Manager from the System Settings window and menu. It is labeled simply as Users & Groups. You can also access it from the GNOME System menu. |
With the
useradd
command, you enter values as options on the command line, such as the name of a user, to create a user account. It then creates a new login and directory for that
# useradd chris
The
useradd
utility first checks the
/etc/login.defs
file for default values for creating a new account. For those defaults not defined in the
/etc/login.defs
file,
useradd
The
useradd
command has options that
# useradd chris -g intro1 -u 578
Once you add a new user login, you need to give the new login a password. Password entries are placed in the /etc/passwd and /etc/shadow files. Use the passwd command to create a new password for the user, as shown here. The password you enter will not appear on your screen. You will be prompted to repeat the password. A message will then be issued indicating that the password was successfully changed.
# passwd chris Changing password for user chris New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully #
|
Options |
Description |
|---|---|
|
-d dir |
Sets the home directory of the new user. |
|
-D |
Displays defaults for all settings. Can also be used to reset default settings for the home directory ( -b ), group ( -g ), shell ( -s ), expiration date ( -e ), and password expirations ( -f ). |
|
-e mm/dd/yy |
Sets an expiration date for the account (none, by default). Specified as month/day/year. |
|
-f days |
Sets the number of days an account remains active after its password
|
|
-g group |
Sets a group. |
|
-m |
Creates user's home directory, if it does not exist. |
|
-m -k skl-dir |
Sets the skeleton directory that holds skeleton files, such as .profile files, which are copied to the user's home directory automatically when it is created; the default is /etc/skel . |
|
-M |
Does not create user's home directory. |
|
-p password |
Supplies an encrypted password (crypt or MD5). With no argument, the account is immediately disabled. |
|
-r |
A Red Hat–specific option that creates a system account (one whose user ID is lower than the minimum set in logon.defs ). No home directory is created unless specified by -m . |
|
-s shell |
Sets the login shell of the new user. This is /bin/bash by default, the BASH shell. |
|
-u
|
Sets the user ID of the new user. The default is the increment of the highest number used so far. |
The usermod command enables you to change the values for any of these features. You can change the home directory or the user ID. You can even change the username for the account. The usermod command takes the same options as useradd , listed in Table 28-3.
When you want to remove a user from the system, you can use the userdel command to delete the user's login. With the -r option, the user's home directory will also be removed. In the next example, the user chris is removed from the system:
# userdel -r chris
| < Day Day Up > |