Mar
12
2009
0

Lock user account under Linux

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:

1
root@host:~# passwd -l username

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

Unlock user account:

1
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

1
2
# List all accounts
root@host:~# passwd -S -a|awk '($2 == "L")'
1
2
# 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).

Written by saz in: Linux | Tags: , ,

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com