Git's tortoisegit using a key to connect to the server method

Source: Internet
Author: User
Tags chmod ssh git clone

Git is a good thing, and tortoisegit is a good thing. The use of Tortoisegit in Windows is much more, while the command line is relatively small.

For Tortoisegit, there are two ways to support the use of keys, one is to support openssh keys, and one is to support putty keys. But these two different, for Linux ssh generally use OpenSSH, but it doesn't matter, we can convert.

Using the Putty key

Let's take a look at the way in which you can actually choose the SSH client to use by default when installing Tortoisegit, by default, by using the Tortoisegitplink client.

Specifies that the client for SSH is Tortoisegit


Generate Putty Key

When installing Tortoisegit, the default will also install Puttygen.exe this program, this program can generate Putty key.

Clicking the Generate button presses a progress bar and the mouse keeps moving inside the program to generate some random numbers.

The first time I used the mouse to be silly, and then the progress bar is very slow, I want this thing to generate a key so slow? It turns out that I opened the wrong way.

Click Save private key to keep Putty's private key, Putty's key suffix name is PPK.

Add the OpenSSH public key to the server

We created the Putty key pair above, and now we need to add the generated public key to the server.

In fact, the public key can also be added to the github.com, but also can be used.

The public key generated by Putty is the same as the public key of the OpenSSH, and they are only the private key different
Suppose that the public key you just generated is


Ssh-rsa aaaab3nzac1yc2eaaaabjqaaaqeai1vfwinbamtpuospewvqdyreffcupkuuze5y6r4l/ xeav7e9f5qdr6qeo215r2qbbnuixagzpjzpsvr7s51qinuq6eyxm4kfgiw6b/ l4zvjx5dkxoftno39xe58qqnaixohnn9ccnhetcxejp7goro1k7amumuqy7v/ 6aekiopfh6qswuumf6hzhzmqpu3q3xaqhlmou5emaif4bqkzfgheyofthzh+e+yo+ed65ktoj+v5pjpxd6rmgfx3a7mhsv5pxdijd7yu0b33r+ medloqro1rdquovirybbue4gcu63a3j8+3gifxbrxohzlmipaythxhjg5xulgenlemodw== Rsa-key

Log on to the server with the name of the user who needs to add the public key, such as User1.

cd/home/user1/
mkdir. SSH #如果这个目录不存在
Touch. Ssh/authorized_keys #如果这个文件不存在
chmod Ssh/authorized_keys #设置一下文件的权限
echo "Ssh-rsa aaaab3nzac1yc2eaaaabjqaaaqeai1vfwinbamtpuospewvqdyreffcupkuuze5y6r4l/ xeav7e9f5qdr6qeo215r2qbbnuixagzpjzpsvr7s51qinuq6eyxm4kfgiw6b/ l4zvjx5dkxoftno39xe58qqnaixohnn9ccnhetcxejp7goro1k7amumuqy7v/ 6aekiopfh6qswuumf6hzhzmqpu3q3xaqhlmou5emaif4bqkzfgheyofthzh+e+yo+ed65ktoj+v5pjpxd6rmgfx3a7mhsv5pxdijd7yu0b33r+ medloqro1rdquovirybbue4gcu63a3j8+3gifxbrxohzlmipaythxhjg5xulgenlemodw== Rsa-key "\
>> Ssh/authorized_keys #这个和上面是同一行的
Note: The public key in the Authorized_keys file form is a one-line public key, remember. Otherwise, the public key does not work.
Using keys on Tortoisegit

The public key has been added to the server, and the next step is to set the key on the client.

Used when Git clone, the following settings:

git clone set Putty private key
So we can fix it.

Putty Key and OpenSSH key conversion

If you have a putty private key, but want to use the OpenSSH's private key under the SSH client, then it is troublesome to generate a OpenSSH key pair (laziness is lazy).

Click the Import key in the Conversions menu item
Select a putty private key or OpenSSH's private key
Click Save private key to be saved as Putty's private key
Or click the menu Conversions->export OpenSSH key to save as OpenSSH's private key


SSH login has failed

If SSH login has failed, see if there are problems with permissions


Enter SSH connection code


Ssh-i private.key-v User@host.com-p22

There is nothing wrong with the information from the connection.

Debug1:authentications that can Continue:publickey,gssapi-keyex,gssapi-with-mic,password
Debug1:next Authentication Method:publickey
Debug1:offering Public Key:private.key
Debug1:authentications that can Continue:publickey,gssapi-keyex,gssapi-with-mic,password
Debug1:next Authentication Method:password
I've been prompted to sign in with the public key and provided the private key, but I'm prompted to enter the password.

But I use another account to log in, found is OK, you can log in successfully. I copied the successful ' Authorized_keys ' to my user name and found that I still couldn't log in. But verify that the server's sshd function is normal operation, otherwise an account will not be able to log in. I think two user names should be in the same environment, but you can't log in.

Think of the client here the connection does not have more effective information, then think of the server to see the relevant information. ' Vim/var/log/secure ' Check the log. Found that there was such a passage:


Authentication Refused:bad ownership or modes for DIRECTORY/HOME/USER/.SSH

The Internet search for this problem, found that the original is '. SSH ' directory permissions are not right, set the correct permissions:


chmod ~/.ssh

In the process also learned a sshd test mode.


/usr/sbin/sshd-p 10022-d
-d runs in debug mode. The server will run in the foreground and send very detailed debug log information.
The server will only allow access to one connection and no child processes are derived. For debugging purposes only.
Use multiple-D options to output more detailed debugging information (up to 3).
will open a sshd debug mode, create a new 10022 port, when the client is connected to the port, the server will have debug log output on the screen, this time can view detailed information. And then solve the information.

# # Summary
The server user has some permission requirements for SSH directory permissions, and SSH does not work if the permissions are incorrect, the following permissions are recommended as the minimum permissions.


chmod ssh # chmod 755 ssh is okay.
chmod Ssh/authorized_keys.
chmod Ssh/private.key #把密钥的权限也设置为最小
Finally can be happy to program again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.