5

I have written a script that is expected to get a bunch of host names from some place and run a command on each of those hosts:

ssh "$host" some command

I have the necessary configuration to make ssh connections without the need for a password. However, sometimes we encounter a host that does need a password and the script hangs.

Is there a way to make ssh time out while waiting for a password? I don't want to use the timeout command.

2

2 Answers 2

6

Either of these options might work on the client side to prevent asking the password at all, which seems it should work in your case. (I assume you can find the failed the hosts from some log and rerun them interactively.) From 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.

So,

ssh -oBatchMode=yes someuser@somehost ...

or

ssh -oPasswordAuthentication=no someuser@somehost ...
2
  • Nice answer. I wanted ssh to prompt for password but not be waiting forever if user doesn't enter the password. man0v's answer shows the way. Feb 28, 2018 at 7:07
  • @codeforester, yep. I tried to see if it can be done client-side, but I didn't seem to find anything with a timeout on the authentication part.
    – ilkkachu
    Feb 28, 2018 at 10:54
2

You are looking for LoginGraceTime in your sshd_config.

From 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .