Page cover image

Connecting to GitHub with SSH

You can connect to GitHub using the Secure Shell Protocol (SSH), which provides a secure channel over an unsecured network.
    Tags
    Published
    Jan 4, 2023
    noBg
    noBg
    If you received the “Support for password authentication was removed on August 13, 2021” error message, consider setting up SSH access to GitHub.
    ℹ️ Text in angle brackets "< >" are supposed to be replaced with your own information

    Generate SSH Key

    1. Open Terminal / Git Bash / PowerShell
    1. Enter this command to generate a SSH Key
      1. ssh-keygen -t ed25519 -C "<Your_GitHub_Email_Address>"
        If you are using a legacy system that doesn't support the Ed25519 algorithm, use
        ssh-keygen -t rsa -b 4096 -C "<Your_GitHub_Email_Address>"
    1. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location
      1. > Enter a file in which to save the key (</PATH/TO/KEY>): [Press enter]
    1. At the prompt, type a secure passphrase
      1. You will need to enter this passphrase every time you use your SSH Key
        Optionally, you can leave it empty and press enter
        > Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]

    Obtain Public Key

    The output should include the following two lines:
    Your identification has been saved in </PATH/TO/KEY> Your public key has been saved in </PATH/TO/KEY>.pub
    Use the cat command to display the content of your public key:
    cat </PATH/TO/KEY.pub>
    The output should look like:
    ssh-ed25519 ****** <Your_GitHub_Email_Address>
    Select and copy this to your clipboard.

    Add Public key to GitHub Account

    1. Go to https://github.com/settings/ssh/new
    1. In the Title field, add a descriptive label for the new key. (E.g. My MacBook Pro)
    1. Leave Key type as is
    1. Paste your public key into the Key field
    1. Click Add SSH key

    Using SSH to Clone a Repository

    You can now see SSH as an option when you are trying to clone a GitHub repository.
    git clone <SSH_URL>
    If this is your first time connecting to GitHub with SSH, you may see a warning like this:
    > The authenticity of host 'github.com (IP ADDRESS)' can't be established. > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. > Are you sure you want to continue connecting (yes/no)?
    Verify that the fingerprint in the message you see matches GitHub's public key fingerprint. If it does, type yes.
    Then, enter your SSH passphrase if prompted.

    Update Local Repo Cloned with HTTPS to SSH

    If you have cloned an repository using HTTPS already (git clone <https://github.com/>), you can set its remote url to the SSH URL.
    git remote set-url origin <NEW_SSH_URL>

    References