< Day Day Up > |
Linux also provides the useradd, usermod, and userdel commands to manage user accounts. All these commands take in all their information as options on the command line. If an option is not specified, they use predetermined default values.
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 name using all the default features for a new account.
# 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 supplies its own. You can display these defaults using the useradd command with the -D option. The default values include the group name, the user ID, the home directory, the skel directory, and the login shell. Values the user enters on the command line will override corresponding defaults. The group name is the name of the group in which the new account is placed. By default, this is other, which means the new account belongs to no group. The user ID is a number identifying the user account. The skel directory is the system directory that holds copies of initialization files. These initialization files are copied into the user's new home directory when it is created. The login shell is the pathname for the particular shell the user plans to use.
The useradd command has options that correspond to each default value. Table 28-3 holds a list of all the options you can use with the useradd command. You can use specific values in place of any of these defaults when creating a particular account. The login is inaccessible until you do. In the next example, the group name for the chris account is set to intro1 and the user ID is set to 578:
# 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 expires. |
-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 userid |
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.
< Day Day Up > |
This HTML Help has been published using the chm2web software. |