As a freelance sysadmin, I use Mac OS X’s Terminal.app to connect to a lot of different Unix and Linux servers–I will frequently have a dozen or two (or sometimes three) terminals open to different machines. This is one of the reasons I hate rebooting–I lose all my connections & pretty much have to start over from scratch.
I recently upgraded to Mac OS X Lion, and things have been mostly positive. I really love the option to “Reopen windows when logging back in.” In terminal, that means I get all my windows back! I do still have to reconnect to all the machines, but at least I can see where I was connected, and pretty much what I was doing. I use screen extensively on the servers I connect to, so I frequently don’t even lose what I was doing.
The only problem is that when Mac OS X boots back up and starts Terminal.app at login, ssh-agent is not started before Terminal.app starts, meaning I can’t log into servers using my SSH public keys. Further, if you quit Terminal.app, and re-open it, it won’t reliably open ssh-agent (I’ve had it happen a couple times out of the many times I’ve tested). The only surefire way to get ssh-agent to start is to close all your windows and then quit & restart Terminal.app with a completely blank slate.
That is a problem as it undoes all the good that saving all my windows did. I wanted to find a way to get ssh-agent started before Terminal.app opened. I added it to my Login Items without any success, and even adding a LoginHook to /etc/ttys did not make it start before Terminal loaded.
But, there is a workaround in that if I have ssh-agent start at login, I can quit & restart Terminal.app and it always connects, so that is what I have done. The probably more correct place to do is to add it to my Login Items. To do that, I opened a Terminal window & created a symbolic link from ssh-agent to my home directory.
ln -s /usr/bin/ssh-agent .
Then I added it to my Login Items by pressing the + button and selecting it from my home dir. I can then remove the symbolic link I created, as Login Items is smart enough to link to the actual ssh-agent program.
So now after bootup and login, if I quit Terminal.app and restart it, it always connects to the ssh-agent and I can go about my passwordless logging in to all my servers.