1) Add User
[root@RedHat ~]# useradd udaipur
[root@RedHat ~]# passwd udaipur
Changing password for user udaipur.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
2) To change settings of user use "usermod"
Changed userid from 1002 to 2121
[root@RedHat mail]# usermod -u 2121 mukesh
[root@RedHat mail]# grep mukesh /etc/passwd
mukesh:x:2121:1002::/home/mukesh:/bin/bash
3) To search in file with specific word
[root@RedHat ~]# getent passwd mukesh
mukesh:x:1002:1002::/home/mukesh:/bin/bash
4) Password Lock
[root@RedHat mail]# passwd -l mukesh
Locking password for user mukesh.
passwd: Success
[root@RedHat mail]# passwd -S mukesh (-S for status)
mukesh LK 2021-01-15 0 99999 7 -1 (Password locked.)
[root@RedHat mail]# passwd -u mukesh
Unlocking password for user mukesh.
passwd: Success
[root@RedHat mail]# passwd -S mukesh
mukesh PS 2021-01-15 0 99999 7 -1 (Password set, SHA512 crypt.)
5) If users are created through script then we need to set password within script file.
[root@RedHat mail]# echo RedHat@2019 | passwd --stdin mukesh
Changing password for user mukesh.
passwd: all authentication tokens updated successfully.
6) If required to remove user password so that account can be logged without password
passwd -S user
7) In /etc/passwd "/bin/bash" means user can log.
8) If you want to disable user login then assign shell /sbin/nologin
9) To change password policy use "chage"
[root@RedHat ~]# chage -l mukesh
Last password change : Jan 15, 2021
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 99
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@RedHat ~]# chage mukesh
Changing the aging information for mukesh
Enter the new value, or press ENTER for the default
Minimum Password Age [99]:
Maximum Password Age [99999]:
Last Password Change (YYYY-MM-DD) [2021-01-15]: 2021-09-21
Password Expiration Warning [7]:
Password Inactive [-1]:
Account Expiration Date (YYYY-MM-DD) [-1]:
[root@RedHat ~]# chage mukesh
Changing the aging information for mukesh
Enter the new value, or press ENTER for the default
[root@RedHat ~]# chage -l mukesh
Last password change : Sep 21, 2021
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 99
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
10 ) To change home directory of user
[root@RedHat adminji]# cd india/
[root@RedHat india]# pwd
[root@RedHat india]# useradd -d /home/adminji/india/ usershell
[root@RedHat india]# ls
usershell -⇾ user directory created at /home/adminji/india rather than default /home.
11) How to change default directory while creating user
There is default file at location /etc/default/useradd
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
If you change value here then it will become the default setting for user creation.
GROUP=100
HOME=/home/adminji/india
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
12) Common hidden files for all user's home directory
[root@RedHat ~]# cd /etc/skel
bash: .l: command not found
[root@RedHat skel]# l.
. .. .bash_logout .bash_profile .bashrc
Comments