Creating and Managing User Accounts
useradd
As its name implies, the useradd utility is used to add users to the Linux system.
The syntax for useradd is:
useradd options username
For example, suppose I wanted to create a user account named lmorgan using default parameters.
I would enter
useradd lmorgan
at the shell prompt.
• /etc/default/useradd
This file contains the defaults used by the useradd utility. Here is
a sample:
openSUSE:/ # cat /etc/default/useradd
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
You can also view new user default values by entering
useradd –D
at the shell prompt.
• /etc/login.defs
This file contains values that can be used for the GID and UID parameters
when creating an account with useradd. It also contains defaults for creating
passwords in /etc/shadow. A portion of this file follows:
openSUSE:/ # cat /etc/login.defs
openSUSE:~ # cat /etc/login.defs
#
# /etc/login.defs - Configuration control definitions for the shadow package.
• /etc/skel
The useradd command copies files from the skeleton directory (/etc/skel by
default) into a newly created home directory when you create a new user.
You can override these defaults when running
useradd
by specifying a list of options in the command line. You can use the following:
• –c
Includes the user’s full name.
• –e
Specifies the date when the user account will be disabled. Format the date as
yyyy-mm-dd.
• –f
Specifies the number of days after password expiration before the account is disabled.
Use a value of
–1
to disable this functionality (for example, useradd –f –1 jmcarthur).
• –g
Specifies the user’s default group.
• –G
Specifies additional groups that the user is to be made a member of.
• –M
Specifies that the user account be created without a home directory.
• –m
Specifies the user’s home directory.
• –n
Used only on Red Hat and Fedora systems. By default, these distributions create a
new group with the same name as the user every time an account is created. Using this
option will turn off this functionality.
• –p
Specifies the user’s encrypted password. You can encrypt the password you want to
use with the
openssl passwd -crypt
command. Run this command and, when prompted, enter the password you want to assign to the user account.
The command will output an encrypted version of the password on the screen. You can then use the encrypted password with the -p option of the useradd and usermod commands.
• –r
Specifies that the user being created is a system user.
• –s
Specifies the default shell for the user.
• –u
Manually specifies a UID for the user.
LX0-104 Exam Objectives (K)
No comments:
Post a Comment