By Sheldon L | Published at 2020-05-01 | Updated at 2020-05-01 |
For each user, the following seven fields are maintained in the /etc/passwd
file:
Field Name | Details | Remarks |
---|---|---|
Username | User login name | Should be between 1 and 32 characters long |
Password | User password, the character x is stored in the /etc/shadow file in encrypted format |
Is never shown in Linux when it is being typed; this stops prying eyes |
User ID (UID) | Every user must have a user id (UID) | UID 0 is reserved for root, 1-99 are reserved for other predefined accounts, 100-999 are reserved for system accounts and groups, Normal users have UID’s of 1000 or greater |
Group ID (GID) | The primary Group ID (GID); stored in the /etc/group file |
Linux 9 - Basics of Linux: Managing Processes; Linux 13 - Users, Environment and Permissions in Linux |
User Info | This field is optional and allows insertion of extra information about the user such as their name | For example: Rufus T. Firefly |
Home Directory | The absolute path location of user’s home directory | For example: /home/rtfirefly |
Shell | The absolute location of a user’s default shell | For example: /bin/bash |
/etc/login.def
By default, Linux distinguishes between several account types in order to isolate processes and workloads. Linux has four types of accounts:
The last
utility, which shows the last time each user logged into the system, can be used to help identify potentially inactive accounts which are candidates for system removal.
root
is the most privileged account on a Linux/UNIX system. This account has the ability to carry out all facets of system administration, including adding accounts, changing user passwords, examining log files, installing software, etc. It has no security restrictions imposed upon it.
When you are signed in as, or acting as root, the shell prompt displays ‘#’ (if you are using bash and you have not customized the prompt, as we have discussed previously). This convention is intended to serve as a warning to you of the absolute power of this account.
root privileges are required to perform operations such as:
A regular account user can perform some operations requiring special permissions; however, the system configuration must allow such abilities to be exercised.
SUID
(Set owner User ID upon execution - similar to the Windows “run as” feature) is a special kind of file permission given to a file. Use of SUID provides temporary permissions to a user to run a program with the permissions of the file owner
(which may be root) instead of the permissions held by the user
.
Operations that do not require Root privilege | Examples of this operation |
---|---|
Running a network client | Sharing a file over the network |
Using devices such as printers | Printing over the network |
Operations on files that the user has proper permissions to access | Accessing files that you have access to or sharing data over the network |
Running SUID-root applications | Executing programs such as passwd |
su |
sudo |
---|---|
When elevating privilege, you need to enter the root password. Giving the root password to a normal user should never, ever be done. | When elevating privilege, you need to enter the user’s password and not the root password. |
Once a user elevates to the root account using su, the user can do anything that the root user can do for as long as the user wants, without being asked again for a password. | Offers more features and is considered more secure and more configurable. Exactly what the user is allowed to do can be precisely controlled and limited. By default the user will either always have to keep giving their password to do further operations with sudo, or can avoid doing so for a configurable time interval. |
The command has limited logging features. | The command has detailed logging features. |
sudo
sudo
has the ability to keep track of unsuccessful attempts at gaining root access. Users’ authorization for using sudo
is based on configuration information stored in the /etc/sudoers
file and in the /etc/sudoers.d
directory.
Whenever sudo
is invoked, a trigger will look at /etc/sudoers
and the files in /etc/sudoers.d
to determine if the user has the right to use sudo and what the scope of their privilege is. Unknown user requests and requests to do operations not allowed to the user even with sudo are reported. The basic structure of entries in these files is who where = (as_whom) what
/etc/sudoers
contains a lot of documentation in it about how to customize. Most Linux distributions now prefer you add a file in the directory /etc/sudoers.d
with a name the same as the user.
You should edit any of these configuration files by using visudo
, which ensures that only one person is editing the file at a time, has the proper permissions, and refuses to write out the file and exit if there are syntax errors in the changes made. The editing can be accomplished by doing a command such as the following ones:
visudo /etc/sudoers
visudo -f /etc/sudoers.d/student
By default, sudo commands and any failures are logged in /var/log/auth.log
under the Debian distribution family, and in /var/log/messages
and/or /var/log/secure
on other systems. This is an important safeguard to allow for tracking and accountability of sudo use. A typical entry of the message contains:
sudo whoami
cat /var/log/auth.log | grep whoami
# Dec 8 14:20:47 server1 sudo: op : TTY=pts/6 PWD=/var/log USER=root COMMAND=/usr/bin/whoami
Linux is considered to be more secure than many other operating systems because processes are naturally isolated from each other. One process normally cannot access the resources of another process, even when that process is running with the same user privileges. Linux thus makes it difficult (though certainly not impossible) for viruses and security exploits to access and attack random resources on a system.
More recent additional security mechanisms that limit risks even further include:
cgroups
)cgroup
.Containers
containers
) on a single system by relying on cgroups
.virtual machines
) on one physical host.Linux limits user access to non-networking hardware devices in a manner that is extremely similar to regular file access. Applications interact by engaging the filesystem
layer (which is independent of the actual device or hardware the file resides on). This layer will then open a device special file (often called a device node
) under the /dev
directory that corresponds to the device being accessed. Each device special file has standard owner, group and world permission fields. Security is naturally enforced just as it is when standard files are accessed.
Hard disks, for example, are represented as /dev/sd*
. While a root user can read and write to the disk in a raw fashion, for example, by doing something like echo hello world > /dev/sda1
The normal reading and writing of files on the hard disk by applications is done at a higher level through the filesystem, and never through direct access to the device node
.
Originally, encrypted passwords were stored in the /etc/passwd
file, which was readable by everyone. This made it rather easy for passwords to be cracked.
On modern systems, passwords are actually stored in an encrypted format in a secondary file named /etc/shadow
. Only those with root access can read or modify this file.
Protecting passwords has become a crucial element of security. Most Linux distributions rely on a modern password encryption algorithm called SHA-512 (Secure Hashing Algorithm 512 bits), developed by the U.S. National Security Agency (NSA) to encrypt passwords.
The SHA-512 algorithm is widely used for security applications and protocols. These security applications and protocols include TLS, SSL, PHP, SSH, S/MIME and IPSec. SHA-512 is one of the most tested hashing algorithms.
echo -n string | sha512sum
chage
, which configures the password expiry information for a user.chage --list [user]
sudo chage -E 2014-31-12 [user]
Another method is to force users to set strong passwords using Pluggable Authentication Modules (PAM
). PAM
can be configured to automatically verify that a password created or modified using the passwd
utility is sufficiently strong. PAM configuration is implemented using a library called pam_cracklib.so
, which can also be replaced by pam_passwdqc.so
to take advantage of more options.
One can also install password cracking programs, such as John The Ripper, to secure the password file and detect weak password entries. It is recommended that written authorization be obtained before installing such tools on any system that you do not own.