Live as if you were to die tomorrow. Learn as if you were to live forever.

Thursday, 19 February 2015

Some important questions on users and groups

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


change file as shown below
#vi /etc/shadow


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


Change as shown below
#vi /etc/shadow


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

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$
mysql:x:27:27:MySQL Server:/var/lib/mysql:/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