.bpHkHg:hover{-webkit-text-decoration:none;text-decoration:none;}/!sc/ .bpHkHg:focus{outline:none;}/!sc/ .bpHkHg:disabled{cursor:default;}/!sc/ .bpHkHg:disabled svg{opacity:0.6;}/!sc/ data-styled.g8[id="ButtonBase-sc-181ps9o-0"]{content:"bpHkHg,"}/!sc/ .eAEDUX{color:#0366d6;border:1px solid rgba(27,31,35,0.15);background-color:#fafbfc;box-shadow:0 1px 0 rgba(27,31,35,0.04);}/!sc/ .eAEDUX:hover{color:#ffffff;background-color:#0366d6;border-color:rgba(27,31,35,0.15);box-shadow:0 1px 0 rgba(27,31,35,0.1);}/!sc/ .eAEDUX:focus{border-color:rgba(27,31,35,0.15);box-shadow:0 0 0 3px rgba(0,92,197,0.4);}/!sc/ .eAEDUX:active{color:#ffffff;background-color:hsla(212,97%,40%,1);box-shadow:inset 0 1px 0 rgba(5,38,76,0.2);border-color:rgba(27,31,35,0.15);}/!sc/ .eAEDUX:disabled{color:rgba(3,102,214,0.5);background-color:#fafbfc;border-color:rgba(27,31,35,0.15);}/!sc/ data-styled.g12[id="ButtonOutline-sc-15gta9l-0"]{content:"eAEDUX,"}/!sc/ .wQTPf > summary{list-style:none;}/!sc/ .wQTPf > summary::-webkit-details-marker{display:none;}/!sc/ data-styled.g56[id="Details-ssy9qz-0"]{content:"wQTPf,"}/!sc/ .cbUQRS{position:relative;display:inline-block;}/!sc/ data-styled.g61[id="Dropdown__StyledDetails-sc-16yoecj-0"]{content:"cbUQRS,"}/!sc/ .hKmZUy{border:4px solid transparent;margin-left:12px;border-top-color:currentcolor;border-bottom-width:0;content:'';display:inline-block;height:0;vertical-align:middle;width:0;}/!sc/ data-styled.g62[id="Dropdown__DropdownCaret-sc-16yoecj-1"]{content:"hKmZUy,"}/!sc/ .bwhlIP{background-clip:padding-box;background-color:#ffffff;border:1px solid #e1e4e8;border-radius:6px;box-shadow:0 8px 24px rgba(149,157,165,0.2);left:0;list-style:none;margin-top:2px;padding:5px 0 5px 0 !important;position:absolute;top:100%;width:160px;z-index:100;right:0;left:auto;}/!sc/ .bwhlIP::before{position:absolute;display:inline-block;content:'';}/!sc/ .bwhlIP::after{position:absolute;display:inline-block;content:'';}/!sc/ .bwhlIP::before{border:8px solid transparent;border-bottom-color:#ffffff;}/!sc/ .bwhlIP::after{border:7px solid transparent;border-bottom-color:#ffffff;}/!sc/ .bwhlIP > ul{list-style:none;}/!sc/ .bwhlIP::before{top:-16px;right:9px;left:auto;}/!sc/ .bwhlIP::after{top:-14px;right:10px;left:auto;}/!sc/ data-styled.g63[id="Dropdown__DropdownMenu-sc-16yoecj-2"]{content:"bwhlIP,"}/!sc/ .gcRVWV{display:block;padding:4px 10px 4px 15px;overflow:hidden;color:#24292e;text-overflow:ellipsis;white-space:nowrap;}/!sc/ .gcRVWV a{color:#24292e;-webkit-text-decoration:none;text-decoration:none;display:block;overflow:hidden;color:#24292e;text-overflow:ellipsis;white-space:nowrap;}/!sc/ .gcRVWV:focus,.gcRVWV a:focus{color:#ffffff;-webkit-text-decoration:none;text-decoration:none;background-color:#0366d6;}/!sc/ .gcRVWV:hover,.gcRVWV:hover a{color:#ffffff;-webkit-text-decoration:none;text-decoration:none;background-color:#0366d6;outline:none;}/!sc/ data-styled.g64[id="Dropdown__DropdownItem-sc-16yoecj-3"]{content:"gcRVWV,"}/!sc/ .ucXfF ul{width:unset;}/!sc/ data-styled.g118[id="LanguagePicker___StyledDropdown-sc-1vjz4bo-0"]{content:"ucXfF,"}/!sc/ .cPqkmV ul{width:unset;}/!sc/ data-styled.g120[id="ArticleVersionPicker___StyledDropdown-sc-5dcjuc-0"]{content:"cPqkmV,"}/!sc/ </style>
- All products
- Authentication
- Account security
- Authentication to GitHub
- Create a strong password
- Update access credentials
- Create a PAT
- Reviewing your SSH keys
- Deploy keys
- Authorizing OAuth Apps
- Authorizing GitHub Apps
- Authorized integrations
- Third-party applications
- Review OAuth apps
- Token expiration
- Security log
- Remove sensitive data
- About anonymized URLs
- GitHub's IP addresses
- SSH key fingerprints
- Sudo mode
- Unauthorized access
- Authenticate with SAML
- Troubleshooting SSH
- Use SSH over HTTPS port
- Recover SSH key passphrase
- Deleted or missing SSH keys
- Permission denied (publickey)
- Error: Bad file number
- Error: Key already in use
- Permission denied other-user
- Permission denied other-repo
- Agent failure to sign
- ssh-add: illegal option -- K
- SSL certificate problem
- Error: Unknown key type
- SSH key audit
- Troubleshoot verification
Authentication
After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.
If you don't already have an SSH key, you must generate a new SSH key to use for authentication. If you're unsure whether you already have an SSH key, you can check for existing keys. For more information, see "Checking for existing SSH keys."
If you want to use a hardware security key to authenticate to GitHub, you must generate a new SSH key for your hardware security key. You must connect your hardware security key to your computer when you authenticate with the key pair. For more information, see the OpenSSH 8.2 release notes.
If you don't want to reenter your passphrase every time you use your SSH key, you can add your key to the SSH agent, which manages your SSH keys and remembers your passphrase.
-
Open TerminalTerminalGit Bash.
-
Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
Note: If you are using a legacy system that doesn't support the Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
> Generating public/private ed25519 key pair.
-
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
> Enter a file in which to save the key (/Users/you/.ssh/id_ed25519): [Press enter]
> Enter a file in which to save the key (/c/Users/you/.ssh/id_ed25519):[Press enter]
> Enter a file in which to save the key (/home/you/.ssh/id_ed25519): [Press enter]
-
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. When adding your SSH key to the agent, use the default macOS ssh-add
command, and not an application installed by macports, homebrew, or some other external source.
-
Start the ssh-agent in the background.
$ eval "$(ssh-agent -s)" > Agent pid 59566
Depending on your environment, you may need to use a different command. For example, you may need to use root access by running
sudo -s -H
before starting the ssh-agent, or you may need to useexec ssh-agent bash
orexec ssh-agent zsh
to run the ssh-agent. -
If you're using macOS Sierra 10.12.2 or later, you will need to modify your
~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain.-
First, check to see if your
~/.ssh/config
file exists in the default location.$ open ~/.ssh/config > The file /Users/you/.ssh/config does not exist.
-
If the file doesn't exist, create the file.
$ touch ~/.ssh/config
-
Open your
~/.ssh/config
file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519
Note: If you chose not to add a passphrase to your key, you should omit the
UseKeychain
line.Note: If you see an error like this
/Users/USER/.ssh/config: line 16: Bad configuration option: usekeychain
add an additional config line to your
Host *
section:Host * IgnoreUnknown UseKeychain
-
-
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add -K ~/.ssh/id_ed25519
Note: The
-K
option is Apple's standard version ofssh-add
, which stores the passphrase in your keychain for you when you add an SSH key to the ssh-agent. If you chose not to add a passphrase to your key, run the command without the-K
option.If you don't have Apple's standard version installed, you may receive an error. For more information on resolving this error, see "Error: ssh-add: illegal option -- K."
-
Add the SSH key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account."
If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.
-
Ensure the ssh-agent is running. You can use the "Auto-launching the ssh-agent" instructions in "Working with SSH key passphrases", or start it manually:
# start the ssh-agent in the background $ eval "$(ssh-agent -s)" > Agent pid 59566
-
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519
-
Add the SSH key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account."
-
Start the ssh-agent in the background.
$ eval "$(ssh-agent -s)" > Agent pid 59566
Depending on your environment, you may need to use a different command. For example, you may need to use root access by running
sudo -s -H
before starting the ssh-agent, or you may need to useexec ssh-agent bash
orexec ssh-agent zsh
to run the ssh-agent. -
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519
-
Add the SSH key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account."
If you are using macOS or Linux, you may need to update your SSH client or install a new SSH client prior to generating a new SSH key. For more information, see "Error: Unknown key type."
-
Insert your hardware security key into your computer.
-
Open TerminalTerminalGit Bash.
-
Paste the text below, substituting in the email address for your account on GitHub.
$ ssh-keygen -t ed25519-sk -C "your_email@example.com"
Note: If the command fails and you receive the error
invalid format
orfeature not supported,
you may be using a hardware security key that does not support the Ed25519 algorithm. Enter the following command instead.$ ssh-keygen -t ecdsa-sk -C "your_email@example.com"
-
When you are prompted, touch the button on your hardware security key.
-
When you are prompted to "Enter a file in which to save the key," press Enter to accept the default file location.
> Enter a file in which to save the key (/Users/you/.ssh/id_ed25519_sk): [Press enter]
> Enter a file in which to save the key (/c/Users/you/.ssh/id_ed25519_sk):[Press enter]
> Enter a file in which to save the key (/home/you/.ssh/id_ed25519_sk): [Press enter]
-
When you are prompted to type a passphrase, press Enter.
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
-
Add the SSH key to your account on GitHub. For more information, see "Adding a new SSH key to your GitHub account."
Did this doc help you?Privacy policy
All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.
Make a contribution- © 2021 GitHub, Inc.
- Terms
- Privacy
- Security
- Status
- Help
- Contact GitHub
- Pricing
- Developer API
- Training
- About