2016-01-21 135 views
1

當我從用戶提示使用ssh git克隆它正常工作。使git克隆與sudo

git clone ssh://URL.com/soft.git soft_git 

SSH密鑰id_rsaid_rsa.pub正在/home/user/.ssh

我的目的是執行混帳與sudo,但我得到了以下錯誤

Cloning into '/home/user/git/soft'... 
Permission denied (publickey,keyboard-interactive). 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

我創建一個文件夾/root/.ssh,我複製SSH密鑰到它,但我得到了相同的錯誤

如何exe與sudo可愛的混帳。

回答

0

通常,默認的遠程SSH用戶與您的用戶名相同。如果您使用的是sudo,這將是root,這可能不會起作用。您需要提供遠程用戶名。

sudo git clone ssh://[email protected]/soft.git soft_git 

通常你可以解決的git SSH問題更容易嘗試登錄與普通的ssh遠程。你會得到更好的診斷,並可以看到出了什麼問題。

sudo ssh ssh://URL.com/ 
4

當你使用sudo運行git時,git將以root身份運行。因爲git以root用戶身份運行,所以ssh以root身份運行。由於ssh以root用戶身份運行,因此它試圖以root身份登錄到遠程服務器。遠程服務器是不是這件事,好嗎

你需要做兩件事情(因爲它應該是!):

  • 把你的URL的用戶名:SSH://[email protected] /soft.git。

  • 使您的SSH密鑰可供root用戶使用,因爲它將在/root/.ssh而不是/home/user/.ssh之下。 (你也可以將SSH指向正確的密鑰,但我不知道如何做到這一點,並且SSH對權限很挑剔。)