How can I generate SSH keys on Mac OS X? Print

  • 381

You will use the Terminal application on Mac OS X to generate an SSH key which will allow you to login to your server without manually entering a password, while giving you a higher level of security that comes from using key pairs.

Mac OS X Terminal

The terminal provides you with a text-based command line interface to the Unix shell component of Mac OS X. In order to get started with it, follow these steps:

  1. Open your Finder and select “Utilities” from the “Go” menu bar.
  2. Find the Terminal application in the list of utilities.
  3. Double-click the Terminal application to start it.

Once you’ve launched the terminal, you’ll see a screen with a prompt that contains your username as well as the name of your machine.

Generating an SSH key

An SSH key consists of a pair of files. One is the private key, which you should never give to anyone. The other is the public key. You will need a public key to log into cloud servers you provision. When you generate your keys, you will use ssh-keygen to store the keys in a safe location so you can bypass the login prompt when connecting to your server.

To generate SSH keys in Mac OS X, follow these steps:

  1. Enter the following command in the Terminal window.
    ssh-keygen -t rsa
    This starts the key generation process. When you execute this command, the ssh-keygen utility prompts you to indicate where to store the key.
  2. Press the ENTER key to accept the default location. The ssh-keygen utility prompts you for a passphrase.
  3. Type in a passphrase. You can also hit the ENTER key to accept the default (no passphrase). However, this is not recommended.
    Please note that you will need to enter the passphrase a second time to continue.

After you confirm the passphrase, the system generates the key pair.

Your identification has been saved in /Users/user/.ssh/id_rsa.
Your public key has been saved in /Users/user/.ssh/
The key fingerprint is:
ae:89:72:0b:85:da:5a:f4:7c:1f:c2:43:fd:c6:44:38 user@mymac.local
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|         .       |
|        E .      |
|   .   . o       |
|  o . . S .      |
| + + o . +       |
|. + o = o +      |
| o...o * o       |
|.  oo.o .        |

Your private key is saved to the id_rsa file in the .ssh directory and is used to verify the public key you use belongs to the same cloud server. It's important to never share your private key with anyone, it is equivalent of your password!

Your public key is saved to the file and it is the key you'll upload to our cloud service. You can save this key to the clipboard by running this:

pbcopy < ~/.ssh/

Was this answer helpful?

« Back