2017-01-01 73 views
2

我已經設置了Github無密碼登錄,如下所示。使用非默認密鑰名稱(除id_rsa之外)

ssh-keygen -t rsa -P '' 
cat .ssh/id_rsa.pub |xclip 

我粘貼公鑰到ssh和GPG密鑰在Github上的網站。

git init 
git config --global user.name "someone" 
git config --global user.email "[email protected]" 
git config remote.origin.url git+ssh://[email protected]/someone/newstart.git 
ssh -T [email protected] 
git clone git+ssh://[email protected]/someone/newstart.git /tmp/newstart 

上述工作。

現在我想爲Github使用不同的密鑰名稱,而不是默認名稱id_rsa

sh-keygen -t rsa -P '' -f .ssh/id_rsa.github 
cat .ssh/id_rsa.github.pub |xclip 

我粘貼了新的酒吧鑰匙插入ssh和GPG密鑰在Github上的網站。

git init 
git config --global user.name "someone" 
git config --global user.email "[email protected]" 
git config remote.origin.url git+ssh://[email protected]/someone/newstart.git 
ssh -T [email protected] 

上述不起作用。

git clone git+ssh://[email protected]/someone/newstart.git /tmp/newstart 

以上也不起作用。

ssh -i .ssh/id_rsa.github -T [email protected] 

上述命令可以成功連接到Github,但我無法鍵入以下命令來克隆存儲庫。

git clone -i .ssh/id_rsa.github git+ssh://[email protected]/someone/newstart.git /tmp/newstart 

難道我不能與另一名酒館關鍵,如id_rsa.github而不是默認的名稱id_rsa

回答

4

您需要告訴SSH將此密鑰用於Github。把這個~/.ssh/config

Host github.com 
    IdentityFile ~/.ssh/id_rsa.github 
    User git