Can I change a user password in Linux from the command line with no interactivity?
Solution 1:
You could use chpasswd.
echo user:pass | /usr/sbin/chpasswd
Solution 2:
You can use usermod
with the -p
option to provide a password hash (not the actual password). You can generate the password hash using something like mkpasswd -m sha-256
or mkpasswd -m md5
Solution 3:
Sure.
- Hash the password on your local system.
- Connect to the remote machine (where you want to change the password)
- Feed the hashed password & the username to a creative
sed
script that updates your system's password file (/etc/shadow
,/etc/master.passwd
, whatever it happens to be).