Home >Development Tools >git >Explain how to set up SSH Key on Git

Explain how to set up SSH Key on Git

PHPz
PHPzOriginal
2023-04-03 09:18:1513484browse

Git is currently one of the most popular version control software in the world founded by Linus Torvalds. During the development process, we can use Git to perform version control, collaborative development, etc. on the code. When using Git, we can use SSH Key for authentication to facilitate a secure connection between our code base and the server. Below, we will explain in detail how to set up SSH Key on Git.

1. Generate SSH Key

  1. Open the terminal or command line.
  2. Enter and execute the following command:
ssh-keygen -t rsa -C "your_email@example.com"

Among them, replace "your_email@example.com" with your email address.

After execution, the following prompt will appear:

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):

Just press the Enter key and use the default situation. Next, you will be prompted to enter your password, or you can just press Enter to skip it.

  1. After successful generation, you can see two files in the .ssh directory: id_rsa and id_rsa.pub.

2. Add SSH Key to GitHub account

  1. Log in to your GitHub account.
  2. Click on the avatar in the upper right corner and select Settings.
  3. Select SSH and GPG keys.
  4. Click New SSH key in the upper right corner.
  5. In the pop-up box to add SSH Key, enter Title and Key.

Title is a name for the SSH Key, and Key is the public key content of the SSH Key generated in the terminal (that is, id_rsa. in the .ssh directory. pub file contents).

  1. Click to add.

3. Add SSH Key to GitLab account

  1. Log in to your GitLab account.
  2. Click on the avatar in the upper right corner and select Settings.
  3. Select SSH keys.
  4. Click Add SSH key in the upper right corner.

Title is a name for the SSH Key, and Key is the public key content of the SSH Key generated in the terminal (that is, id_rsa. in the .ssh directory. pub file contents).

  1. Click to add.

4. Add SSH Key to Bitbucket account

  1. Log in to your Bitbucket account.
  2. Click the avatar in the upper right corner and select Bitbucket settings.
  3. Select SSH keys.
  4. Click Add key in the upper right corner.

Title is a name for the SSH Key, and Key is the public key content of the SSH Key generated in the terminal (that is, id_rsa. in the .ssh directory. pub file contents).

  1. Click to add.

5. Test SSH Key

Enter the following command in the terminal:

ssh -T git@github.com

Taking GitHub as an example, if the following prompt appears, it means success:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If you encounter connection problems, you need to further check the SSH Key configuration, firewall, etc.

The above is the detailed content of Explain how to set up SSH Key on Git. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn