Git SSH Key: A Guide to Creating and Using SSH Key in Git

SSH Key (Secure Shell Key) is a pair of cryptographic keys used in the SSH protocol for authentication and data encryption over a network. In Git, SSH Key is used to establish a secure connection between your personal computer and a remote Git server, allowing you to perform operations like clone, push, and pull without entering a password each time.

 

Here's how to create an SSH Key on different operating systems:

On Windows:

  1. Open Git Bash (if you have Git installed) or Command Prompt.

  2. Enter the following command to generate a new SSH Key:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
    
  3. You will be prompted to choose the location to save the SSH Key. By default, it will be saved in C:\Users\your_username\.ssh\. You can also specify a custom path.

  4. Once completed, the system will generate two files: id_rsa (private key) and id_rsa.pub (public key) in the .ssh directory.

  5. Copy the content of the public key (id_rsa.pub) using the type command and add it to your remote Git account on the Git hosting website (e.g., GitHub, GitLab) in the SSH Keys section.

 

On Linux and macOS:

  1. Open the Terminal.

  2. Enter the following command to generate a new SSH Key:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
    
  3. You will be prompted to choose the location to save the SSH Key. By default, it will be saved in ~/.ssh/. You can also specify a custom path.

  4. Once completed, the system will generate two files: id_rsa (private key) and id_rsa.pub (public key) in the .ssh directory.

  5. Copy the content of the public key (id_rsa.pub) using the cat command and add it to your remote Git account on the Git hosting website (e.g., GitHub, GitLab) in the SSH Key section.

 

After creating and adding the SSH Key, you can use Git without entering a password each time you access the remote server.