Datasheet
Task 1.6: Manage Accounts
31
You can create an account with different defaults by placing appropriate parameters
between useradd and the account name. Alternatively, you can create an account with the
defaults and then use usermod to change them. Some features you’re particularly likely to
want to adjust include:
Comment The -c comment parameter passes the comment field for the user. Some admin-
istrators store public information like a user’s office or telephone number in this field. Others
store just the user’s real name or no information at all.
Home directory You specify the account’s home directory with the -d home-dir parameter.
This defaults to /home/username on most systems.
Do or do not create a home directory The -M option forces the system to not automatically
create a home directory, while -m forces the system to create one. Which behavior is the default
varies from one system to another.
Default group You set the name or GID of the user’s default group with the -g default-
group option. The default for this value varies from one distribution to another.
Default shell Set the name of the user’s default login shell with the -s shell option. On
most systems, this defaults to /bin/bash.
Specify a UID The -u UID parameter creates an account with the specified user ID value
(UID). This value must be a positive integer, and it is normally above 500 for user accounts.
System accounts typically have numbers below 100. The -o option allows the number to be
reused so that two usernames are associated with a single UID.
No user group In some distributions, such as Red Hat, the system creates a group with the
same name as the specified username. The -n parameter disables this behavior.
This list of options isn’t complete; consult useradd’s man page for more options. As an
example of some of these options in action, suppose you want to place Trevor Brown’s real
name in the comment field and set his home directory to /home2/trevor. You could do so at
account creation time by including appropriate parameters:
# useradd -c "Trevor Brown" -d /home2/trevor tbrown
After typing this command (or the simpler version shown earlier), be sure to check for the
existence of the home directory. If it’s not present, you must create it yourself and change its
ownership (including its group):
# mkdir /home2/trevor
# chown tbrown.users /home2/trevor
Alternatively (and preferably), you could add the -m option to the useradd command. This
option has the advantage that the system copies a starting set of files from /etc/skel. These
files include things such as bash configuration files.
The useradd command won’t ordinarily set a starting password for the account. (There is
a -p option to do this, but it requires a pre-encrypted password.) The best way to deal with
this issue is to create new accounts in the presence of their users; you can then, as root, use
83484.book Page 31 Monday, September 18, 2006 8:58 AM










