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

2019-07-24 11:27发布

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?)

标签: bash ssh
1条回答
放荡不羁爱自由
2楼-- · 2019-07-24 11:46

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.

查看更多
登录 后发表回答