How can I check a remote machines root password?
I have a remote machines that are normally accessed via ssh root and other users. For security purposes I have a script to change all keys and user passwords periodically from a central server.
For non root users the password is updated like so.
ssh -i a_priv_key root@ip "echo 'user:NEWPASS' | chpasswd"
And I check it has actually changed with this.
ssh -i b_priv_key user@ip "echo NEWPASS | sudo -S ls /root"
However if I want to do the same with the root user I am stuck. The sudo -S ls /root always returns a listing with any password because we just ssh'd in to the remote machine as root.
And if we ssh in as user sudo prompts for user's password.
I have been trying to get something with su user && su root because I noticed it will prompt for a root password but am not able to script it like the above.
'login root' from the root shell will also always prompt for a password but I cannot script the clear-text password to that either.
I have read this question but was hoping for a inbuilt method to do it rather than writing a custom application that must be installed on the remote machines. How to check password with Linux?
expect
is a good way to automate that for commands that read the password from a pty (like you mentionedsu
orlogin
.) You can runexpect
locally and have it start the ssh connection, so no need to install it on the remote machines. – filbranden May 29 '19 at 11:40echo NEWPASS
on ssh is quite insecure! It might make it into log files and even be visible fromps
, so you'd be leaking your passwords. At the very least, use something like<<<NEWPASS
(assumingbash
, this is abash
syntax) passing that to the stdin of ssh itself rather than as part of the command string. Butexpect
is possibly a better way to make this slightly more secure (still pretty scary though.) – filbranden May 29 '19 at 11:44