簡體   English   中英

通過 ssh(gitosis)訪問 git 存儲庫時,如何包含 ssh 私有 rsa 密鑰?

[英]How to include ssh private rsa key when accessing git repo via ssh (gitosis)?

目前我已經通過 gitosis 添加了一個 git 存儲庫。 我使用的手冊是http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

  1. 我可以克隆它並通過 ssh 身份驗證將其推入(在 gentoo 上),但使用 Git 擴展的 windows 用戶不能。 SSH 密鑰放在 $HOME/.ssh 中,ssh 要求輸入密碼。 密碼和密碼(來自私有 ssh 密鑰)也不匹配。

  2. Redmine 需要一個裸倉庫,所以我在本地機器上從 gitosis 克隆倉庫並將其移動到服務器(redmine + git),然后嘗試像這里顯示的那樣同步http://www.redmine.org/projects/redmine/wiki /HowTo_keep_in_sync_your_git_repository_for_redmine But it asks for a password again, Of course I didn't make apache his own ssh keys to auth gitosis =_= (Apache is owner of redmine bare repo, cause it access it through http auth)

無論如何,問題是如何在訪問 gitosis 時使用文件中的私有 ssh 密鑰?

===

部分解決! ssh-keygen -t rsa生成密鑰,其名稱正是id_rsaid_rsa.pub 如果你運行ssh -vvv gitosis@your-server.com你應該看到類似於

debug1: Authentications that can continue: publickey,keyboard-interactive
…
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: user@domain-user
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /home/user/.ssh/id_rsa
debug3: no such identity: /home/user/.ssh/id_rsa
debug1: Trying private key: /home/user/.ssh/id_dsa
debug3: no such identity: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug3: no such identity: /home/user/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive

因此,ssh 客戶端想要准確命名的文件,否則將切換到下一個身份驗證方法(密碼)。 現在我重命名了家用機器上的鍵,並且:

user@home ~ $ git clone ssh://git@your-gitosis-server/reponame.git
Cloning into reponame...
Enter passphrase for key '/home/user/.ssh/id_rsa':

萬歲,它要求輸入密碼,順便說一句。 ШIИDOШS™ 用戶仍然在使用他們生成的數十個密鑰時遇到問題。

更新

如果您使用 OpenSSH,那么在 ~/.ssh 中,您可以創建一個名為 'config' 的文件並在其中放置如下內容:

Host mygitosisserver.com
IdentityFile ~/.ssh/private-key-for-mygitosisserver-com

如果 Windows 用戶定義了 %HOME% 環境變量,他們也應該能夠克隆(使用 ssh)。
默認情況下未定義 HOME。
它可以引用他們想要的任何目錄(通常,一個與%HOMEPATH%相同)


OP user685107報告:

windows 用戶的問題已通過嚴格遵循使用 puttygen 生成密鑰的手冊得到解決。
windows 制作的新密鑰對工作正常

設置 git 推與 SSH

使用 ssh-keygen 生成 SSH KEY

ssh-keygen -t rsa -C "your_github_email@example.com"

Github SSH 連接設置

1.從本地機器復制ssh

cat /home/ubuntu/.ssh/github_rsa.pub

2. Go轉github賬號設置頁面

3. 點擊新的 SSH 密鑰

4.添加標題並從本地粘貼復制的ssh密鑰

5.測試SSH

ssh -T git@github.com

6. 用 ssh url 代替 Z5E7656C50BADEZ014C 更新存儲庫的遠程 URL

  • 從存儲庫中復制 ssh url

  • 使用 ssh URL 復制克隆 - 時鍾使用 SSH如第一個屏幕截圖所示

    git 遠程設置 URL 來源 git@github.com:JinnaBalu/GitCheatSheet.git

7.用ssh試推

 git add --all

 git commit -am "testing the changes"

 git push -u origin master

暫無
暫無

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

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