Thanks to a hard drive failure, I recently installed a fresh copy of Mac OS X 10.5 (Leopard) on my MacBook. I do a lot of work on remote systems and SSH is my bread and butter. Whenever I tried to SSH into other Macs on my local network, SSH would start up but take a minute or two to connect. This problem did not occur when connecting to hosts not on the local network.
When I fired up SSH with the verbosity cranked up, here is what I saw:
$ slogin -vvv Skadi.local
OpenSSH_5.1p1, OpenSSL 0.9.7l 28 Sep 2006
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to Skadi.local [fe80::214:51ff:fe28:e74e%en1] port 22.
As you can see, my laptop is trying to connect to the remote server using IPv6. The other side of the connection is listening for SSH connections via IPv6, but something is causing the connection to timeout and failover to IPv4.
$ netstat -an | grep 22
tcp4 0 0 *.22 *.* LISTEN
tcp6 0 0 *.22 *.* LISTEN
I checked the firewall settings on the remote hosts and there is nothing blocking the incoming connection. Additionally, the other Macs on my local network are connecting via IPv6.
In the end, I removed the problem by disabling IPv6 on the laptop. This is by no means a perfect solution and doesn’t explain the problem at all. I’m curious if the remote hosts have some sort of cached information about the host I’ve reinstalled. I can’t find any evidence of that, but I can’t rule that out. If you have an idea I haven’t thought of, please leave a comment below and let me know.

Get Slaptijack updates delivered to your Inbox or RSS Reader for free!
Disabling IPv6 globally is a bit excessive.
You could force ssh to use IPv4 by using the -4 flag (-6 forces IPv6).
If you do this a lot you could add the AddressFamily option to your local ssh_config. It supports the values: any, inet, inet. So you just add this to ~/.ssh/config (this will impact the behavior of scp & sftp as well):
AddressFamily=inet
For more ssh_config goodness look at the man page: man ssh_config
Mark, you’re absolutely right. Disabling IPv6 is over the top. More testing has shown that this problem is affecting other inter-Mac services too (file sharing, etc.). One thing I hadn’t previously considered is that this problem may be related to my wireless router rather than the laptop.
Thanks for the SSH config tips.