簡體   English   中英

無法使用ssh推送到gitlab分支

[英]cannot push to branch on gitlab with ssh

我是gitlab的新手,這是我第一次使用ssh。 我可以生成ssh密鑰並將其添加到我的帳戶設置中。 我可以通過ssh克隆倉庫,我可以結帳到分支,但是我仍然不能做的就是將更改推送到分支。 這是逐步生成ssh密鑰的步驟,直到我嘗試按它為止(按照此處的說明進行操作):

PS。 我正在使用Windows 10。

  • 在終端上(以管理員身份),鍵入: ssh-keygen -o -t rsa -b 4096 -C "myemail@example.com"
  • Enter以獲取ssh鍵的默認路徑
  • 提供密碼
  • ~/.ssh/創建配置文件。 這是我在配置文件中寫的:

Host ahostname Hostname myhostname.com User mygitlabusername Port port PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa

  • 使用以下命令復制ssh密鑰: cat ~/.ssh/id_rsa.pub | clip cat ~/.ssh/id_rsa.pub | clip
  • 將ssh密鑰放入我的帳戶設置
  • 然后,運行ssh -T git@myhostname.com ,結果如下:

The authenticity of host '[myhostname.com]:port ([123.456.789]:port)' can't be established. ECDSA key fingerprint is SHA256:xxxx. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[myhostname.com]:port ([ipofmyshost]:port)' (ECDSA) to the list of known hosts. Enter passphrase for key 'C:~/.ssh/id_rsa': Welcome to GitLab, <myusername>!

  • 然后我嘗試克隆一個git clone ssh://git@myhostname.com/repo.gitgit clone ssh://git@myhostname.com/repo.git
  • 但是,顯然,在克隆時,它指的是另一個IP地址。 例如,讓我們說ipofmyhost上的ssh -T git@myhostname.com123.456.789 然后,當我克隆時,IP更改為123.456.781 (對不起,我怕我不能提到真實IP)。 因此,這是嘗試克隆存儲庫時得到的信息:

Warning: Permanently added the ECDSA host key for IP address '[123.456.781]:port' to the list of known hosts. Enter passphrase for key '/c/.ssh/id_rsa':

  • 但是,克隆完成,然后我使用git checkout mybranchname簽出到我的分支
  • 現在,我在分支機構中。 做出一點改變。 嘗試push ,但這是我得到的錯誤:

git@myhostname.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

我在這里錯過了什么? 我找到了這個問題,但是對不起,我不明白所接受的答案建議我做些什么來解決這個問題。

更新

我嘗試再次重新克隆,但是在此之前,我刪除了所有known_host 然后,再次進行git clone ,而不用ssh -T git@myhostname.com進行測試,以避免創建新的IP地址。 但是,即使在沒有將新IP地址添加到known_host情況下推送分支時,我仍然遇到相同的錯誤。

再試一次,進行測試,有沒有密碼創建SSH密鑰。

或者,首先,請確保已使用ssh-add密鑰添加到ssh-agent中
請參閱“ 使用非默認SSH密鑰對路徑

您可以“ 在Windows的Git上自動啟動ssh-agent ”(GitHub指令,但也對GitLab有效)

暫無
暫無

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

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