In order for you to be able to connect to your Github account or to SSH into applications you are going to be required to generate an SH1 key.
Here is how you generate SSH key pairs in MacOS.
Open up your favorite terminal or the default MacOS terminal: Applications
> Utilities
> Terminal
You’ll first want to check and see if you already have an SSH key created. You can check by running this in your terminal:
ls -al ~/.ssh
If you see files named id_rsa
and id_rsa.pub
or like what’s in the image below
This means a key has already been created in it’s default location (Yay, less work!), so you can use that key (see how use below) or you can generate a new one.
If you don’t see those files, then you’ll want to generate a new key. For something such as CPanel, start in the next section.
Note:
If all you need to do is add your key to GitHub then Scroll down for instructions.
For cPanel you’ll want to run this in your terminal and the press the return
key:
ssh-keygen -t rsa
You will now be prompted to tell the the prompt where you want your key be placed/located. If you leave it blank and press return
key, it will place the key in it’s default location (Recommended). If you decide to place the key in a different location, just remember to make a note of where you place your key. If you leave it blank and press return
it will place your key in:
/home/user/.ssh/id_rsa
Now you will be prompted to enter a password to access the key (Note: The password is not required, you can leave blank and press return
). Also, note that you will not see the characters when you are typing the password. This is for your own safety.
After you press return
, your SSH key will have been created and located in:
/home/user/.ssh/id_rsa.pub
Depending on what you are using the passkey for you can upload/use by going into something like C Panel or Github by using this command:
ssh-add /home/user/.ssh/id_rsa
For GitHub you’ll want to open your terminal app and run the following command (but with your Github account email address):
ssh-keygen -t rsa -b 4096 -C "your_github_email@example.com"
This creates a new ssh key with your_github_email
address.
Now you’ll be asked where you want to save your key (I recommend that you leave this blank to have it placed in your default location):
(/Users/yourUsername/.ssh/id_rsa): [Press return]
Next, a prompt will ask for a passphrase/password. Again, this is optional and you won’t be able to see the password you type.
Enter passphrase (empty for no passphrase): typePasswordHere
Enter same passphrase again: typeSamePasswordAgain
Note:
Much of the remaining two sections were taken directly from the GitHub help pages. I'm lazy and they explain things better, but I wanted to combine their work with the stuff I added above for ease-of-access.
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.
eval "$(ssh-agent -s)"
> Agent pid 59566
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.
Open using VSCode:
code ~/.ssh/config
Update the ~/.ssh/config
:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
ssh-add -K ~/.ssh/id_rsa
Copy the SSH key to your clipboard 1.
If your SSH 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_rsa.pub # Copies the contents of the id_rsa.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.
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”.
And you should now be good to go. I hope you found this article useful, if so, please leave a comment or Disqus Response below so that I know how things things went for you.