×

Search anything:

Linux user management

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

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.

  1. Introduction.
  2. User accounts.
  3. User administration files.
  4. User management commands.
  5. Adding groups.
  6. Modifying groups.
  7. Deleting groups.
  8. Adding users.
  9. Modifying user accounts.
  10. Removing user accounts.
  11. User information.
  12. Switching user accounts.
  13. Summary.
  14. References.

Introduction.

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.

User accounts.

In Linux user accounts are of three types,

Root account
Also referred to as superuser, it has unfettered control of the whole system, in that the owner can run any and all commands.

System accounts
These are accounts required for the operation of system-specific components.

User accounts
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.

Command Description
useradd/adduser adding accounts.
groupadd/addgroup adding groups.
usermod modifying account attributes.
groupmod modifying group attributes
userdel/deluser deleting accounts.
groupdel/delgroup deleting groups.
chage change user password expiry info.

Adding groups.

We use the following syntax to create a group in the system,

groupadd [-g gid [-o]] [-r] [-f] groupname

An example
To create a group for employees we write,

groupadd employees

Modifying groups.

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

Deleting groups.

We use the groupdel command to delete groups as follows,

groupdel marketing

Adding users.

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

User information.

To view information about users on a system, the finger command is used.

An example
To view information about all logged in users we write,

finger

To view information about a single user we write,

finger johndoe

Switching users accounts.

In Linux we can switch accounts using the su (switch user),

An example
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.

Summary.

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.

References.

  1. Linux file permissions
Linux user management
Share this