Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

git - How to use specified key when working with github via portablegit?

I have two ssh keys to work with github - my own and one from organisation where I'm working. My key was generated automatically by github gui client and the other one was generated by portablegit. My .ssh folder looks like:

github_rsa            <--- my key
github_rsa.pub
id_rsa                <--- org key
id_rsa.pub

When I use portablegit it takes the key with name 'id_rsa' but sometimes I need to use my key too. How can I setup default key?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can by adding to your HOME/.ssh a config file:

Host wpengine 
user git
hostname git.wpengine.com
IdentityFile ~/.ssh/myPrivateKey

You can add as many 'Host' entry as you want, each one with a different IdentityFile

See for instance "Multiple SSH Keys settings for different github account"

#activehacker account
Host github.com-activehacker
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_activehacker

#jexchan account
Host github.com-jexchan
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_jexchan

You can then use the scp syntax for cloning your repo:

git clone github.com-activehacker:activehacker/gfs.git gfs_jexchan

(instead of ssh://git@github.com/activehacker/gfs.git, which wouldn't be able to reference a specific private key and would always fall back to id_rsa.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...