How to generate SSH key on Mac, Step by Step Guide

Easily generate an SSH key (contains the public key and private key) by using the MacOS Terminal application, let`s do it!

Overview

When we wish to connect the remote server, we most likely need the SSH  to connect, in this tutorial, I will show you how to generate the SSH keys for later consume on Mac OS X system.

Terminal Tools

We will use Mac built-in app called “Terminal”, it is a very common command tool on Mac. Two ways open it:

  • Method one: Command–Space bar: open the Spotlight Search, search “Terminal”, then press enter key to open it.
  • Method two:
    1. In Finder, choose Utilities from the Go menu.
    2. Find the Terminal application in the Utilities window.
    3. Double-click the Terminal application.
Screenshot of Mac terminal
Screenshot of Mac Terminal

Generate the SSH keys

InTerminal, enter the command:

ssh-keygen -t rsa

It will ask us where to store the keys. Press Enter again, Let`s accept the default directory.

It will prompt for the passphrase, set a password, Press Enter, it will ask again to confirm your password, input the same password Press Enter.

The keys were generated in your default location. in my case, it would be:

/Users/kasonz/.ssh/

Below is the full example.

DLCM50937148A:~ kasonz$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kasonz/.ssh/id_rsa):   
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/kasonz/.ssh/id_rsa.
Your public key has been saved in /Users/kasonz/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:SwXe6SX1cyyINjCLG2f+OAIaCAdG8xoNtApNZk+5nv4 kasonz@DLCM50937148A
The key's randomart image is:
+---[RSA 2048]----+
|+*+ ..  +   .    |
|.**o.  o * + o . |
|oooo..o = O o + o|
|+oo .  * + +   + |
|o...... S .      |
|   oo. . +       |
|  ..  . + .      |
|    .  . .       |
|     .E          |
+----[SHA256]-----+

An important note: Never share your private key to anyone.

In this case, the private key is id_rsa, the public key is id_rsa.pub

You may use the keys to connecting remote server or other things.

Share:

Leave a Reply

Your email address will not be published. Required fields are marked *