Lock user account under Linux

2009-03-12 12:39:00 by Saz

Ever wanted to lock an user account under Linux, but don't know how? Well, today, I was in this situation, but don't know, how to do it. Now I know :)

Lock user account:

root@host:~# passwd -l username

This will change the password to a value, which won't match a possible encrypted value.

Unlock user account:

root@host:~# passwd -u username

This will change the password back to it's original value. If you want to know the status of an account (or all of them), you can use

# List all accounts
root@host:~# passwd -S -a|awk '($2 == "L")'
# List one account
root@host:~# passwd -S username

An L at the second position shows that an account is locked, a P marks a valid password, NP stands for No Password. Have a look at **man passwd** to find out more. But be sure to read the english man page, as the german version is lacking some information (it took me quite some time to find out what -a stands for).


Comments

Fork me on GitHub