Set up SSH on macOS

Niño Villaflor
Mac O’Clock
Published in
2 min readFeb 14, 2020
Photo by Markus Spiske on Unsplash
  1. From the terminal, enter ssh-keygen at the command line.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ninovillaflor/.ssh/id_rsa):

2. Press the Enter or Return key to accept the default location.

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ninovillaflor/.ssh/id_rsa): /Users/ninovillaflor/.ssh/my-new-ssh-key

It is recommended that you keep the default key name unless you have a reason to change it.

To create a key with a name or path other than the default, specify the full path to the key. For example, to create a key called my-new-ssh-key, enter a path like the one shown at the prompt:

3. Enter and re-enter a passphrase when prompted.
The command creates your default identity with its public and private keys. The whole interaction will look similar to the following:

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ninovillaflor/.ssh/id_rsa):
Created directory '/Users/ninovillaflor/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/ninovillaflor/.ssh/id_rsa.
Your public key has been saved in /Users/ninovillaflor/.ssh/id_rsa.pub.
The key fingerprint is:
4c:80:61:2c:00:3f:9d:dc:08:41:2e:c0:cf:b9:17:69 ninovillaflor@myhost.local
The key's randomart image is:
+--[ RSA 2048]----+
|*o+ooo. |
|.+.=o+ . |
|. *.* o . |
| . = E o |
| o . S |
| . . |
| . |
| |
| |
+-----------------+

4. List the contents of ~/.ssh to view the key files.

$ ls ~/.ssh
id_rsa id_rsa.pub

On macOS, the following command copies the output to the clipboard:

$ pbcopy < ~/.ssh/id_rsa.pub

On Linux

$ cat ~/.ssh/id_rsa.pub

Thanks for reading and following along.
I hope that this blog will give value to you at some point. Please feel free to reach out if you have any questions.

--

--