I'm using ssh and have a passwordless ssh setup for my system. Using ssh in a script works fine, but if the user specifies a host that don't has a passwordless ssh setup the script prompts for a password and hangs.
How could I avoid the password prompt and return an error if passwordless ssh is not setup for the host?
SSH uses private/public key pairs to protect your communication with the server. SSH passphrases protect your private key from being used by someone who doesn't know the passphrase. Without a passphrase, anyone who gains access to your computer has the potential to copy your private key.
With an SSH Key set up, you can also safely log in to your server without any need for a password at all. The server will require the connecting computer to have the private key associated with the server's public key to connect.
ssh -o PasswordAuthentication=no user@hostname
See man page of ssh_config
for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With