Users

A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system.

After installation of the operating system, the ID 0 is assigned to the root user and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.

In a single directory, we can create 60,000 users.

User Management

Now we will discuss the important commands to manage users in Linux.

  1. AWK command

To list out all the users in Linux, use the awk command with -F option. Here, we are accessing a file and printing only first column with the help of print $1 and awk.

awk -F':' '{ print $1}' /etc/passwd 
  1. ID command

Using id command, you can get the ID of any username. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user.

id username
  1. Useradd command

The command to add a user. useradd command adds a new user to the directory. The user is given the ID automatically depending on which category it falls in.

The username of the user will be as provided by us in the command.

sudo useradd username
  1. Password command

Using passwd command to assign a password to a user.

After using this command we have to enter the new password for the user and then the password gets updated to the new password.

passwd username
  1. User Configuration

This commands prints the data of the configuration file. This file contains information about the user in the format.

cat /etc/passwd
  1. Usermod command

The command to change the user ID for a user.

usermod  -u new_id username
Ex: sudo usermod -u 1982 user1
  1. Change User Login Name command

You can change the user login name using usermod command. The below command is used to change the login name of the user.

The old login name of the user is changed to the new login name provided.

sudo usermod -l new_login_name old_login_name
  1. User Directory setup command

The command to change the home directory.

The below command change the home directory of the user whose username is given and sets the new home directory as the directory whose path is provided

usermod -d new_home_directory_path username
  1. Delete user

You can also delete a user name. The below command deletes the user whose username is provided.

userdel -r username
  1. User Database Files

/etc/passwd — → this file contains all user details as a list.
/etc/shadow — → this file contains all user password details as a list.

User and group management in Linux is vital for maintaining security and access control.

Last updated