簡體   English   中英

使用SSH並指定憑據時,Git push使用公鑰失敗

[英]Git push fails with public key when using SSH and specifying credentials

我這里有一個奇怪的問題。 我們的Maven發布插件失敗,因為它無法將標簽推送到Git。 以下失敗:

git push ssh://PU0S:xL8q@git-eim.fg.com/u0r0-SS/workspace-proxy.git workspace-proxy-server-1.10.1
[ERROR] Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR] 
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.

如果我遠程進入機器並嘗試使用表單的URL推送,我會得到相同的錯誤:

git push ssh://PU0S:xL8q@git-eim.fg.com/u0r0-SS/workspace-proxy.git

如果我只是推動使用已定義的遙控器,它會成功:

git push origin master

上面的內容讓我確定機器上有.ssh鍵。 為什么第一種形式失敗?

知道為什么以下命令失敗git clone ssh://git-eim.fg.com/u0r0-SS/workspace-proxy.git但是以下成功ssh://git@git-eim.fg.com/u0r0-SS/workspace-proxy.git
git@什么特別之處?

git@表示將接收推送的用戶將是git。 然后,通過用於ssh的公鑰來管理身份驗證。
這與PU0S:xL8q不同,后者是用戶名/密碼,僅在使用https網址時才需要。
對於ssh url,你永遠不會像你一樣推送(PU0S),而是在服務器端管理git repos的帳戶。
這就是為什么,例如,你總是推動git@github.com

如果git push origin master成功,則表示正確形成了與名為' origin '的遠程關聯的url。
通常是ssh://git@git-eim.fg.com/u0r0-SS/workspace-proxy.git

git remote -v檢查,或者從git 2.7開始 ,使用git remote get-url origin

git在你的.ssh文件夾下的某個位置查找ssh。

在配置文件中設置密鑰,您應該能夠克隆它。

打開終端窗口。 編輯~/.ssh/config文件。
如果您沒有配置文件,請創建一個。 為每個標識組合添加別名,例如:

Host workid
HostName github.com 
IdentityFile ~/.ssh/workid

以下線索有助於診斷問題。

首先,讓我們嘗試ssh -vT而不指定用戶。 請注意,會話假定用戶是登錄的帳戶,該帳戶具有特殊字符('SE121947 + PVHF0ONE_SS')!

 $ ssh -vT git-eim.fg.com
OpenSSH_7.1p2, OpenSSL 1.0.2g  1 Mar 2016
....
debug1: Authenticating to git-eim.fg.com:22 as'SE121947+PVHF0ONE_SS'
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/PVHF0ONE_SS/.ssh/id_rsa
debug1: No more authentication methods to try.

Permission denied (publickey).

現在讓我們通過指定git@git-eim.fg.com來嘗試它

$ ssh -vT git@git-eim.fg.com
OpenSSH_7.1p2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to git-eim.fg.com [10.238.35.34] port 22.
debug1: Connection established.
debug1: identity file /c/Users/PVHF0ONE_SS/.ssh/id_rsa type 1
...
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
Authenticated to git-eim.fg.com ([10.238.35.34]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi PU0R0SRVDEVOPS! You've successfully authenticated, but GitHub does not provide shell access.

奇怪的是git@可以被foo@取代而且驗證工作正常! 這幾乎就像它只是一個占位符。 因此,修復程序確保pom.xml中的developerConnection具有git@ ,以便git能夠進行身份驗證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM