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

Gregory Seidman gsslist+ssh at anthropohedron.net
Thu Oct 1 05:28:01 AEST 2020


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

On Wed, Sep 30, 2020 at 02:38:23PM +1000, raf wrote:
> Hi,
> 
> I have a VM with a git repository whose origin is on
> github. I have several keys known to github, so I needed
> to set git's core.sshcommand config parameter in the
> repository to something like this:
> 
>   ssh -i ~/.ssh/id_ed25519_github2
> 
> But it meant that I needed to copy that key to the VM.
> The same key is available via my forwarded ssh-agent
> connection. Is it possible to tell ssh to use that
> instead of the key in a file? The documentation for the
> -i option only mentions files.
> 
> cheers,
> raf
> 
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev at mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
> 


More information about the openssh-unix-dev mailing list