Git - Specify private SSH-key to use when executing shell command with or without Ruby

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git) command from the local computer.

Basically like this: git clone git@github.com:TheUser/TheProject.git -key "/home/christoffer/ssh_keys/theuser"

Or even better (in Ruby):

with_key("/home/christoffer/ssh_keys/theuser") do
  sh("git clone git@github.com:TheUser/TheProject.git")
end

I have seen examples of connecting to a remote server with Net::SSH that uses a specified private key, but this is a local command. Is it possible?

Answers

Something like this should work (suggested by orip):

ssh-agent bash -c  ssh-add /somewhere/yourkey; git clone git@github.com:user/project.git 

if you prefer subshells, you could try the following (though it is more fragile):

ssh-agent $(ssh-add /somewhere/yourkey; git clone git@github.com:user/project.git)

Git will invoke SSH which will find its agent by environment variable; this will, in turn, have the key loaded.

http://linux.die.net/man/5/ssh_config http://linux.die.net/man/5/ssh_config

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils