To lock a user in Ubuntu sudo usermod –expiredate 1 [username] Substitute the user’s username where username is shown below.
sudo usermod --expiredate 1 username
This also can be shortened to
sudo usermod -e 1 username
To unlock a user
sudo usermod -e -1 username
This will disable the user both from accessing via password and from accessing via a private key.
You can also expire a user at a future date using
sudo usermod -e YYYY-MM-DD username
To expire a password and force a user to enter a new password
sudo passwd -e YYYY-MM-DD username
Related: Managing Users in Ubuntu – Reset Root Password on MySQL Database – Don’t Copy-Paste Directly from Website to Terminal