Creating an SSH Key on MacOS
Introduction
This tutorial will teach you how to generate an SSH key, allowing you to effortlessly add it to your server. We will demonstrate this process on MacOS.
Generating SSH key (MacOS)
Launch the terminal and input the following command.
ssh-keygen
Upon execution, it will inquire whether you wish to change the password. You can either modify it or retain the current one. The default folder is /Users/your_username/.ssh/. Following this, you will be asked to input a passphrase, serving as the password required when connecting to a server via your SSH key. Provide a passphrase if desired; otherwise, leave it empty and press enter. Verification of the passphrase is the next step. Input the passphrase if you had one, otherwise, leave it empty again and press enter. You will receive a confirmation that your SSH key has been generated, along with the storage location. The output should resemble something like this.
Your identification has been saved in testing
Your public key has been saved in testing.pub
The key fingerprint is:
SHA256:kvkQ1VFszcGDtvQNvY0ZU3oeA4MIbOBx3J2maBgcXog @localhost
The key's randomart image is:
+---[RSA 3072]----+
| o+*++.+++B.+.|
| Eo++= o.=* @..|
| o= . o+ o.@+|
| . * . . ++=|
| * S .|
| + |
| . |
| |
| |
+----[SHA256]-----+
Transfer your key to the server using the specified command.
ssh-copy-id <username>@<server-ip>
You will receive a prompt to enter your user’s password on the server to which we are copying the key. Input the password and press enter. Your key is now successfully copied to the server. The output should resemble something like this.
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '@XXX.XXX.XXX.XXX'"
and check to make sure that only the key(s) you wanted were added.