How can I delete a password and lock the account in one step?
You may want to try:
usermod -p '!!' root
usermod
with the -p
parameters takes the raw value to bet set as encrypted password in the /etc/shadow
files.
The traditional usage of this parameter is to give to usermod
an already encrypted password, but it accepts also the '!!'
flagging the account as locked.
In the end, this command will remove the current password and leave only the exclamation marks setting the root account as locked in the passwd
way¹, all in one move using a safe and standard command, thus fulfilling the request.
¹: According to this discussion, there is no established standard on the way to lock an account. So usermod -L
uses only a single exclamation mark (!
) in front of the hashed password to lock it, while passwd -l
uses two (!!
).