0

I have multiple ssh rsa keys on my computer that I use. That led me to having a file located at ~/.ssh/config that looks like this:

#Bit Bucket Account
Host bitbucketid
 HostName bitbucket.org
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/bitbucketid

# Server
Host serverid
 HostName website.name
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/serverid

Here is what this links says to add:

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

After following the advice from question Start ssh-agent on login, I can load the ssh key upon opening my terminal like so:

Initialising new SSH agent...
succeeded
Identity added: /Users/pc/.ssh/id_rsa (/Users/pc/.ssh/id_rsa)

How can I automatically add the identity of one of my other rsa keys such as serverid or bitbucketidupon terminal starting?

Community
  • 1
  • 1
Daniel
  • 2,650
  • 2
  • 21
  • 42

1 Answers1

0

Normally I add these keys when the shell gets started. For instance if you were using bash, I would ssh-add the keys I wanted in my .bashrc file.

binarycreations
  • 2,922
  • 5
  • 28
  • 37
  • Can you give me an example of how you would add them? I don't understand what you mean and putting `ssh-add ~/.ssh/serverid` into my .bashrc file does nothing – Daniel Jul 26 '14 at 14:26
  • Doing ssh-add should work as long as the ssh agent has started. I do this at the end of my bashrc. I'll try to find a link. – binarycreations Jul 26 '14 at 16:31
  • This is similar to what you need. http://stackoverflow.com/questions/16985927/set-ssh-identities-in-bashrc please post any errors you get. Also watch out for the gotcha where argument to ssh add is blank. – binarycreations Jul 26 '14 at 16:42