Linux is a multiuser operating system and thus can support several users working on a given system concurrently. User management entails adding, modification(editing, suspension) and removal of user accounts along with their permissions.
Table of contents.
- User accounts.
- User administration files.
- User management commands.
- Adding groups.
- Modifying groups.
- Deleting groups.
- Adding users.
- Modifying user accounts.
- Removing user accounts.
- User information.
- Switching user accounts.
A user is an entity in a system that can perform operations such as creation and deletion of files, execution of scripts and much more.
In this article we discuss the described tasks involving users accounts and group management, you can learn more about user permissions in the link provided in the references section.
In Linux user accounts are of three types,
Also referred to as superuser, it has unfettered control of the whole system, in that the owner can run any and all commands.
These are accounts required for the operation of system-specific components.
These provide access to other users and user groups. They have a limited access to the system's files and directories.
In Linux we can also group accounts together, this is useful for file permissions and process management.
User administration files.
These are files used for the administration of users on a Linux system, they include,
- /etc/passwd: which is responsible for storing user account and password information.
- /etc/shadow: responsible for storing encrypted passwords of a corresponding user account.
- /etc/group: this will contain group information for each account.
- etc/gshadow: holds secured group accounts information.
User management commands.
|usermod||modifying account attributes.|
|groupmod||modifying group attributes|
|chage||change user password expiry info.|
We use the following syntax to create a group in the system,
groupadd [-g gid [-o]] [-r] [-f] groupname
To create a group for employees we write,
Assuming we want to change the group name employees to marketing we can write,
groupmod -n employees marketing
To change the GID we use the -g option as follows,
groupmod -g newGID marketing
We use the groupdel command to delete groups as follows,
To create a new user we write,
sudo adduser johndoe
A prompt for a password, its confirmation and user details will appear. After filling the information a new user account is created.
To view the created user navigate to the /home directory.
cd /home && ls
If we opt to use the useradd command make sure to use the passwd command to set a password for the account as follows,
sudo useradd johndoe sudo passwd johndoe
To view the encrypted password write,
sudo grep johndoe /etc/shadow
Modifying user accounts.
To add a user to a group we write,
sudo usermod -a -G marketing johndoe
To view all existing groups we write,
groupmod "press tab twice!!"
To remove a user from a group we write,
sudo deluser johndoe marketing
Removing user accounts.
To disable a user account, we write,
sudo passwd -l johndoe
To completely remove a user from the system we write,
sudo userdel -r johndoe
To view information about users on a system, the finger command is used.
To view information about all logged in users we write,
To view information about a single user we write,
Switching users accounts.
In Linux we can switch accounts using the su (switch user),
To switch accounts from current user to johndoe account we write,
sudo su johndoe
The chsh command can be used to change a users login shell as follows
chsh -s /bin/bash
Use the exit command to exit johndoe's shell.
Linux is a multiuser operating system and thus can support several users working on a given system concurrently.
User management is necessary for such a system to maintain order.
It is also important to consider that two or more users may need to share system resources such as files and directories, with groups this is possible.
One can also opt to manage users via the provided GUI so as to avoid mistakes if not yet proficient in the command line interface.