How to generate a SSH key (MacOS)


This tutorial will learn you how you can generate a SSH key This way you can easily add your SSH key to your server. We will show how this can be done on MacOS.

Generating SSH key (MacOS)

Open the terminal and enter the following command.


It will prompt you if you would like to change the password. You can change this or leave it as it is. Default folder is /Users/your_username/.ssh/ After that you will be prompted to enter a passphrase. This is a password you'll need to enter when connecting to a server via your SSH key. Enter a passphrase if you want one, otherwise just leave it emtpy and press enter. Now you need to verify your passphrase. Enter your passphrase if you had one, otherwise just leave it empty again and press enter. You will see that you ssh key has been generated and where it has been stored. Output should look something like this.

Your identification has been saved in testing
Your public key has been saved in
The key fingerprint is:
SHA256:kvkQ1VFszcGDtvQNvY0ZU3oeA4MIbOBx3J2maBgcXog <username>@localhost
The key's randomart image is:
+---[RSA 3072]----+
|    o+*++.+++B.+.|
|   Eo++= o.=* @..|
|     o= . o+ o.@+|
|     . * .  . ++=|
|      * S       .|
|       +         |
|        .        |
|                 |
|                 |

You can copy your key to your server by using the following command.

ssh-copy-id <username>@<server-ip>

You will be prompted to enter your users password from the server we are copying the key to. Enter the password and press enter. Your key has now been copied to your server. Output should look something like this.

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh '<username>@XXX.XXX.XXX.XXX'"
and check to make sure that only the key(s) you wanted were added.