我们可以在等待密码时使 ssh 超时吗

cod*_*ter 4 ssh timeout

我编写了一个脚本,希望从某个地方获取一堆主机名并在每个主机上运行命令:

ssh "$host" some command
Run Code Online (Sandbox Code Playgroud)

我拥有ssh无需密码即可建立连接的必要配置。但是,有时我们会遇到需要密码的主机而脚本挂起。

有没有办法在等待密码时使 ssh 超时?我不想使用timeout命令。

ilk*_*chu 5

这些选项中的任何一个都可能在客户端工作以完全防止询问密码,这似乎适用于您的情况。(我假设您可以从某些日志中找到失败的主机并以交互方式重新运行它们。)来自ssh_config(5)

BatchMode
    If set to yes, passphrase/password querying will be disabled. ...

PasswordAuthentication
    Specifies whether to use password authentication.
    The argument to this keyword must be yes (the default) or no.
Run Code Online (Sandbox Code Playgroud)

所以,

ssh -oBatchMode=yes someuser@somehost ...
Run Code Online (Sandbox Code Playgroud)

或者

ssh -oPasswordAuthentication=no someuser@somehost ...
Run Code Online (Sandbox Code Playgroud)


man*_*n0v 2

您正在sshd_config.

sshd_config(5)

LoginGraceTime
             The server disconnects after this time if the user has not successfully logged in.  If the value is 0, there is no time
             limit.  The default is 120 seconds.
Run Code Online (Sandbox Code Playgroud)