I'm trying to cut down the time ssh is trying to open a connection to a host. If I put for example ssh www.google.com
it takes very long until the prompt comes back.
I read about using ssh -o ConnectTimeout=10 www.google.com
instead, but even this takes very long. Is there maybe a number of attemps I can modify to decrease the blocking time?
Use the ssh_timeout command to set the number of minutes that the SSH session can be idle before it is closed. The default timeout interval is 0 minutes. Use this value, if you do not want the SSH session to expire. The minimum timeout interval is 2 minutes.
Some systems use a default as low as five seconds, and some go as high as two hours; the average is typically around three to five minutes. Your SSH connection, if it has not been modified to change the timeout on either the server or client end, will use this timeout.
The problem may be that ssh is trying to connect to all the different IPs that www.google.com
resolves to. For example on my machine:
# ssh -v -o ConnectTimeout=1 -o ConnectionAttempts=1 www.google.com OpenSSH_5.9p1, OpenSSL 0.9.8t 18 Jan 2012 debug1: Connecting to www.google.com [173.194.43.20] port 22. debug1: connect to address 173.194.43.20 port 22: Connection timed out debug1: Connecting to www.google.com [173.194.43.19] port 22. debug1: connect to address 173.194.43.19 port 22: Connection timed out debug1: Connecting to www.google.com [173.194.43.18] port 22. debug1: connect to address 173.194.43.18 port 22: Connection timed out debug1: Connecting to www.google.com [173.194.43.17] port 22. debug1: connect to address 173.194.43.17 port 22: Connection timed out debug1: Connecting to www.google.com [173.194.43.16] port 22. debug1: connect to address 173.194.43.16 port 22: Connection timed out ssh: connect to host www.google.com port 22: Connection timed out
If I run it with a specific IP, it returns much faster.
EDIT: I've timed it (with time
) and the results are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With