Linux is a multi-user operating system that means you can add multiple users in as single Linux machine and access it with multiple accounts at same time.In this post we will learn some basic commands to manage users in Linux operating system. Lets start...
There are basically two types of accounts existed in Linux system.
1: User Accounts
2: System Accounts
A user accounts may be for a user like system admin or database admin etc and the system accounts for any services like sshd, httpd etc. You can configure the properties for creating accounts in /etc/login.defs
When an account created a specific UID and GID has been assigned with that account which can be check with Linux inbuilt command id . For normal user IDs starts with 1000 and for system accounts it is below then 1000. Here note that root account has always assigned with ID and GID 0 .
When a new user account created an entry for that user append in /etc/passwd file. In this file you can see the user accounts basic details like username, encrypted password, ID and GID, comments for user, default shell, login access info.
When a new account created and password supplied that information saved in /etc/shadow file. This file store data in colon separated values. In this file you can see the information like your password, last password change date, password validation date, next password change date etc. In this file your password stored in encrypted form. The encrypted password has basically three parts 1: algorithm type 2:salt value 3:hashes and these parts starts with dollar($) sign. If password starts with $6 that means it uses SHA516 algorithm to encrypt the password.
User Management Commands In Linux
In below pdf file you can learn how to create a user account with all possible options.
ID: This command is used to check the user account ID and GID and other important inforamtion. You can supply the flags in order to print or get specific information with this command.
1 : id -a command will gives output as same as id command with better compatibility.
# id -a
2 : id -G command will gives output about all groups ids assigned with the user who is currently logged in.
# id -G
3 : id 'username' command will gives output ID and GID values about supplied user name with the id command. Please replace 'username' with the actual username of user account
# id 'username'
Passwd: This is a simple utility to manage password for a user account. Below are some use of this command
1 : Simply execute passwd from currenlty login user account and this will give you prompt to change the password for current login user.
# passwd
2 : To change password for any other user simply supply the username along with passwd as passwd 'username'
# passwd 'username'
3 : Force user to change the password in next login, run below command
# passwd -e 'username'
4 : Set minimum age for a user password in days .
# passwd -n 'number of days' 'username'
5 : Set maximum age for a user password in days .
# passwd -x 'number of days' 'username'
6 : start showing warning message from number of days before password expires.
# passwd -w 'number of days' 'username'
7 : Set number of days after a password expire to make account disable/inactive.
# passwd -i 'number of days' 'username'
Userdel: To delete a user account, run this command as mentioned below.
# userdel 'username'
Usermod: To make any modification in user account e.g adding/removing supplementary group form user account,changing home directory, set expiry date for specific user account,inactive a user account, make user password disable etc.. can be done with this command
1 : To override user's supplementary group, run below command.
# usermod -G 'groupname' 'username'
2 : To add a another supplementary group without override another supplementary group, run below command.Note you can add multiple groups to a user account. see below example.
# usermod -aG 'groupname1' 'groupname2' 'username'
3 : To override user's primary group, run below command.
# usermod -g 'groupname' 'username'
4 : To add comment in user account in /etc/passwd file, run below command.
# usermod -c 'Your_Comment' 'username'
5 : To change the default home directory for a user account.
# usermod -d 'directory_path' 'username'
6 : Moves the contents of the user's current home directory to the new home directory. Only used with the -d flag.
# usermod -md 'directory_path' 'username'
7 : Set an expiry date for a user account. Account will be disable.
# usermod -e 'YYYY-MM-DD' 'username'
0 Comments