Setting up ssh-agent on OS X

It is very important to make the environment variable SSH_AUTH_SOCK available all the time in order to set up successfully ssh-agent on your OS X. The way to save the SSH_AUTH_SOCK variable is simple. Just create the following directory and file on your $HOME.

cd $HOME
mkdir .MacOSX
cd .MacOSX

And then create a file environment.plist in it

[15:02] halfrunt:~/.MacOSX % cat environment.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>SSH_AUTH_SOCK</key>
        <string>/tmp/dikim_ssh-agent.socket</string>
</dict>
</plist>

After that, follow up with the normal ssh-agent configuration on linux.

  1. if SSH_AUTH_SOCK is not defined, setup the value with my specific null file(e.g., /tmp/dikim_ssh-agent.socket)
  2. Otherewise, just use the value of SSH_AUTH_SOCK
  3. check to see if ssh-agent process is running
  4. if not, start it like this
    ssh-agent -a /tmp/dikim_ssh-agent.socket
  5. And then add your ssh private key to your running ssh-agent (e.g., ssh-add ${HOME}/.ssh/id_dsa mostly)

I wrote a simple shell script to run all the boring processes and then put the script to my customized shell configuration(e.g., .tcshrc, .cshrc, or .bashrc) to make my ssh-agent configuration always work whenever I login.
Here is my shell script to configure my ssh_agent.

#!/bin/sh
#
# Check that the ssh-agent is running, and if not, kick it off
#

# default TTL = 8 hours
TTL=28800

if [[ -z $SSH_AUTH_SOCK ]]; then
   SOCKETFILE=/tmp/dikim_ssh-agent.socket
else
   SOCKETFILE=${SSH_AUTH_SOCK}
fi

/bin/ps -wU ${USER} | grep "[s]sh-agent" > /dev/null
if [[ $? -gt 0 ]]; then
   rm -f ${SOCKETFILE}
   ssh-agent -a ${SOCKETFILE}
   chmod 600 ${SOCKETFILE}
   ssh-add ${HOME}/.ssh/id_dsa
fi
blog/apple/setting_up_ssh-agent_on_os_x.txt · Last modified: 2007/11/02 09:58 by donginn
Back to top
Open Systems Lab
Indiana University Computer Science Department
Lindley Hall 215
150 S. Woodlawn Ave.
Bloomington, IN 47405-7104

chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0