git 到 CentOS 7 的 SSH 连接 Windows
SSH connection Windows to CentOS 7 for git
我有以下问题,我已经安装了一个带有 CentOS 7 的服务器。现在我想将此服务器用于 git。
问题是我无法通过 SSH 连接到服务器来执行此操作。我已经制作了密钥并将 id_rsa 密钥放入 C:\Users\MYNAME.ssh
我还在服务器上创建了一个 git 用户并将 public 键放入 /home/git/.ssh/authorized_keys
当我想将存储库克隆到我的服务器时,我使用以下命令:
$ git clone ssh://git@IP/domains/optiekruymen.be/public_html/.git
输出为
Cloning into 'public_html'...
Enter passphrase for key '/c/Users/MYNAME/.ssh/id_rsa':
git@IP's password:
我不明白为什么我还需要提供 git 密码,因为我想使用 ssh 连接而不是 git 用户的密码。
我使用 ssh-keygen 在 Centos 上生成了密钥,而不是使用
复制的
cat id_rsa.pub >> /home/git/.ssh/authorized_keys
将文件复制到 git 用户下一步我将密钥下载到我的电脑并将 id_rsa 复制到 /c/Users/MYNAME/.ssh/id_rsa
额外输出
.ssh 文件设置
drwx------ 2 git git 4096 Feb 13 20:59 .ssh
authorized_keys 文件设置
-rw-r--r-- 1 git git 408 Feb 13 20:53 authorized_keys
其他调试信息
debug1: Trying private key: /c/Users/USERNAME/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA
SHA256:xUB8U9Mn3EkwzhLXjsBlZU1tJMViEfM/Yit5Kjkv/TA
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with mic,password
此消息表示您的私钥受密码保护(使用密码加密),在连接到远程主机之前,需要解密此密钥(通过您输入密码)。
解决这个问题最简单的方法是 remove the passphrase from the private key.
我通过将用户 git 添加到 /etc/ssh/sshd_config 文件解决了这个问题
并检查以下配置
- 服务器上的主目录不应被其他人写入:chmod go-w /home/user
- 服务器上的SSH文件夹需要700权限:chmod 700 /home/user/.ssh
- Authorized_keys文件需要644权限:chmod 644/home/user/.ssh/authorized_keys
- 确保用户拥有 files/folders 而不是 root:chown user:user authorized_keys 和 chown user:user /home/user/.ssh
- 将生成的 public 密钥(来自 ssh-keygen)放入服务器上用户的 authorized_keys 文件中
- 确保用户的主目录设置为您所期望的,并且它包含您一直在修改的正确的 .ssh 文件夹。如果不是,请使用 usermod -d /home/user user 来解决问题
- 最后,重启ssh:service ssh restart
- 然后确保客户端在本地用户的 .ssh 文件夹中有 public 密钥和私钥文件并登录:ssh user@host.com
来自此消息:
git@IP's password:
您可以看到您正在获取 git
用户的密码。
正如您上面提到的,一旦您将用户添加到 /etc/ssh/sshd_config
,它就不再要求您输入密码。
/etc/ssh/sshd_config 文件
The /etc/ssh/sshd_config file is the system-wide configuration file for OpenSSH
which allows you to set options that modify the operation of the daemon.
This file contains keyword-value pairs, one per line, with keywords being case insensitive.
我有以下问题,我已经安装了一个带有 CentOS 7 的服务器。现在我想将此服务器用于 git。
问题是我无法通过 SSH 连接到服务器来执行此操作。我已经制作了密钥并将 id_rsa 密钥放入 C:\Users\MYNAME.ssh
我还在服务器上创建了一个 git 用户并将 public 键放入 /home/git/.ssh/authorized_keys
当我想将存储库克隆到我的服务器时,我使用以下命令:
$ git clone ssh://git@IP/domains/optiekruymen.be/public_html/.git
输出为
Cloning into 'public_html'...
Enter passphrase for key '/c/Users/MYNAME/.ssh/id_rsa':
git@IP's password:
我不明白为什么我还需要提供 git 密码,因为我想使用 ssh 连接而不是 git 用户的密码。
我使用 ssh-keygen 在 Centos 上生成了密钥,而不是使用
复制的cat id_rsa.pub >> /home/git/.ssh/authorized_keys
将文件复制到 git 用户下一步我将密钥下载到我的电脑并将 id_rsa 复制到 /c/Users/MYNAME/.ssh/id_rsa
额外输出
.ssh 文件设置
drwx------ 2 git git 4096 Feb 13 20:59 .ssh
authorized_keys 文件设置
-rw-r--r-- 1 git git 408 Feb 13 20:53 authorized_keys
其他调试信息
debug1: Trying private key: /c/Users/USERNAME/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA
SHA256:xUB8U9Mn3EkwzhLXjsBlZU1tJMViEfM/Yit5Kjkv/TA
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with mic,password
此消息表示您的私钥受密码保护(使用密码加密),在连接到远程主机之前,需要解密此密钥(通过您输入密码)。
解决这个问题最简单的方法是 remove the passphrase from the private key.
我通过将用户 git 添加到 /etc/ssh/sshd_config 文件解决了这个问题
并检查以下配置
- 服务器上的主目录不应被其他人写入:chmod go-w /home/user
- 服务器上的SSH文件夹需要700权限:chmod 700 /home/user/.ssh
- Authorized_keys文件需要644权限:chmod 644/home/user/.ssh/authorized_keys
- 确保用户拥有 files/folders 而不是 root:chown user:user authorized_keys 和 chown user:user /home/user/.ssh
- 将生成的 public 密钥(来自 ssh-keygen)放入服务器上用户的 authorized_keys 文件中
- 确保用户的主目录设置为您所期望的,并且它包含您一直在修改的正确的 .ssh 文件夹。如果不是,请使用 usermod -d /home/user user 来解决问题
- 最后,重启ssh:service ssh restart
- 然后确保客户端在本地用户的 .ssh 文件夹中有 public 密钥和私钥文件并登录:ssh user@host.com
来自此消息:
git@IP's password:
您可以看到您正在获取 git
用户的密码。
正如您上面提到的,一旦您将用户添加到 /etc/ssh/sshd_config
,它就不再要求您输入密码。
/etc/ssh/sshd_config 文件
The /etc/ssh/sshd_config file is the system-wide configuration file for
OpenSSH
which allows you to set options that modify the operation of the daemon.This file contains keyword-value pairs, one per line, with keywords being case insensitive.