Skip to main content

Adding a new SSH key to your GitHub account

To configure your account on GitHub.com to use your new (or existing) SSH key, you'll also need to add the key to your account.

About addition of SSH keys to your account

You can access and write data in repositories on GitHub.com using SSH (Secure Shell Protocol). When you connect via SSH, you authenticate using a private key file on your local machine. For more information, see "About SSH."

After you generate an SSH key pair, you must add the public key to GitHub.com to enable SSH access for your account.

Prerequisites

Before adding a new SSH key to your account on GitHub.com, complete the following steps.

  1. Check for existing SSH keys. For more information, see "Checking for existing SSH keys."
  2. Generate a new SSH key and add it to your machine's SSH agent. For more information, see "Generating a new SSH key and adding it to the ssh-agent."

Adding a new SSH key to your account

After adding a new SSH key to your account on GitHub.com, you can reconfigure any local repositories to use SSH. For more information, see "Switching remote URLs from HTTPS to SSH."

Nota: GitHub mejorò la seguridad al dejar los tipos de llave inseguros el 15 de marzo de 2022.

Desde esta fecha, las llaves DSA (ssh-dss) ya no son compatibles. No puedes agregar claves DSA nuevas a tu cuenta personal de GitHub.com.

Las llaves RSA (ssh-rsa) con un valid_after anterior al 2 de noviembre de 2021 podrán continuar utilizando cualquier algoritmo de firma. Las llaves RSA que se generaron después de esta fecha deberán utilizar un algoritmo de firma de tipo SHA-2. Algunos clientes más angituos podrían necesitar actualizarse para poder utilizar firmas de tipo SHA-2.

  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_ed25519.pub
    # Copies the contents of the id_ed25519.pub file to your clipboard

    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.

  2. En la esquina superior derecha de cualquier página, da clic en tu foto de perfil y después da clic en Configuración.

    Icono Settings (Parámetros) en la barra de usuario

  3. En la sección de "Acceso" de la barra lateral, haz clic en Llaves SSH y GPG.

  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. Si se te solicita, confirma el acceso a tu cuenta en GitHub. Para obtener más información, consulta la sección "modo Sudo".

  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_ed25519.pub
    # Copies the contents of the id_ed25519.pub file to your clipboard

    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.

  2. En la esquina superior derecha de cualquier página, da clic en tu foto de perfil y después da clic en Configuración.

    Icono Settings (Parámetros) en la barra de usuario

  3. En la sección de "Acceso" de la barra lateral, haz clic en Llaves SSH y GPG.

  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. Si se te solicita, confirma el acceso a tu cuenta en GitHub. Para obtener más información, consulta la sección "modo Sudo".

  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_ed25519.pub
    # Then select and copy the contents of the id_ed25519.pub file
    # displayed in the terminal to your clipboard

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

  2. En la esquina superior derecha de cualquier página, da clic en tu foto de perfil y después da clic en Configuración.

    Icono Settings (Parámetros) en la barra de usuario

  3. En la sección de "Acceso" de la barra lateral, haz clic en Llaves SSH y GPG.

  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. Si se te solicita, confirma el acceso a tu cuenta en GitHub. Para obtener más información, consulta la sección "modo Sudo".

Para aprender más sobre el CLI de GitHub, consulta la sección "Acerca del CLI de GitHub".

Before you can use the CLI de GitHub to add an SSH key to your account, you must authenticate to the CLI de GitHub. For more information, see gh auth login in the CLI de GitHub documentation.

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

gh ssh-key add key-file

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

gh ssh-key add key-file --title "personal laptop"

If you generated your SSH key by following the instructions in "Generating a new SSH key", you can add the key to your account with this command.

gh ssh-key add ~/.ssh/id_ed25519.pub

Further reading