SSH connection Windows to CentOS 7 for git

2019-09-20 04:47发布

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

3条回答
干净又极端
2楼-- · 2019-09-20 05:32

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
查看更多
萌系小妹纸
3楼-- · 2019-09-20 05:38

This message means that your private key is password-protected (encrypted with a password), before a connection to the remote host can be made, this key needs to be decrypted (by you inputing the password).

The easiest way to solve thi is to remove the passphrase from the private key.

查看更多
一纸荒年 Trace。
4楼-- · 2019-09-20 05:48

From this message:

git@IP's password:

You can see that you are being for the password for the git user.
As you mentioned above once you added the user to the /etc/ssh/sshd_config its no longer asking you for password.


/etc/ssh/sshd_config file

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.

查看更多
登录 后发表回答