I'm trying to connect to various servers to change the password of a specific user.
I need to build a Script to do that thing, the complexity is that I have to use sudo and send the password in order to connect on the remote server as root.
I'm trying something like this but is not working:
sshpass -p pass ssh user@server << EOF echo pass | sudo -S -u root "echo 'user2:pass2' | chpasswd" EOF
To better explain what I want to do, these are the steps that I need to do:
- connect to a server with my user.
- using "sudo" to connect as a root.
- execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2.
This is the error:
Pseudo-terminal will not be allocated because stdin is not a terminal. stat: cannot stat `pipe:': No such file or directory [sudo] password for user1: sudo: echo 'user2:XXXXXXX' | chpasswd: command not found