Users & Group Management
Users & Group Management
Linux
Liban Bashir
Network Security Administrator/
Former SYSTEM ADMIN
RHCSA / RHCE & RED HAT
VIRTUALIZATION
Liben.bashir@gmail.com
Introduction to Linux -
agenda
Users,
Groups
Permissions in Linux
Linux User Management
Linux stores user and group data in specific files and directories
that contain user account info, passwords, and group
configurations. System administrators can interact with these
files to control and modify user and group settings in Linux.
The main files and directories for storing user data in Linux
include:
/etc/passwd. The passwd file contains a list of user accounts
and the corresponding user ID, group ID, home directory, and
the default shell. It is readable by most users, but only root and
sudo accounts can add new users or remove and modify
existing user data.
/etc/group. The group file contains a list of user groups. Each
line in the file represents a group and displays the group name,
GID, and group members. Administrators can interact with this
file to manage settings for an entire collection of users.
Linux User Management
/etc/sudoers. The sudoers file specifies which users have elevated permissions,
on which machines, and for which directories. Admins can use this file to
configure permissions for users and groups to use the sudo command.
/etc/shadow. The shadow file stores encrypted user password information and
other password-related data such as the password expiration date, last change
date, and account expiration date. It is only accessible by the root user or users
with appropriate privileges. The restricted access and encryption add another
security layer compared to the /etc/passwd file.
/etc/gshadow. The gshadow file stores encrypted user group password
information and other password-related data such as the password expiration
date, last change date, and account expiration date. Like the shadow file, it is
only accessible by the root user or users with appropriate privileges.
/etc/skel. The skel directory contains default configuration scripts and
templates such as .bashrc and bash_profile. The templates are copied to the
user's home directory when a new user is created, streamlining the provisioning
of new user accounts.
/etc/login.defs. The login.defs file contains system-wide user account policy
settings, like the password aging policy. System administrators can refer to and
modify this file to enforce specific security and user management rules.
Check Currently Logged Users
The most efficient way to determine which
users are currently logged in a Linux system
is to use the who command. Enter the
following command to list currently logged
users:
Who
id : : /home/username : /bin/bash
The command to change the user ID
for a user.
usermod -u new_id username
This command can change the
user ID of a user. The user with
the given username will be
assigned with the new ID given
in the command and the old ID
will be removed.
Example: sudo usermod -u 1982
test
Command to Modify the group ID of
a user.
usermod -g new_group_id username
This command can change the group
ID of a user and hence it can even be
used to move a user to an already
existing group. It will change the
group ID of the user whose username
is given and sets the group ID as the
given new_group_id.
Example: sudo usermod -g 1005 test
change the user login
root:x:0:0:root:/root:/bin/bash
user1:x:1002:1002::/home/user1:/bin/sh
user2:x:1003:1002::/home/user2:/bin/sh
user3:x:1004:1002::/home/user3:/bin/sh
user4:x:1006:1003::/home/user4:/bin/sh
user5:x:1007:1003::/home/user5:/bin/sh
View users
Each entry has the following features:
$ getent group
This should give an output similar to:
leads:x:1002:user1,user2,user15
developers:x:1003:user3,user4,user5,user6,user7,us
er8,user9
Marketing:x:1004:user10,user11,user12,user13,user
14
Next, let’s define the level of access allowed for each
group.
Permissions and Ownership
The reason Linux so elegantly supports a multi-user system
is as a result of permissions. Permissions grant users the
right to access files and directories within the system. In
Linux, the basic permissions are:
Read : the right to open and view the contents of files and
directories. Represented by r
Write: the right to modify the content of a file and to add,
remove and rename files within a directory. Represented by
w
Execute: the right to run a script or application. Represented
by x
Let’s demonstrate the significance of file permissions; create
3 separate files using the following command:
$ ls -l
The output of this command should be similar to this:
The first ten characters -rw-r--r-- symbolize the file access permissions:
the first character refers to the file type, where - means a regular file. Other
notations are d for a directory, l for a symbolic link, and so on.
the other nine characters define access permissions to the file type — the first
three characters rw-are user permissions, the next three r-- are group
permissions while the last three r-- are permissions for all other users.
root: the user that owns (created) the file
root: the group that owns the file
With the above information in mind, we will assign a specific group to its related
file.
Assign Group Ownership
We want each file to belong to its own group. To do this, let’s
assign group ownership using the chgrp (short for change group)
command. The syntax for this command is:
$ sudo su user5
Now, let’s attempt to read a file that does not belong to the developers group.
Run the following command to view the leads.txt file:
$ cat leads.txt
You should get a warning that says: