如何设置ssh超时?

如何设置ssh超时?

问题描述:

我正在远程主机上执行通过无密码 SSH 连接的脚本.我想设置一个超时,这样如果远程主机需要无限长的时间来运行,我想退出那个 ssh 会话并继续我的 sh 脚本中的其他行.

I'm executing a script connecting via password-less SSH on a remote host. I want to set a timeout, so that if the remote host is taking an infinite time to run, I want to come out of that ssh session and continue other lines in my sh script.

如何设置超时时间?

ssh -o ConnectTimeout=10  <hostName>

其中 10 是以秒为单位的时间.此超时仅适用于连接的创建.

Where 10 is time in seconds. This Timeout applies only to the creation of the connection.