Linux User Account
Linux User Account
UID is fixed. It cannot be changed. Once assigned, it always remains the same
for that user account.
Username is used to access the user account. Username is also known as login
name. UID is used to authenticate, track and monitor the activity of user
account. Username is used by the user while the UID is used by the system
This is the normal user account. During the installation, one regular user
account is created automatically. After the installation, we can create as many
regular user accounts as we need. This account has moderate privilege. This
account is intended for routine works. It can perform only the tasks for which
it is allowed and can access only those files and services for which it is
authorized. As per requirement, it can be disabled or deleted.
The service account
Service accounts are created by installation packages when they are installed.
These accounts are used by services to run processes and execute functions.
These accounts are neither intended nor should be used for routine work.
If supplied username and password are correct and all above conditions are
satisfied, user is allowed to login.
Since the entire user management system is controlled through these files,
Linux itself maintain and update a back copy of each file in same directory.
The back copy is stored with the original name. To distinguish the backup
copy from original copy, a hyphen sign is used as prefix in the name of the
backup copy.
Following table lists the name of backup file along with original file.
In Linux every user must be a member of at least one group. While we create a
user account, shell automatically creates a group and adds created user in it.
This group is known as user’s primary group. Unless we manually change or
update a user’s primary group name, it matches with the username. For
example, if username is john, his default primary group name will also be john.
Besides primary group, additional groups can be setup as per requirement.
The file /etc/group stores group information. Each line in this file stores one
group entry. Each line contains following four fields separated by colons.
Group password
If the group password is used, this field stores a place holder character, to
indicate that the password is stored in a separate file. If the group password is
not used then this field is kept blank.
GID
Group members
Since a group may contain several members and a user can be the member of
several groups, a user’s primary group information can’t be revealed from this
file. To reveal a user’s primary group information, always the /etc/passwd file
should be used.
The /etc/gshadow file
This file stores group password and other password related information.
Password information of each group is stored in an individual line. There are
four fields in each line.
Group password
Group admin
This file contains a list of all user accounts. Each user account is stored in an
individual line. Each line contains following seven fields separated by colons.
1. Username
2. Placeholder character for password
3. UID
4. GID
5. Description
6. Home directory
7. Login shell
This file stores users’ password and password related information. Just
like /etc/passwd file, this file also uses an individual line for each entry. Each
line contains following nine fields.
1. Username
2. Encrypted password
3. Number of days when password was last changed
4. Number of days before password can be changed
5. Number of days after password must be changed
6. Number of days before password expiry date to display the warning
message
7. Number of days to disable the account after the password expiry
8. Number of days since the account is disabled
9. Reserved field
#cat /etc/passwd
Each line in /etc/passwd file represents an individual user account and
contains following seven fields separated by colons (:).
The first field stores username or login name. Login process compares the
value stored in this field with the value we typed at the login prompt in
username field. If both values match, login process assumes that username is
valid. While comparing username, login process starts looking for the supplied
username in the first field of each line starting from first line and keeps
looking until a match is found or all lines are checked.
Since each line represents an individual user account, the value stored in this
field must be unique.
This field can store maximum 32 characters. Due to this limit, a username in
Linux always consists less than or equal to 32 characters in length.
This field does not have any default value. It means, in order to create a new
user account, we must have to supply the desired username.
Although we are allowed to use any symbol or character except colons and
newlines, still we should never use special symbols in this field. A username
with special symbol works in login process, but it may not work in other
processes or services. Let’s take an example to understand it more clearly.
While phrasing this address, email server will understand domain name
as “[email protected]” instead of “example.com” and username
as “sanjay” instead of “sanjay@goswami”.
An email sent on this address will never deliver. The best and safest way to
avoid this kind of error, always use alphanumeric characters and generic
symbols such as underscore and hyphen in username.
Encrypted password
The second field stores encrypted password. Historically, this field was used to
store user’s password encrypted with DES algorithm. Over the time computing
power increased and DES algorithm became trivial to crack.
User ID
Third field stores UID of user. In Linux, every user has a unique ID known as
UID (User ID). UID is a 32 bits integer value. Linux uses UID to track and
manage each action of user such as creating file, modifying system properties,
starting applications and process, etc. The first UID (0) is always assigned to
user root. Besides 0, other low UIDs (usually less than 500) are assigned to
service accounts such bin, lp, mail, news, games, ftp etc. UIDs of regular user
accounts usually start from 500.
Never assign a deleted user account’s UID to a new user account. Linux uses
UID rather than login name to tack the files. If files created under deleted
account exist in system or restored from backup, new user will be mapped
with those files automatically.
Group ID
In Linux, every user belongs to one or more groups. While creating a user
account, if we don’t specify the group name, shell automatically creates a new
group and adds user account in that group. This group is known as primary
group or default group of the user. Once user account is created, as per
requirement it can be added in other groups. Other groups will be considered
as secondary groups of the user.
Fourth field in each line, stores GID of user’s primary group. Group
information of a user account is stored in /etc/group file separately. Just like
username, group name is also associated with a unique GID. Same as UID, GID
is a 32 bits integer value. Linux uses GID instead of group name to track,
monitor and authenticate the activities of group.
User description
Fifth field stores descriptive information about the user. In a multiuser
environment where several users use system, if stored, this field provides all
necessary information about a user such as his full name, email address,
phone number, position in organization, etc. Usually the chfn utility is used to
store and the finger utility is used to read this information.
Home directory
Sixth field stores information about user’s home directory. Login process uses
this information to decide where it has to put the user just after the login. In
other words, this is the default directory which user gets just after the login
process. While creating a user if this information is omitted, shell automatically
sets it to /home/username.
If login process does not find user’s home directory at the location specified in
this field, depending on system configuration, it may either completely
disallow the login or put the user in / directory. Getting root (/) directory just
after the login is an indication that user’s home directory is missing or not
accessible.
Login shell
The last field stores information about user’s default shell. If no shell
information is specified while creating a regular user account, shell will use
default value which is /bin/bash. If no shell is required, this field can be set to
blank.
$cat /etc/shadow
$sudo cat /etc/shadow
[sudo] password for super user
Following figure shows above commands with output.
As you can see in above figure, when we tried to view the content
of /etc/shadow file from a regular user account, shell denied the action. But
when we performed the same action from a root user or super user account,
shell allowed to it.
This security feature keeps encrypted passwords safe from unauthorized users
and password cracking programs.
1. Username
2. Encrypted password
3. Date of last password change
4. Minimum required days between password changes
5. Maximum allowed days between password changes
6. Number of days in advance to display password expiration message
7. Number of days after password expiration to disable the account
8. Account expiration date
9. Reserve field
Let’s understand each field in detail.
Username
Encrypted password
This field stores actual user password in encrypted form. For encryption it uses
SHA512 algorithm. In this algorithm, a random salt is mixed with original
password before encryption. If two or more users have selected the same
password, due to this feature, their encrypted passwords will be different.
Controlling Login
Linux does not support blank password in login process. Any user or service
which does not have a valid password or have a blank password is not allowed
to login. By setting a value other than an encrypted password, this field can be
used to control the user login. For example, if the value (!) or (*) is stored in
this field, the account will be locked and user or service will not be allowed to
login.
This field sets the minimum required days that must be elapsed between
password changes. Once a password is changed, a user is not allowed to
change his password until the days specified in this field are elapsed. If the
value is set to 0 (zero), user is allowed to change his password immediately.
This filed sets the maximum allowed days between password changes. Once a
password is changed, a user must have to change his password again before
the days specified in this field are elapsed. In other word, the days specified in
this field are the maximum allowed days for a user to use a password. If this
field is set to blank, a user can use his password as long as he wants to use.
Warning message will be display only when user will be login in command line
terminal. This message will not be displayed if user is login in GUI desktop.
Number of days after password expiration to disable the account
This field sets the number of days after password expiration to disable the
account. If a user does not change his password in maximum allowed days, his
password will be marked as expired. A user account which password is expired
will be disabled automatically once the days specified in this field are elapsed.
This field sets an account expiration date. A user is not allowed to login after
the date specified in this field. To specify a date, number of days starting from
1 January 1970 is used. For example, to set account expiration date to 28 June
2018, number 17710 will be used. If this field is set to blank, user account will
never expire.
Reserve field
The last field is reserved for future. Since it’s a reserved field and does not
store any value, usually it is skipped while formatting this file.
Understanding /etc/shadow file entries with
example
An entry in /etc/shadow file looks like following.
john:
$6$iTEFbMTM$CXmxPwErbEef9RUBvf1zv8EgXQdaZg2eOd5uXyvt4sFzi6G4lIqavLilTQgniAHm3Czw/LoaGzo
FzaMm.YwOl/:17707:0:90:14:::
Following table explains this entry field by field.
john:
$6$iTEFbMTM$CXmxPwErbEef9RUBvf1zv8EgXQdaZg2eOd5uXyvt4sFzi6G4lIqavLilTQgniAHm3Czw/LoaGzo
FzaMm.YwOl/:17707:0:90:14:::
Following table explains this entry field by field.
Field Description
john This is the username.
$6$iTEFbMTM$CXmxPwErbEef9 This is the encrypted
RUBvf1zv8EgXQdaZg2eOd5uXyvt4sFzi6G4lI password.
qavLilTQgniAHm3Czw/LoaGzoFzaMm.YwOl/
17707 John last changed his
password on 25 June
2018.
0 If require, John can
change his password
immediately
90 John can use this
password till 30
September 2018. (90 + 7
grace days).
14 After 15 September 2018
whenever John will
login in CLI terminal,
he will get a warning
message to change his
password.
[bank field] John account will not
be disabled even if his
password is expired.
[blank field] John account will never
expire.
Reserve filed is
omitted.