Wiki‎ > ‎

Adduser vs Useradd (Debian/Ubuntu)

posted Feb 23, 2016, 8:27 AM by Dong Xu   [ updated Sep 23, 2017, 3:03 PM ]
Should use adduser which is a perl script that calls useradd and has enhanced features:

http://unix.stackexchange.com/questions/121071/what-does-adduser-do-that-useradd-doesnt

Lock a Password

To disable / lock the password of user account use below command. This will not disallow ssh-access on Ubuntu. This prepends a ! to the password hash so that no password will match it anymore.

# take away peters password
sudo passwd -l peter

To unlock him:

# give peter back his password
sudo passwd -u peter

passwd -l

that might be what you're looking for :)

from the passwd man page:

-l, --lock Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ´!´ at the beginning of the password).

Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators should use

usermod --expiredate 1 (this set the account's expire date to Jan 2, 1970).

Users with a locked password are not allowed to change their password.

How to disable user's login without disabling the account

Alter /etc/passwd manually like below

user1:x:1001:1001:,,,:/home/user1:/usr/sbin/nologin

after making change user1 is not being able to login from terminal but surprisingly can login from gnome

Comments