How to disable/lock the user with the help of command and
using shadow file ?
Lock account using command
We can lock the user using usermod command with the help of
L to lock option and U to unlock the account.
#usermod -L test
It will lock the user test
#usermod -U test
It will unlock the user test
Lock and Unlock account using file
#vi /etc/shadow
test:$6$xb7FL2gXeJ9VbVP1$dRbWMmySxrDR8Kb8VQCfIg9IYlf1h72I84/cjqAiy2gR.VcWZeia4J/RzZXEHYNCAsPq4xDBmlgLo31Qsi2aP/:16461:0:99999:7:::
change file as shown below
#vi /etc/shadow
test:!$6$xb7FL2gXeJ9VbVP1$dRbWMmySxrDR8Kb8VQCfIg9IYlf1h72I84/cjqAiy2gR.VcWZeia4J/RzZXEHYNCAsPq4xDBmlgLo31Qsi2aP/:16461:0:99999:7:::
:wq
In this way you can lock the user account with the help of
file. In the same way you can unlock the account for that you have to
remove the ! in second column.
How to remove the password of the user using command and
using shadow file?
We can use passwd command with -d option to remove the
password of the user.
#passwd -d test
Remove password using file
Open file /etc/shadow in vi editor and remove the second
column
#vi
/etc/shadow
test:$6$xb7FL2gXeJ9VbVP1$dRbWMmySxrDR8Kb8VQCfIg9IYlf1h72I84/cjqAiy2gR.VcWZeia4J/RzZXEHYNCAsPq4xDBmlgLo31Qsi2aP/:16461:0:99999:7:::
Change as shown below
#vi /etc/shadow
test::16461:0:99999:7:::
:wq
Here, we have just removed the second column. So the system
will not prompt for password for that user.
How to change the login shell of the user?
You can use the usermod command to change the login shell of
the user with the help of -s option
#usermod -s /sbin/nologin
We can also edit the /etc/passwd file and add /sbin/nologin
instead of /bin/bash
How to check total number users in the system?
[root@server Desktop]# cat
/etc/passwd | wc -l
43
It will show the count of all the users in the system.
Use below command to see the users having login shell bash
[root@server Desktop]# cat
/etc/passwd | grep bash$
root:x:0:0:root:/root:/bin/bash
mysql:x:27:27:MySQL
Server:/var/lib/mysql:/bin/bash
test:x:500:500::/home/test:/bin/bash
dnyaneshwar:x:501:500::/home/dnyaneshwar:/bin/bash
pramod:x:502:500::/home/pramod:/bin/bash
vinod:x:503:500::/home/vinod:/bin/bash
Here, we have used grep command to check the bash shell. $
is used to check the bash word at the end of the line. So it will print all the
lines which contains bash at end of each line.
Guys, Please comment if you have any query or feedback…. :)
No comments:
Post a Comment