Git SSH 认证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13425811/
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
Git SSH authentication
提问by Ivan Zamylin
I have Debian, Fisheye and Git on my server. My git repos are managed by Fisheye. There is no authentication at the Fisheye part. All authentication procedures are managed by git.
我的服务器上有 Debian、Fisheye 和 Git。我的 git 存储库由 Fisheye 管理。鱼眼部分没有身份验证。所有身份验证程序都由 git 管理。
I would like to use SSH authentication, so that I do not need to provide username and password as I push my changes to the server. I know how to create an rsa key, but where do I copy my public key at the server?
我想使用 SSH 身份验证,以便在将更改推送到服务器时不需要提供用户名和密码。我知道如何创建 rsa 密钥,但是我应该在服务器上的哪里复制我的公钥?
回答by VonC
The key part of the article "Git on the Server - Setting Up the Server" is:
《服务器上的 Git - 设置服务器》一文的关键部分是:
you need to add some developer SSH public keys to the
~/.ssh/authorized_keys
file for that user.
Let's assume you've received a few keys by e-mail and saved them to temporary files. Again, the public keys look something like this:
您需要
~/.ssh/authorized_keys
为该用户的文件添加一些开发人员 SSH 公钥。
假设您通过电子邮件收到了一些密钥并将它们保存到临时文件中。同样,公钥看起来像这样:
$ cat /tmp/id_rsa.john.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4L
ojG6rs6hPB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4k
Yjh6541NYsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9Ez
Sdfd8AcCIicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myiv
O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
dAv8JggJICUvax2T9va5 gsg-keypair
(Note: make sure the key is displayed on onesingle line)
(注:确保关键是显示在一个单行)
You just append them to your authorized_keys file:
您只需将它们附加到您的 authorized_keys 文件中:
$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
If you don't have an authorized_keys
file on your server, create it, but make sure to protect it correctly.
如果您authorized_keys
的服务器上没有文件,请创建它,但请确保正确保护它。
server$ mkdir ~/.ssh
server$ chmod 700 ~/.ssh
server$ cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
server$ chmod 600 ~/.ssh/authorized_keys
server$ rm ~/id_rsa.pub
See "Creating SSH keys for Gerrit and Hudson" for a concrete example.
有关具体示例,请参阅“为 Gerrit 和 Hudson 创建 SSH 密钥”。
- Make sure git is in the PATH used by your ssh daemon.
- Make sure all parent directories of your
~/.ssh
are not writable for the group (chmod 755
only).
- 确保 git 在您的 ssh 守护程序使用的 PATH 中。
- 确保您的所有父目录
~/.ssh
都不可写入组(chmod 755
仅限)。
回答by ErJab
You need to paste your public key inside ~/.ssh/authorized_keys
. Create the file if it doesn't exist.
您需要将您的公钥粘贴到~/.ssh/authorized_keys
. 如果文件不存在,则创建该文件。