SSH连接Windows到CentOS 7 for git [英] SSH connection Windows to CentOS 7 for git

查看:228
本文介绍了SSH连接Windows到CentOS 7 for git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的问题,我已经安装了CentOS 7的服务器。现在我想用这个服务器作为git。



问题是我无法与服务器建立SSH连接来执行此操作。我已经创建了密钥,并将id_rsa键放在C:\ Users \MYNAME.ssh中。

我还在服务器上创建了一个git用户,并将公钥in /home/git/.ssh/authorized_keys



当我想将存储库克隆到我的服务器时,我使用以下命令:

  $ git clone ssh://git@IP/domains/optiekruymen.be/public_html/.git 

lockquote

克隆到'public_html'... p>

输入密码'/c/Users/MYNAME/.ssh/id_rsa'的密码:



git @ IP的密码:

我不明白为什么我仍然需要提供git密码,因为我想要使用ssh连接而不是



我使用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

其他调试信息
$ b


debug1:尝试私钥:/ c / Users / USERNAME / .ssh / id_rsa

debug3:sign_and_send_pubkey:RSA

SHA256:xUB8U9Mn3EkwzhLXjsBlZU1tJMViEfM / Yit5Kjkv / TA
debug2:我们发送了一个publickey包,等待回复


debug1:可以继续的验证:publickey,gssapi- keyex,gssapi-with mic,password



解决方案

我通过将用户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

  • 确保用户拥有文件/文件夹而不是root:chown user:user authorized_keys和chown user:user /home/user/.ssh

  • 将生成的公钥(来自ssh-keygen)放入服务器上的用户的authorized_keys文件

  • 确保用户的主目录设置为您所期望的并且它包含您正在修改的正确的.ssh文件夹。如果没有,请使用usermod -d / home / user用户来解决问题。
  • 最后,重新启动ssh:service ssh restart

  • 然后确保客户端在本地用户的.ssh文件夹和登录中有公用密钥和私钥文件:ssh user@host.com


I've got the following question, I've installed a server with CentOS 7. Now I want to use this server for git.

The problem is I can't make an SSH connection to the sever to do this. I already made keys and I putted the id_rsa key in C:\Users\MYNAME.ssh

I also created an git user on the server and putted the public key in /home/git/.ssh/authorized_keys

When I want to clone the repository to my server I use the following command:

$ git clone ssh://git@IP/domains/optiekruymen.be/public_html/.git

The output is

Cloning into 'public_html'...

Enter passphrase for key '/c/Users/MYNAME/.ssh/id_rsa':

git@IP's password:

I don't understand why I still need to give the git password, beceause I want tot use the ssh connection and not the password of the git user.

I generated the key on Centos using ssh-keygen, than i copied using

cat id_rsa.pub >> /home/git/.ssh/authorized_keys

to copy the file to the git user user next i downloaded the key to my pc and copied id_rsa to /c/Users/MYNAME/.ssh/id_rsa

Extra output

.ssh file settings

drwx------ 2 git git 4096 Feb 13 20:59 .ssh

authorized_keys file settings

-rw-r--r-- 1 git git 408 Feb 13 20:53 authorized_keys

other debug info

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

解决方案

I solved this by adding the user git to the /etc/ssh/sshd_config file

and checking the following configurations

  • Home directory on the server should not be writable by others: chmod go-w /home/user
  • SSH folder on the server needs 700 permissions: chmod 700 /home/user/.ssh
  • Authorized_keys file needs 644 permissions: chmod 644 /home/user/.ssh/authorized_keys
  • Make sure that user owns the files/folders and not root: chown user:user authorized_keys and chown user:user /home/user/.ssh
  • Put the generated public key (from ssh-keygen) in the user's authorized_keys file on the server
  • Make sure that user's home directory is set to what you expect it to be and that it contains the correct .ssh folder that you've been modifying. If not, use usermod -d /home/user user to fix the issue
  • Finally, restart ssh: service ssh restart
  • Then make sure client has the public key and private key files in the local user's .ssh folder and login: ssh user@host.com

这篇关于SSH连接Windows到CentOS 7 for git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆