Git Tutorial #17: What is SSH and How to Use It with Git | Learn Git with GitKraken

4 min read 30 days ago
Published on Aug 04, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, we will explore SSH (Secure Shell) and its significance in facilitating secure connections to remote Git repositories. By the end of this guide, you'll understand how SSH keys function within version control systems and how to set them up using GitKraken Desktop, enhancing your workflow with platforms like GitHub, GitLab, and Bitbucket.

Step 1: Understanding SSH and Its Importance

  • What is SSH?
    SSH stands for Secure Shell, a protocol that allows secure communication over a network. It is widely used for securely accessing remote computers and managing servers.

  • Why SSH Matters for Git
    When working with Git, SSH provides a secure method to authenticate your identity without entering your password each time you push or pull changes to a repository. This not only saves time but also improves security.

Step 2: How SSH Keys Work

  • What are SSH Keys?
    SSH keys are cryptographic keys used for authentication. They come in pairs: a public key and a private key.

  • Public Key
    The public key is shared with remote servers (like GitHub or GitLab) and can be openly distributed.

  • Private Key
    The private key is kept secret and stored securely on your local machine. It should never be shared.

  • How They Work Together
    When you attempt to connect to a remote server, the server checks if your public key matches the private key. If they match, you gain access without needing a password.

Step 3: Generating SSH Keys

  1. Open Terminal or Command Prompt

    • On Windows, use Git Bash or Command Prompt.
    • On macOS or Linux, use the Terminal.
  2. Generate SSH Key Pair
    Run the following command:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
    • Replace your_email@example.com with your actual email address.
    • Press Enter to accept the default file location.
  3. Set a Passphrase (Optional)
    You can add a passphrase for extra security. If you choose to set one, you will need to enter it each time you use the key.

Step 4: Adding Your SSH Key to the SSH Agent

  1. Start the SSH Agent
    Run the following command to ensure the SSH agent is running:

    eval "$(ssh-agent -s)"
    
  2. Add Your SSH Key
    Use the command below, replacing ~/.ssh/id_rsa with the path to your private key if different:

    ssh-add ~/.ssh/id_rsa
    

Step 5: Adding Your SSH Key to Your Git Account

  1. Copy Your Public Key
    Use the following command to copy your public key to the clipboard:

    cat ~/.ssh/id_rsa.pub
    
    • Alternatively, you can manually open the file in a text editor and copy its contents.
  2. Add to GitHub/GitLab/Bitbucket

    • GitHub: Go to Settings > SSH and GPG keys > New SSH key. Paste your key and save.
    • GitLab: Navigate to User Settings > SSH Keys. Paste your key and save.
    • Bitbucket: Go to Personal settings > SSH keys. Paste your key and save.

Step 6: Testing Your SSH Connection

  • After adding your SSH key, you can test the connection with the following command:
    ssh -T git@github.com
    
    • Replace github.com with gitlab.com or bitbucket.org as needed. You should see a success message confirming the connection.

Conclusion

In this tutorial, we covered the basics of SSH, its importance for Git, and how to set up SSH keys using GitKraken Desktop. By configuring SSH for your Git operations, you streamline your workflow and enhance security. As a next step, consider exploring more advanced Git features or integrating with other tools to further improve your development process.