ЛР №9 (ОС - NDG - LEv2 - Ch15 - Ch16)
ЛР №9 (ОС - NDG - LEv2 - Ch15 - Ch16)
Objective Description
Various types of users on a Linux system.
Identifying User Accounts
Users and Permissions
● User accounts are designed to provide security on a Linux operating
system.
● This chapter covers commands that provide the ability to view user
and group account information and how to switch to other user
accounts.
Administrative Accounts
● Some commands require administrative or root privileges.
● Using the login shell option results in fully configuring the new shell with
settings of new user. If username is not specified su opens a new shell as
root
su -
user.
su - root
● Prompts for the user’s own password instead that of the root
sysadmin@localhost:~$ sudo head /etc/shadow
user.
[sudo] password for sysadmin:
○ Contains; Name, Password Placeholder, User ID, Primary Group ID, Comment,
Home Directory, Shell (fields are separated by a colon)
● Fields include:
○ Username: Username of the account (matches username in /etc/passwd)
○ Password: Encrypted password for the account
○ Last Change: Last time password was changed
○ Min: Minimum # of days between password changes
○ Max: Max # of days password is valid
○ Warn: Number of days before password expiry in the system warns the user
○ Inactive: Grace period in which user’s password can be changed
○ Expire: Number of days when user accounts will expire (from January 1, 1970)
○ Reserved: Currently not used, this field is reserved for future use
System Accounts
● Users log in using regular accounts (UID > 1000).
● Fields include:
○ Group Name: Field contains the group name
○ Password Holder: The x means password is not stored in this file
○ GID: Unique group ID associated with group
○ User List: Lists members in the group
Viewing User Accounts
Viewing User Information
● The id command is used to print user and group information.
sysadmin@localhost:~$ id
uid=1001(sysadmin) gid=1001(sysadmin) groups=1001(sysadmin),4(adm),27(sudo)
● Output:
○ Lists user account information first (UID (uid=1001) and username (sysadmin))
○ After username, the primary group is listed (group ID and group name)
○ Other information includes other groups user belongs to (group IDs and group
names)
● Output:
○ Username: Indicates user who is logged in and has an open session.
○ Terminal: Indicates which terminal window the user is working in. tty
indicates a local login whereas pts indicates a pseudo terminal.
○ Date: Indicates when user logged in. A hostname means user logged in
remotely. A colon and number means a graphical local login. No location
info means user logged in via local command line.
Viewing Current Users
● The w command provides more detailed information about
users currently on the system.
sysadmin@localhost:~$ last
Objective Description
Creating users and groups on a new system.
Introduction
Introduction
● Remember: User account info and authentication info is stored in
the /etc/passwd and /etc/shadow files.
● Avoid creating GIDs in the same range as UIDs created in the future.
● GIDs under 1000 are reserved for system use. To bypass this and
assign a <1000 GID, use the -r option.
Group Naming Considerations
● A portable group name functions correctly with other systems.
● Changing the group name won’t cause any problems with accessing
files
● To search for orphaned files, use the find command with the -
Deleting a Group
● The groupdel command can be used to delete a group.
● The -D option to the useradd command will allow you to view or change
some of the default values. This can also be done by manipulating
the /etc/default/useradd file.
root@localhost:~# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
User Configuration
● What the values of useradd -D mean:
GROUP - default primary group for a new user. This setting affects the primary group ID
field of the /etc/passwd file.
GROUP=100
bob:x:600:600:bob:/home/bob:/bin/bash
HOME - the default base directory under which the user's new home directory will be
created. This setting affects the home directory field of the /etc/passwd file.
HOME=/home
bob:x:600:600:bob:/home/bob:/bin/bash
User Configuration
INACTIVE - This value represents the number of days after the password expires that
the account is disabled. This setting affects the inactive field of the /etc/passwd file.
INACTIVE=-1
bob:x:600:600:bob:/home/bob:/bin/bash
EXPIRED - By default, there is no value set for the expiration date. This setting affects
the expire field of the /etc/passwd file.
EXPIRE=
bob:pw:15020:5:30:7:60:15050:
User Configuration
SHELL - The default shell for a user when they log in to the system.
This setting affects the shell field of the /etc/passwd file.
SHELL=/bin/bash
bob:x:600:600:bob:/home/bob:/bin/bash
SKELETON DIRECTORY - The contents of this directory are copied into the new user's
home directory. This setting affects the expire field of the /etc/passwd file.
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
User Configuration
● The /etc/login.defs file also contains values that will be applied by default to new
users you create with the useradd command.
● To view contents of /etc/login.defs file without comments and blank lines, use
the grep command.
Mail Directory - The directory in which the user's mail spool file will be created.
MAIL_DIR /var/mail/spool
Password Max Days - The maximum number of days that a user can continue to use
the same password.
PASS_MAX_DAYS 99999
Password Min Days - The shortest time that a user is required to keep a password.
PASS_MIN_DAYS 0
User Configuration
Password Minimum Length - The minimum number of characters that a
password must contain.
PASS_WARN_AGE 7
UID Minimum - Determines the first UID that will be assigned to an ordinary
user.
UID_MIN 500
GID Maximum - The maximum number of days that a user can continue to use
the same password.
GID_MAX 60000
Home Directory - Determines whether or not a new directory will be created for
the user when their account is created.
CREATE_HOME yes
User Configuration
Mail Directory - The directory in which the user's mail spool file will be created.
MAIL_DIR /var/mail/spool
Password Max Days - The maximum number of days that a user can continue to use
the same password.
PASS_MAX_DAYS 99999
Password Min Days - The shortest time that a user is required to keep a password.
PASS_MIN_DAYS 0
User Configuration
Umask- Determines what the default permissions will be on the user home directory.
UMASK 077
UPG - If UPG is used in the distribution, it will have a value of yes. If not, a value of no.
USERGROUPS_ENAB yes
Encryption - The encryption method that is used to encrypt the users' passwords in
the /etc/shadow file.
ENCRYPT_METHOD SHA512
Account Considerations
● Creating a user account may require additional information
○ You need the account name, you may also want to plan the UID, the primary
group, the supplementary groups, the home directory, the skeleton directory, and
the shell to be used.
Note: Requiring a user to change their password too often might also pose security
problems.
Setting a User Password
● There are a few ways a password can be set up:
○ User can execute passwd command
○ Graphical tools
● Users must follow guidelines for entering passwords while root can
bypass warnings:
root@localhost:~# passwd jane
Enter new UNIX password:
BAD PASSWORD: it is WAY to short
BAD PASSWORD: is too simple
Retype new UNIX password:
Modifying a User
● Use who, w, and last commands to verify if user is currently logged
in.
● The usermod command offers multiple options for modifying users.
● Examples of usermod options include:
Short Option Long Option Description
-c COMMENT Sets the value of the GECOS or
comment field to COMMENT.