質問

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 -o PasswordAuthentication=no user@hostname

See man page of ssh_config for more details.

他のヒント

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top