我無法推送到我的Amazon EC2實例上存儲的遠程git倉庫。SSH可以進入服務器,但不是git push
我的本地ssh
config
文件中有一個主機條目,看起來像這樣:
Host ec2
HostName ec2-54-89-205-210.compute-1.amazonaws.com
User ec2-user
IdentityFile ~/.ssh/ec2TestB
而且這樣我就可以運行該命令ssh ec2
,我會成功連接到ec2
。
接下來,我在名爲testGitRoot
的root
文件夾中的ec2
上創建了git repo
。在我的本地機器上,我創建了一個git repo
,名爲testGitLocal
。然後我添加ec2
repo
與git remote add origin [email protected]:/root/testGitRoot
(我也試過沒有[email protected]
部分..不知道是否需要)。
位當我運行git push origin master
我得到:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
所以我的問題是什麼概念,我錯過了?如果我能通過ssh與ssh ec2
進行連接,那麼爲什麼我不能推回我的回購?有一件事情我不清楚的是,我甚至使用了ssh
來完成git設置步驟。通常情況下,我總是推送到github,在這種情況下,我採取ssh
網址並將其設置爲我的遠程。在這種情況下,我只是將我的ec2
repo
設置爲遠程,其URL只是ec2Domain:path/to/git/repo
。所以即使git push origin master
使用ssh
,如果是的話,爲什麼它似乎是在ssh ec2
命令不失敗時公鑰失效?
我使用的(我認爲)CentOS的AMI,所以我敢肯定的是,用戶是'ec2user'。我不確定在'git remote add origin'中是否需要'user @'語法。基本上是''?或' @'?我也不知道哪個密鑰對是正確的。我已經安裝了兩個git代表,並簡單地將遠程作爲源名添加到域名中。正如我在我的問題中所說,我甚至不確定如果它使用ssh。 –
'git remote add origin $ URL'。如果你使用ssh類型的URL,git將使用ssh。請參閱[git URL](https://git-scm.com/docs/git-fetch#_git_urls_a_id_urls_a)。 – phd