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.
[root@vps ~]# useradd anbu
Let’s create a username ‘anbu’ with some options.
[root@vps ~]# useradd -d /home/anbu -s /bin/bash anbu
You can see the created user’s information tghroiugh the below command
[root@vps ~]# grep anbu /etc/passwd anbu:x:1007:1011::/home/anbu:/bin/bash [root@vps ~]#
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.
[root@vps ~]# usermod -aG linux -d /opt/anbu -s /bin/sh anbu [root@vps ~]#
To see the modfied details, again use the command.
[root@vps ~]# grep anbu /etc/passwd anbu:x:1007:1011::/opt/anbu:/bin/sh [root@vps ~]#
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.
[root@vps ~]# userdel anbu [root@vps ~]#
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.
[root@vps ~]# userdel -r anbu [root@vps ~]#
Thanks for reading this aritcle, Hope It will help you 🙂