I've got a shell script that ssh'es into a server using public key authentication and runs a command on that machine. This works fine on machines where the users have installed the public key on the server. If this script is run from a machine where the user hasn't set up the authentication key, then the script will be stuck at password prompt. I want my script to carry on instead of getting stuck at the prompt. How can I bypass the prompt? I'm on a Mac OSX. The server is also running OSX
Ssh – Bypass ssh password prompt from a shell script
osxssh
Best Answer
One way to do this is by specifying
-o PasswordAuthentication=No
as part of your SSH command:ssh -o PasswordAuthentication=no user@server
This removes PasswordAuthentication from the list of authentication choices that the SSH client has to talk to the server, prevent you from sticking on the Password prompt. Note that this also allows other authentication mechanisms other than PubkeyAuthentication to work (RHostsRSAAuthentication, etc). If you want to use PubkeyAuthentication only...
ssh -o PreferredAuthentications=publickey user@server