How to use ssh -i with a key from ssh-agent rather than from a file?

raf ssh at raf.org
Thu Oct 1 10:18:08 AEST 2020


On Wed, Sep 30, 2020 at 03:28:01PM -0400, Gregory Seidman <gsslist+ssh at anthropohedron.net> wrote:

> I have sections in my .ssh/config (see below) to allow me to use several
> different github accounts. The important part is having the .pub files
> sitting there. You don't need the private key on the VM, just the public
> key, and it will pick the correct private key from your agent. Then on the
> git repo I do: git remote add origin githubu2:user/repo.git
> 
> Those sections:
> 
> Host githubu1
> Tunnel no
> ForwardAgent no
> ForwardX11 no
> HostName github.com
> user git
> IdentityFile ~/.ssh/githubu1.pub
> 
> Host githubu2
> Tunnel no
> ForwardAgent no
> ForwardX11 no
> HostName github.com
> user git
> IdentityFile ~/.ssh/githubu2.pub
> 
> Host githubu3
> Tunnel no
> ForwardAgent no
> ForwardX11 no
> HostName github.com
> user git
> IdentityFile ~/.ssh/githubu3.pub
> 
> --Gregory

Hi Gregory,

Thanks. That's great. I didn't realise that I could use
the name of the public key file with -i. The
documentation doesn't indicate that. In fact, it
explicitly states that the filename argument is for the
private key.

With this knowledge, the git config approach works just
as well:

  git config core.sshcommand 'ssh -i ~/.ssh/id_ed25519_github2.pub'

and the remote origin can stay as git at github.com and there's
no need to put repository-specific config in ssh's config.
I prefer that.

I've attached a new patch to ssh.1 that explains how to
do this.

Many thanks.

cheers,
raf

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ssh.1.patch
Type: text/x-diff
Size: 524 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20201001/a6e190eb/attachment.bin>


More information about the openssh-unix-dev mailing list