Create, Access and Use SSH Keys with macOS
SSH or "Secure Shell" is a network protocol for operating networked services securely. It is typically used for remote command-line authentication and command execution.
In this tutorial I will show you how you can create, access and use your SSH key for macOS.
1. Open Terminal and Navigate to .ssh
Open up your terminal and navigate to your ssh folder.
2. Create your SSH key
We can create an SSH key with the ssh-keygen command in the terminal.
ssh-keygen -t rsa
3. Name your SSH key
You will also be asked to choose a name for your SSH key if you already have previously created keys.
Enter file in which to save the key (/Users/username/.ssh/id_rsa): your-key-name
4. Choose a password for your SSH key
When you have named your SSH key you will be asked to enter a password for the SSH key, twice to make sure that the password match.
Enter passphrase (empty for no passphrase): Enter same passphrase again:
5. Verify that your SSH key has been created
If your SSH key was created sucessfully your SHA256 fingerprint along with the randomart should be desplayed in the terminal.
Your identification has been saved in your-key-name. Your public key has been saved in your-key-name.pub. The key fingerprint is: SHA256:y31xp0ynRklGKx5i/Lv9bcD7VDfRaboliEk2YzXlhGY username@computer The key's randomart image is: +---[RSA 2048]----+ | o=E=.+ + | | . .*. . | | O=o= O ..| | S o= B .| | .o. = +o| | . + .o + B| | + o .+ Bo| | . .*Lo| | .o.o| +----[SHA256]-----+
The randomart might look funky or down right cryptic, but it actually meant to be an easier way for humans to validate keys. Rather than comparing a long hexadcimal string the randomart is both faster and easier to compare. However, if you are creating an SSH key for your server or a service, you will rarely use them.
6. Access & copy your SSH key
Now that we have created our SSH key we can use the ls command and see that the public and private key is located in our ssh folder.
ls your-key-name your-key-name.pub
In order to authenticate yourself with third-party services that uses SSH authentication they need to be aware of your public key. We can access and copy the public key by using the pbcopy command.
pbcopy < ~/.ssh/your-key-name.pub
That's how you create and access an SSH key on macOS. How you use it will vary for each service or use case. Most services should provide documentation to get you started. If you for example want configure SSH for Github, they provide their own documentation for it.