2015-06-22 37 views
1

每當我嘗試做一個「git的拉起源大師」我得到(它不是Github上):配置Git的使用。質子交換膜鍵從一個特定的位置

權限被拒絕(公鑰)。

我能夠通過SSH連接到我的AWS EC2 Linux服務器,該服務器具有裸存儲庫,當我收到上述權限錯誤時,我正試圖從該存儲庫中提取該服務器。

我確實複製公鑰到該服務器,因爲我可以通過ssh登錄成功,但只有通過做:

ssh -i /location/of/pemkey/mykey.pem [email protected]

我需要的Git配置爲使用我的「質子交換膜」鍵。 如何完成設置Git以利用我的'.pem'鍵?

+0

好的,你爲什麼要配置git來使用.pem鍵?如果您已成功生成ssh密鑰,只需將公鑰複製到服務器即可。 – ckruczek

回答

1

git(1)手冊頁:

GIT_SSH 
     If this environment variable is set then git fetch and git push 
     will use this command instead of ssh when they need to connect to a 
     remote system. The $GIT_SSH command will be given exactly two or 
     four arguments: the [email protected] (or just host) from the URL and 
     the shell command to execute on that remote system, optionally 
     preceded by -p (literally) and the port from the URL when it 
     specifies something other than the default SSH port. 

     To pass options to the program that you want to list in GIT_SSH you 
     will need to wrap the program and options into a shell script, then 
     set GIT_SSH to refer to the shell script. 

     Usually it is easier to configure any desired options through your 
     personal .ssh/config file. Please consult your ssh documentation 
     for further details. 

在我個人的經驗,在加入.ssh/config主機設置的一次性成本方面取得了很大的不同,即使是主機,其中只有用戶名是不同的。

+0

好,那是我的想法,但我的.ssh/config文件在哪裏? – ConfusedDeer

+1

@ConfusedDeer'〜/ .ssh/config' – poke

+0

你讓我走上了正確的軌道,我會將你的答案標記爲答案,但我會添加自己的答案來澄清,因爲還有一些其他步驟需要要做。我終於把它拉了。謝謝! – ConfusedDeer

1

我從here得到這個,但它不是主要答案。 這裏列出的說明對我更有用。

調整你的〜/ .ssh/config並添加:

Host example 
Hostname example.com 
User myuser 
IdentityFile ~/.ssh/other_id_rsa 

現在使用ssh主機別名爲你的資料庫:

$ git remote add origin example:repository.git 

$ git pull origin master 

而且它應該使用other_id_rsa關鍵!