Domanda

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?

È stato utile?

Soluzione

ssh -o PasswordAuthentication=no user@hostname

See man page of ssh_config for more details.

Altri suggerimenti

Setting PasswordAuthentication didn't work for me but this did:

ssh -o BatchMode=yes user@hostname

From ssh_config(5)

BatchMode If set to ''yes'', passphrase/password querying will be disabled. This option is useful in scripts and other batch jobs where no user is present to supply the password. The argument must be ''yes'' or ''no''. The default is ''no''.

For good measure you could also throw in StrictHostKeyChecking so it will automatically accept keys and avoid the prompt.

ssh -o StrictHostKeyChecking=no -o BatchMode=yes user@hostname
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top