How to Create and Use SSH Keys with macOS Platform

Learn how you can create, access, and use your SSH key for macOS Platforms.

Picture of Nsikak Imoh, author of Macsika Blog
An image with the text How to Create and Use SSH Keys with macOS Platform
An image with the text How to Create and Use SSH Keys with macOS Platform

Table of Content

SSH (Secure Shell) is a network protocol for securely operating devices in a network.

SSH is mostly used to handle command-line authentication remotely and execute commands.

In this post, you will learn how you can create, access, and use your SSH key for macOS Platforms.

What Is SSH?

SSH, or Secure Shell Protocol, is a remote administration protocol that allows users to access, control, and modify their remote servers over the internet.

SSH service was created as a secure replacement for the unencrypted Telnet.

It uses cryptographic techniques to ensure that all communication to and from the remote server happens in an encrypted manner.

It provides a mechanism for authenticating a remote user, transferring inputs from the client to the host, and relaying the output back to the client.

How Does SSH Work for macOS?

The SSH command for macOS consists of 3 distinct parts:

ssh {user}@{host}
Highlighted code sample.

The SSH key command instructs your system that you want to open an encrypted Secure Shell Connection.

{user} represents the account you want to access.

For example, you may want to access the root user, which is basically synonymous with the system administrator with complete rights to modify anything on the system.

{host} refers to the computer you want to access. This can be an IP Address (e.g. 244.235.23.19) or a domain name (e.g. www.xyzdomain.com).

When you hit enter, you will be prompted to enter the password for the requested account.

When you type it in, nothing will appear on the screen, but your password is, in fact, being transmitted.

Once you—re done typing, hit enter once again.

If your password is correct, you will be greeted with a remote terminal window.

How to Create an SSH Key on macOS

Using SSH for Mac is very simple.

Head over to your terminal program and then follow the instructions below:

1. Start up the terminal and navigate to .ssh

Open up your terminal and navigate to your ssh folder.

cd .ssh
Highlighted code sample.

2. Create an SSH key

We can create an SSH key with the ssh-keygen command in the terminal.

ssh-keygen -t rsa

Highlighted code sample.

3. Give the SSH key a name

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

Highlighted code sample.

4. Select a password for the 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:

Highlighted code sample.

5. Verify that your SSH key has been created

If your SSH key was created successfully, your SHA256 fingerprint along with the random art should be displayed 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]-----+

Highlighted code sample.

The random art might look funky or cryptic, but it is actually meant to be an easier way for humans to validate keys.

Rather than comparing a long hexadecimal string, the random art is both faster and easier to compare.

However, if you are creating an SSH key for your server or service, you will rarely use them.

How to Access and Use an SSH Key on macOS

Now that we have created our SSH key, we can use the ls command and see that the public and the private key are located in our ssh folder.

ls

your-key-name
your-key-name.pub

Highlighted code sample.

To authenticate yourself with third-party services that use 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

Highlighted code sample.

Wrap Off

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 to configure SSH for GitHub, they provide their own documentation for it.

If you learned from this tutorial, or it helped you in any way, please consider sharing and subscribing to our newsletter.

Please share this post and for more insightful posts on business, technology, engineering, history, and marketing, subscribe to our newsletter.

Connect with me.

Need an engineer on your team to grease an idea, build a great product, grow a business or just sip tea and share a laugh?