All about Information Technology!

Lock or UnLock Linux User Account

To lock the account

sudo passwd -l username

 
To unlock the account (this command will change the password back to its previous value)

sudo passwd -u username

, , , , , ,

One Response to “Lock or UnLock Linux User Account”

  • idrositis | jdros says:

    The above command actually adds (or removes) a ‘!’ or ‘!!’ in front of the hashed password entry in /etc/shadow:
    user:$1$0AR6z6sk$2bW8iFthim9u7be0:15537:0:99999:7:::
    becomes:
    user:!$1$0AR6z6sk$2bW8iFthim9u7be0:15537:0:99999:7:::
    NOTEs:
    1. Certain older versions of passwd (ie. RHEL/CentOS 5.5 and others) just used to remove ‘!’ from hash value to unlock user, without the -f (force) flag and no other check or notice. Running passwd -u for a second time made the hash value: ‘::’ in other words empty, resulting in a non-password user :-) .
    2. Certain versions of sshd, even if you only use public key authentication, require shadow entry for given user NOT to begin with a ‘!’ (or to be ‘!!’). In that case the user is reported as ‘locked’.

Leave a Reply