通过 ssh (gitosis) 访问 git repo 时如何包含 ssh 私有 rsa 密钥?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6749361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:42:19  来源:igfitidea点击:

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

gitsshgitosisgitolitegit-extensions

提问by tijagi

At this moment I've got one git repo added through gitosis. The manual i used is http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

此时我已经通过 gitosis 添加了一个 git repo。我使用的手册是http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

  1. I can clone it and push in it via ssh auth with private and public keys (on gentoo), but windows users which are using Git Extensions can not. SSH keys placed in $HOME/.ssh, and ssh asks for a password. Nor password, nor passphrase (from private ssh key) don't match.

  2. Redmine needs for a bare repo, so i cloned repo from gitosis on my local machine and moved it to server (redmine + git), then tried to sync like showed here http://www.redmine.org/projects/redmine/wiki/HowTo_keep_in_sync_your_git_repository_for_redmineBut 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)

  1. 我可以克隆它并通过 ssh auth 使用私钥和公钥(在 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但它再次要求输入密码!当然,我没有让 apache 成为他自己的 ssh 密钥来认证 gitosis =_= (Apache 是 redmine 裸仓库的所有者,导致它通过 http auth 访问它)

Anyway the question is how to use private ssh key from file when accessing to gitosis?

无论如何,问题是如何在访问 gitosis 时使用文件中的私有 ssh 密钥?

===

===

Partially solved! ssh-keygen -t rsagenerates keys, which names are exactly id_rsaand id_rsa.pub. if you run ssh -vvv [email protected]you should see something similar to

部分解决! ssh-keygen -t rsa生成密钥,其名称正是id_rsaid_rsa.pub。如果你运行ssh -vvv [email protected]你应该看到类似的东西

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

So, ssh client wants exactly named files or will switch to next auth method (password). Now i renamed keys on my home machine and:

因此,ssh 客户端需要完全命名的文件或将切换到下一个身份验证方法(密码)。现在我重命名了我家用机器上的密钥,并且:

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

Hurray, it asks for a passphrase! BTW, ШIИDOШS? users are still having problems with their tens of generated keys.

万岁,它要求输入密码!顺便说一句,ШIИDOШS?用户仍然对他们的数十个生成的密钥有问题。

Upd

更新

If you use OpenSSH, then in ~/.ssh you may create a file named ‘config' and put there something like this:

如果您使用 OpenSSH,那么在 ~/.ssh 中,您可以创建一个名为“config”的文件,并在其中放置如下内容:

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

采纳答案by VonC

Windows users should be able to clone as well (with ssh), if they have defined the %HOME% environment variable.
HOME isn't defined by default.
It can reference any directory they want (usually, one takes the same than %HOMEPATH%)

如果 Windows 用户定义了 %HOME% 环境变量他们也应该能够克隆(使用 ssh)。
默认情况下未定义 HOME。
它可以引用他们想要的任何目录(通常,一个与 相同%HOMEPATH%



The OP user685107reports:

OP user685107报告:

Problem with windows users was solved by strictly following the manual of key generation with puttygen.
new key pair maked in windows works fine

严格按照puttygen生成密钥的手册解决了windows用户的问题。
在 Windows 中制作的新密钥对工作正常

回答by Jinna Balu

Setup git push with SSH

使用 SSH 设置 git push

Generate SSH KEY with ssh-keygen

使用 ssh-keygen 生成 SSH KEY

ssh-keygen -t rsa -C "[email protected]"

Github SSH connection setup

Github SSH 连接设置

1. Copy the ssh from local machine

1.从本地复制ssh

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

2. Go to github account settingspage

2.进入github账号设置页面

3. Click on New SSH Key

3. 单击新建 SSH 密钥

4. Add title and paste the copied ssh key from the local

4.添加标题并粘贴从本地复制的ssh密钥

5. Test SSH

5. 测试 SSH

ssh -T [email protected]

6. Update the Remote URL of the repository with the ssh url in place of https

6. 使用 ssh url 代替 https 更新存储库的远程 URL

  • Copy the ssh url from the repository

  • Copy clone with ssh URL - Clock Use SSHas in first screenshot

    git remote set-url origin [email protected]:JinnaBalu/GitCheatSheet.git

  • 从存储库中复制 ssh url

  • 使用 ssh URL 复制克隆 - 时钟如第一个屏幕截图所示使用 SSH

    git remote set-url origin [email protected]:JinnaBalu/GitCheatSheet.git

7. Test pushing with ssh

7. ssh 测试推送

 git add --all

 git commit -am "testing the changes"

 git push -u origin master