Create, Access and Use SSH Keys with macOS

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.

cd .ssh

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.

Freddie Freddie 4 years, 11 months ago 0
Login to Comment
No comments have been posted yet, be the first one to comment.
How to Install Deno on macOS
How to Install Deno on macOS
Deno is a simple, modern and secure runtime for JavaScript and TypeScript, by the creator of Node.js himself, Ryan Dahl. Deno uses the Chrome v8 engine and is built with Rust. The project just reach version 1.0 and got many people in the JavaScript community interested. In this tutori...
How to Install Redis on MacOS with Curl
How to Install Redis on MacOS with Curl
Redis a fantastic free and open-source in-memory key-value database that can be used to cache your web app to improve both performance and resource consumption. Today I will go over how we can install and run Redis locally on your Mac. Installing Redis for macOS is not as straight for...
Fix PostgreSQL error: Stale postmaster.pid file on macOS
Fix PostgreSQL error: Stale postmaster.pid file on macOS
Sometimes when you mac shuts down unexpectedly while running a PostgreSQL database it can result in the following error: Stale postmaster.pid file. The data directory contains an old postmaster.pid file. FATAL: lock file “postmaster.pid” already exists Fix PostgreSQL error: Stale pos...