Multiple git accounts generate multiple RSA secret keys to implement multi-account simultaneous use configuration

Source: Internet
Author: User
Tags ssh


Use Git's child shoes should be ID_RSA secret key is not unfamiliar, must use GitHub bar, the generation Id_rsa is very easy:

Ssh-keygen-t rsa-c "$your _email"

By default, this secret key is generated in your account in the. SSH directory generates ID_RSA files, corresponding to a id_rsa.pub public key file,

$ ssh-keygen-t rsa-c "test@test.com"
Generating public/private RSA key pair.
Enter file in which to save the key (/C/USERS/ZHONG/.SSH/ID_RSA):
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/c/users/zhong/.ssh/id_rsa.
Your public key has been saved in/c/users/zhong/.ssh/id_rsa.pub.
The key fingerprint is:
5B:44:7E:B8:E5:20:3B:A8:2B:63:45:C0:F8:73:87:F3 test@test.com
The key ' s Randomart image is:
+--[RSA 2048]----+
|      O. |
|.     o O. |
| . . .  . = O |
| o =.. + *     |
| + +.    S O. |
| .. E + |
|   ..        . |
|           +  . |
| . O. |
+-----------------+

The secret key is tied to an email address, and the secret key is that the secret key is generated by test@test.com, so you can use id_ in any place where test@test.com address authentication is used. Rsa.pub Public key verifies your private key, because the system will read you by default at checksum. Ssh/id_rsa this secret key file.
This is in the use of a single secret key users, there is no problem, however, you may have other mailbox accounts, you need to generate two secret keys, so you should pay attention to the name of the generation, do not put the existing id_rsa to cover.


$ ssh-keygen-t rsa-c "test2@domain.com"
Generating public/private RSA key pair.
Enter file in which to save the key (/C/USERS/ZHONG/.SSH/ID_RSA):/c/users/zhong
/.ssh/id_rsa_gitlab
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/c/users/zhong/.ssh/id_rsa_gitlab.
Your public key has been saved in/c/users/zhong/.ssh/id_rsa_gitlab.pub.
The key fingerprint is:
5B:44:7E:B8:E5:20:3B:A8:2B:63:45:C0:F8:73:87:F3 test2@domain.com
The key ' s Randomart image is:
+--[RSA 2048]----+
|      O. |
|.     o O. |
| . . .  . = O |
| o =.. + *     |
| + +.    S O. |
| .. E + |
|   ..        . |
|           +  . |
| . O. |
+-----------------+
In the Enter file Inwhich to save the key prompts this place to typing the name of the generated private key, because you want to keep the default private key, so you need to take another name, if you typed the secret key name already exists, then you will be prompted that the same name of the key file already exists, whether to overwrite


$ ssh-keygen-t rsa-c "test@test.com"
Generating public/private RSA key pair.
Enter file in which to save the key (/C/USERS/ZHONG/.SSH/ID_RSA):
/c/users/zhong/.ssh/id_rsa already exists.
Overwrite (y/n)?
I've generated two secret keys, which are the default Id_rsa and Id_rsa_gitlab, so. SSH directory should have these files:


Zhong@lee ~
$ ls. SSH
Id_rsa id_rsa.pub Id_rsa_gitlab id_rsa_gitlab.pub known_hosts
The pub end is the public key, next, is to configure the SSH to allow the system to find Id_rsa_gitlab this public key, according to Google's results, only to execute the SSH-ADD secret key path can be


$ ssh-add/c/users/zhong/.ssh/id_rsa_gitlab
Could not open a connection to your authentication agent.
And I'm going to prompt when I execute the command: Could not open a connection to your authentication agent. And maybe this is a lot of people have problems, so the corresponding prompts if this error occurs first execute the following ssh-agent Bash and then execute the ssh-add command.


$ ssh-agent Bash
bash-3.1$ Ssh-add/c/users/zhong/.ssh/id_rsa_gitlab
Could not open a connection to your authentication agent.
The results showed that I couldn't solve the problem even though Ssh-agent bash was first executed, and I didn't find a solution in a large circle. This step is to be configured, or even if you put the public key to the GIT host and try to connect Id_rsa_gitlab This account of the host, because it will find the default Id_rsa this key to do the check, the result must be a checksum, so there will be a password to enter the hint:


$ ssh-t git@192.168.1.2
The authenticity of host ' 192.168.1.2 (192.168.1.2) ' can ' t be established

RSA key fingerprint is d9:8c:82:18:e7:86:3f:7d:ee:01:9d:bb:7d:40:86:5e.
Are you sure your want to continue connecting (yes/no)? Yes
warning:permanently added ' 192.168.1.2 ' (RSA) to the list of known hosts.
git@192.168.1.2 ' s Password:
and the default Id_rsa account checksum is still no problem.


$ ssh-t git@github.com
Hi lizhong! ' ve successfully authenticated, but GitHub does not provide s
Hell access.
After looking for half a day to find that can not solve the ssh-add command problem, I inadvertently saw config configuration, so I skipped ssh-add directly in. ssh new config file:


Host github.com
HostName github.com
User git
Identityfile/c/users/zhong/.ssh/id_rsa

Host 192.168.1.2
HostName 192.168.1.2
User git
Identityfile/c/users/zhong/.ssh/id_rsa_gitlab
Clear known_hosts file and test again, it's normal.

Zhong@lee ~
$ ssh-t git@github.com
The authenticity of host ' github.com (192.30.252.130) ' can ' t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure your want to continue connecting (yes/no)? Yes
warning:permanently added ' github.com,192.30.252.130 ' (RSA) to the list of know
N hosts.
Hi lizhong8532! ' ve successfully authenticated, but GitHub does not provide s
Hell access.

Zhong@lee ~
$ ssh-t git@192.168.1.2
The authenticity of host ' 192.168.1.2 (192.168.1.2) ' can ' t be established.

RSA key fingerprint is d9:8c:82:18:e7:86:3f:7d:ee:01:9d:bb:7d:40:86:5e.
Are you sure your want to continue connecting (yes/no)? Yes
warning:permanently added ' 192.168.1.2 ' (RSA) to the list of known hosts.
Welcome to Gitlab, lizhong!

If the configuration is not good, but also prompted to lose the password of the children's shoes can be this test

SSH-VV "Your Githost"

The

will see the entire debug process, focusing on whether to read the config file and match it to the host and read the corresponding private key under the host configuration, generally if the private key pair succeeds that's basically fine

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.