How to Manage Local Users in Linux

Hi all !

User administration is one of the important task of Linux system administrator. Local accounts or users in Linux like operating system is managed by useradd, usermod, userdel, chage and passwd commands.

Commands to Manage Users :

  • useradd command is used to create new accounts in Linux
  • usermod command used to modify the existing accounts in linux
  • userdel command is used to delete local account in linux
  • passwd command used assign password to local accounts or users.
  • chage comamnd is used to view & modify users password expiry information

Lets see all commands one by one.

User Creation :

Syntax to create user

# useradd [options] LOGIN

Through the useradd command, we can create a new user or update default new user information.

Here options are optional only, We can create user without specifying options.

Let’s create a username ‘anbu’ with some options.

You can see the created user’s information tghroiugh the below command

Options:
-d, –home-dir HOME_DIR home directory of the new account
-g, –gid GROUP name or ID of the primary group of the new
account
-G, –groups GROUPS list of supplementary groups of the new
account
-h, –help display this help message and exit
-p, –password PASSWORD encrypted password of the new account
-s, –shell SHELL login shell of the new account
-u, –uid UID user ID of the new account

For more details see the man page of useradd.

Modifying the Existing User :

To modify the existing user, We can use usermod command.

SYNOPSIS
usermod [options] LOGIN

Already we have created user anbu. let’s make the anbu as part of secondary group  linux and change it’s home directory from /home/anbu to /opt/anbu and login shall from /bin/bash to /bin/sh.

To see the modfied details, again use the command.

You can seen man page of usermod to see more option do with usermod

User Deletion :

userdel command is used to delete local account in linux.

SYNOPSIS :
userdel [options] LOGIN

To delete the existing user, use the below command.

Note, it will delete the user account only. But still files related to the user anbu. in his  home directory and mail pool.

So delete user account with it’s file, Use the below command.

Thanks for reading this aritcle, Hope It will help you 🙂

 

 

 

 

 

 

 

 

 

About

View all posts by

Leave a Reply

Your email address will not be published. Required fields are marked *