bash: check if I can ssh (with keys) to a list of

2019-07-24 10:58发布

问题:

I want to check if I can ssh to a list of hosts by only using keys.

This answer suggests doing the following:

exec ssh -o BatchMode=yes "user@host" true

... which should connect to the host, run true and return its exit status.

On my Ubuntu machine it doesn't work. Something in the above command forces the terminal to close. What did I do wrong?

(Also, since I am required to use the -l option to pass my username, the regular command would be: ssh -l user host. Will exec interpret this as something else?)

回答1:

exec causes the current shell to be replaced by ssh. When ssh exits, your terminal does as well. Just use

ssh -o BatchMode=yes "user@host" true

to return to your shell after ssh completes.



标签: bash ssh