1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/content/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account.md

5.9 KiB

title, intro, redirect_from, versions, topics, shortTitle
title intro redirect_from versions topics shortTitle
Adding a new SSH key to your GitHub account To configure your {% data variables.product.product_name %} account to use your new (or existing) SSH key, you'll also need to add it to your {% data variables.product.product_name %} account.
/articles/adding-a-new-ssh-key-to-your-github-account
/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
fpt ghes ghae
* * *
SSH
Add a new SSH key

Before adding a new SSH key to your {% data variables.product.product_name %} account, you should have:

After adding a new SSH key to your {% data variables.product.product_name %} account, you can reconfigure any local repositories to use SSH. For more information, see "Switching remote URLs from HTTPS to SSH."

{% data reusables.ssh.key-type-support %}

{% mac %}

{% include tool-switcher %} {% webui %}

  1. Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.

$ pbcopy < ~/.ssh/id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub
# Copies the contents of the id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub file to your clipboard

{% tip %}

Tip: If pbcopy isn't working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

{% endtip %}

{% data reusables.user_settings.access_settings %} {% data reusables.user_settings.ssh %} 4. Click New SSH key or Add SSH key. SSH Key button 5. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air". 6. Paste your key into the "Key" field. The key field 7. Click Add SSH key. The Add key button {% data reusables.user_settings.sudo-mode-popup %}

{% endwebui %}

{% endmac %}

{% windows %}

{% include tool-switcher %}

{% webui %}

  1. Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.

$ clip < ~/.ssh/id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub
# Copies the contents of the id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub file to your clipboard

{% tip %}

Tip: If clip isn't working, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

{% endtip %}

{% data reusables.user_settings.access_settings %} {% data reusables.user_settings.ssh %} 4. Click New SSH key or Add SSH key. SSH Key button 5. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air". 6. Paste your key into the "Key" field. The key field 7. Click Add SSH key. The Add key button 8. If prompted, confirm your {% data variables.product.product_name %} password. Sudo mode dialog

{% endwebui %}

{% endwindows %}

{% linux %}

{% include tool-switcher %} {% webui %}

  1. Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.

$ cat ~/.ssh/id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub
# Then select and copy the contents of the id_{% ifversion ghae %}rsa{% else %}ed25519{% endif %}.pub file
# displayed in the terminal to your clipboard

{% tip %}

Tip: Alternatively, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

{% endtip %}

{% data reusables.user_settings.access_settings %} {% data reusables.user_settings.ssh %} 4. Click New SSH key or Add SSH key. SSH Key button 5. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air". 6. Paste your key into the "Key" field. The key field 7. Click Add SSH key. The Add key button 8. If prompted, confirm your {% data variables.product.product_name %} password. Sudo mode dialog

{% endwebui %}

{% endlinux %}

{% cli %}

{% data reusables.cli.cli-learn-more %}

To add an SSH key to your GitHub account, use the ssh-key add subcommand, specifying your public key.

gh ssh-key add <em>key-file</em>

To include a title for the new key, use the -t or --title flag.

gh ssh-key add <em>key-file</em> --title "personal laptop"

{% endcli %}

{% ifversion fpt %}

Further reading