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

Damien Miller djm at mindrot.org
Wed Sep 30 15:35:43 AEST 2020


On Wed, 30 Sep 2020, 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.

ssh will read the public key (id_ed25519_github2.pub) to identify the key
before it tries to use the private key (id_ed25519_github2). If the private
key is available in the agent then it will never try to use the private key
file.

Summary: copy id_ed25519_github2.pub to your VM and the above command will
work.

-d


More information about the openssh-unix-dev mailing list