Connecting to github with SSH in macOS Monterey
Checking for existing SSH Keys1 2
1 | $ ls -al ~/.ssh |
If you don't already have an SSH key, generating a new SSH key and adding it to the ssh-agent
1 | cd ~/ |
Check:
1 | ls -al |
Adding your SSH key to the ssh-agent
Start the ssh-agent in the background:
1 | eval "$(ssh-agent -s)" |
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:
1 | open ~/.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.
Note: If you chose not to add a passphrase to your key, you should omit the UseKeychain line.
1 | Host * |
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.
Note: The -K option is Apple's standard version of ssh-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."
In MacOS Monterey (12.0), the -K and -A flags are deprecated and have been replaced by the --apple-use-keychain and --apple-load-keychain flags, respectively.
1 | ssh-add -K ~/.ssh/id_ed25519 |
Adding a new SSH key to your GitHub account
Copy the SSH public key to your clipboard:
1 | pbcopy < ~/.ssh/id_ed25519.pub |
In the upper-right corner of any page, click your profile photo, then click Settings.
In the user settings sidebar, click SSH and GPG keys. Click New SSH key or Add SSH key. Paste your key into the "Key" field. Click Add SSH key. If prompted, confirm your GitHub password.