Generate an SSH key on macOS

Generate an SSH key on macOS (Sierra 10.12.3)

Generating an SSH key with macOS is relatively straight forward using the variety of Terminal applications available for the OS.

I have written this post as part of a prereq documentation for building on Oracle Cloud Services, but the step apply regardless of your objective. There are plenty of places documenting these steps for both Windows and Linux

Open the Terminal application

To open the a terminal application you can either find it in the Dock, but if it’s not there, follow these steps:

  1. Click the Applications icon in the dock
  2. Search for and click the Utilities folder
  3. Launch the Terminal application
SSH terminal image

Terminal Application on macOS

Generate the ssh key

Once your terminal window is open, to generate the ssh key, follow these steps:

1. Change to the ~/.ssh directory. This will ensure that the ssh keys will be saved in your .ssh directory.
Danny: > cd .ssh
2. Execute ssh-keygen -t rsa to start the process
Danny: > ssh-keygen -t rsa
Generating public/private rsa key pair.
3. Provide a name the key files generated. In this example I have called it "cloudKey"
Enter file in which to save the key (/Users/username/.ssh/id_rsa): cloudKey
4. Enter a passphrase. Please remember this passphrase, you will need it later.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in cloudKey.
Your public key has been saved in cloudKey.pub.
The key fingerprint is:
SHA256:xxxxxxxxxxXXXXXXXXXXxxxxxxxxxxXXXXXXXXXXxxx username@computername
The key's randomart image is:
+---[RSA 2048]----+
|4einc |
|hhhh |
|+.+. . |
|*oo= . o |
|+B= o E S |
|B=cc o |
|=+=.. . |
|ooo-= .o |
|grdB..ot |
+----[SHA256]-----+

Your private key is saved as “cloudKey” and your public key is “cloudKey.pub” both in the ~/.ssh directory. Next steps will be use these files to enable secure remote access without the need to use passwords.

Enjoy!


Originally published at My Experiences with Oracle Technology.