I have a script which runs another script via SSH on a remote server using sudo. However, when I type the password, it shows up on the terminal. (Otherwise it works fine)
ssh user@server "sudo script"
What's the proper way to do this so I can type the password for sudo over SSH without the password appearing as I type?
Depending on your usage, I had success with the following:
This will prompt for the root password and then execute the command correctly.
The best way is
ssh -t user@server "sudo <scriptname>"
, for examplessh -t user@server "sudo reboot"
. It will prompt for password for user first and then root(since we are running the script or command with root privilege.I hope it helped and cleared your doubt.
I was able to fully automate it with the following command:
Advantages:
Regarding security: as Kurt said, running this command will show your password on your local bash history, and it's better to save the password in a different file or save the all command in a .sh file and execute it. NOTE: The file need to have the correct permissions so that only the allowed users can access it.
Another way is to use the
-t
switch tossh
:See
man ssh
:I faced a problem,
Then I tried with
didn't work
that worked properly!