You are not logged in.

#1 2013-10-08 03:35:27

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Simple ssh-agent config

I've been looking for a simple and robust way of getting ssh keys to work with an agent. It seemed like the existing methods detailed on the wiki were all some combination of not simple and not robust. After RTFMing I came up with a method that works for me. Maybe it's kind of trivial but I haven't seen it described anywhere else and I suspect others might find it useful to have the approach spelled out. I've added my notes to the wiki here and here.

The current post is basically just an FYI but if you see any glaring problems/shortfalls with the new subsections you should feel invited to volunteer your feedback smile

Offline

#2 2013-10-08 03:41:47

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Simple ssh-agent config

I use keychain in my zprofile.  It runs but doesn't immediately unlock my ssh key or my gpg key.  Gpg is able to automatically unlock on first access, as this functionality is built into the gpg-agent.  But the ssh-agent will want to unlock right away.  So instead I use a simple alias that checks for the existence of an unlocked key.  If it exists it just runs ssh, if not, it adds the key first:\

alias ssh='ssh-add -l &>/dev/null || ssh-add ~/.ssh/id_rsa && ssh'

BTW, keychain (as you may have deduced from the above) is just a wrapper around gpg-agent and ssh-agent.  It is available in the offical repos.

Offline

#3 2013-10-08 03:54:33

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Simple ssh-agent config

WonderWoofy wrote:

BTW, keychain (as you may have deduced from the above) is just a wrapper around gpg-agent and ssh-agent.  It is available in the offical repos.

Thanks for your reply. I've tried using gpg-agent and keychain in the past. It wasn't recent but I seem to recall a lot of frustrations. Also, they strike me as less simple than the method I've currently settled on. Keychain seems to basically be addressing the concern about multiple ssh-agents running around after multiple logins, but this concern doesn't arise in the first place with my "new" (old?) technique; and maybe I'm being obstinate but in my mind gpg is conceptually different to ssh and I'd rather maintain separation of concerns by having ssh-agent rather gpg-agent handle my ssh keys.

Offline

#4 2013-10-08 04:09:38

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Simple ssh-agent config

You still have two agents, one for gpg and one for ssh.  But keychain just starts them and then allows you to use just once instance of each whenever you upon a subsequent shell.  It can be told to do just one or the other very easily. 

From the keychain man page:

This snippet should work in any shell to load two ssh keys and one gpg key:
           eval `keychain --eval id_rsa id_dsa 0123ABCD`

I use the somewhat more "complex" form without using eval:

my ~/.zprofile wrote:

/usr/bin/keychain --agents ssh,gpg -Q -q --nogui
[ -z "$HOSTNAME" ] && HOSTNAME=$(uname -n)
[ -f $HOME/.keychain/${HOSTNAME}-sh ] && source $HOME/.keychain/${HOSTNAME}-sh
[ -f $HOME/.keychain/${HOSTNAME}-sh-gpg ] && source $HOME/.keychain/${HOSTNAME}-sh-gpg

Not sure how this would lead to frusturations…

Offline

#5 2013-10-08 04:17:23

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: Simple ssh-agent config

WonderWoofy wrote:

You still have two agents, one for gpg and one for ssh.  But keychain just starts them and then allows you to use just once instance of each whenever you upon a subsequent shell.  It can be told to do just one or the other very easily.

If anyone is perfectly happy with keychain and friends then I'm not proposing they change to suit me. I am only offering an alternative for those who aren't hip to that groove.


WonderWoofy wrote:

Not sure how this would lead to frusturations…

Nevertheless that is what happened.

Offline

Board footer

Powered by FluxBB