This guides is for macOS 12 or higher. My Mac uses macOS Ventura 13.0.01.
Step 1: Creating a new SSH Key
Go to the
$ cd ~/.ssh
Made new key:
$ ssh-keygen -t ed25519 -C "email@example.com"
- Don't just copy, put in your email. I also added a password.
- Also, don't copy the
$, just the
ssh-keygen -t ed25519 -C "firstname.lastname@example.org"part. But with your email.
You can name your key. For this example, we call it
Step 2: Adding SSH Key to ssh-agent.
$ eval "$(ssh-agent -s)"
Step 3: Adding Key Info to config
.ssh/config in your favourite text editor. If you want to stay at the command line, use nano.
Add the following:
Host *.github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_github_test
Step 4: Adding the Key to ssh-agent
Adding private key to ssh-agent
$ ssh-add --apple-use-keychain ~/.ssh/id_github_test
This add the new key to the Apple Keychain.
If you used a passphrase when you created the key, you will be asked for it now.
Enter passphrase for /Users/georg/.ssh/id_github_test:
Identity added: /Users/georg/.ssh/id_github_test (email@example.com)
Step 5: Adding Public Key to github.com
- Log into Github
- Profile > Settings > SSH and GPG Keys
- Click 'New SSH Key'
Copy and paster your public key, in this example case, id_github_test.pub.
The tutorial on Github suggest to copy the public key using a command:
$ pbcopy < ~/.ssh/id_github_test.pub
pbcopy - for paste board copy is the terminal interface to the macOS' Copy & Paste.
pbcopy < read the content of a file into the copy memory. After running
pbcopy you can press Command-V to paste the text.
- Paste the copied SSH Public Key.
Step 5.1: Two-Factor Authentication at GitHub.com
I setup Two-Factor Authentication at GitHub.com, I had to confirm the addition of a new key via my mobile GitHub App. Your mileage might vary.
Step 6: Testing the connection
$ ssh -T firstname.lastname@example.org Hi trembl! You've successfully authenticated, but GitHub does not provide shell access.
Ok, great! It worked!
Now you can clone, add, commit, push and pull!