9

Is there an SSH option (similar to -o ConnectTimeout=$seconds) that limits the time that it spends waiting at a password: prompt?

Note, I do use keypairs for passwordless ssh, but I still wind up seeing a password: prompt several times a week, because I have bash functions running in a background window that reconnect my SSH tunnels whenever they drop (as I wander between WiFi networks and close the MacBook lid randomly). So sometimes SSH negotiation can get into the "password:" state, then it stays there until I manually intervene with ^C or killall ssh...

dtunnel-home () {
  while true ; do
    title "XXX-TTT-..."
    wait-for-host.sh "$g"   ## sleep until ping-able.
    time (
        set -x
         ssh -o ConnectTimeout=10        \
             -Y -L 5920:$t:5900  -L ...  \
             $g_user@$g
    ) ; date "+%Y-%m-%d_%H-%M-%S"
  done
}

2 Answers 2

2

I recently ran into a similar problem (a cygwin ssh shell running in the background that should reconnect automatically, where sometimes a password prompt appears).

I did find a solution in the ssh_config man page:

BatchMode=yes

or as a parameter for the ssh shell:

-o BatchMode=yes

according to the man page it disables the password prompt client side:

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

6

For linux you maybe have the option to workaround with the timeout command, provided with "coreutils" from any regular RPMs .

If it's timeout then return code 124

cinacio@jdivm04:~> time timeout 10s ssh cinacio@vulca_5 ; echo $?
cinacio@vulca_5's password:

real    0m10.002s
user    0m0.006s
sys     0m0.002s

124

I discovery this at this question : https://stackoverflow.com/questions/15785832/how-to-make-ssh-command-execution-to-timeout

3
  • 1
    Hmmm, that will timeout the entire SSH session, so in my case that will kill the tunnel after the 10s timeout even if it did sucessfully connect and login normally with pubkeys. Also I'd really prefer something portable (no timeout on MacOSX).
    – DouglasDD
    Apr 1, 2014 at 15:53
  • 1
    ...but further down in the same StackOverflow answer I found PasswordAuthentication=no which completely prevents the password: prompt that was plaguing me!
    – DouglasDD
    Apr 5, 2014 at 5:58
  • @DouglasDD I understand that you're showing appreciation, but you really shouldn't have this as the accepted answer; the limitation you've described in your comment makes it useless, even though you have (separately) found a workaround for your particular workflow. Mar 8, 2017 at 22:09

You must log in to answer this question.

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