How to create an SSH key

Applies to:
Professional Hosting
Business Hosting
WordPress Hosting

Difficulty:
Easy

Time Needed:
5 minutes

Introduction

This is a quick step-by-step walkthrough for creating a private SSH key, which can be used to establish a secure connection when connecting to a server over SSH.


Article Contents


Creating an SSH key on Windows


Step 1

Open Command Prompt

Firstly you need to open the Command Prompt application.

To do this, use the search field next to the 'Start' button (or on older versions click the 'Start' button, and choose 'Run'). Then enter the following command.

cmd

Then hit the 'Enter' key.

Open Command Prompt

Step 2

Check for existing SSH keys

Before you create an SSH key, its good practise to check if you already have any SSH keys setup on your machine. To do this, simply enter the following command.

cd %userprofile%/.ssh

If you receive the message 'No such file or directory', then you have no SSH keys setup on your machine. If this is the case, please skip the next step and go directly to step 4.

Check for existing SSH keys

Step 3

Back up existing SSH keys

If you have existing SSH keys, its good practise to back them up before generating a new one.

Firstly, to create a new folder where your back up will be stored, enter the following command.

mkdir key_backup

The copy your existing SSH keys to your backup folder with the following command.

copy id_rsa* key_backup
Back up existing SSH keys

Step 4

Generate a new SSH key

Now you are ready to generate a new SSH key. Simply enter the following command to generate your key.

ssh-keygen -t rsa -C "johnsmith@yourdomain.com"

You will then be prompted to choose a location to save your new key. Simply hit the 'Enter' button to accept the location and continue.

Finally, enter and re-enter a passphrase when prompted, and your new SSH key will be generated.

Generate a new SSH key

Creating an SSH key on Mac OS X


Step 1

Open Terminal

Firstly you need to open the Terminal application.

Click the 'Finder' icon on your dock, then choose Go > Go to folder.... The enter the following command path.

/Applications/Utilities/Terminal

The double click the Terminal icon to open the application.

Open Terminal

Step 2

Check for existing SSH keys

Before you create an SSH key, its good practise to check if you already have any SSH keys setup on your machine. To do this, simply enter the following command.

cd ~/.ssh

If you receive the message 'No such file or directory', then you have no SSH keys setup on your machine. If this is the case, please skip the next step and go directly to step 4.

Check for existing SSH keys

Step 3

Back up existing SSH keys

If you have existing SSH keys, its good practise to back them up before generating a new one.

Firstly, to create a new folder where your back up will be stored, enter the following command.

mkdir key_backup

The copy your existing SSH keys to your backup folder with the following command.

cp id_rsa* key_backup
Back up existing SSH keys

Step 4

Generate a new SSH key

Now you are ready to generate a new SSH key. Simply enter the following command to generate your key.

ssh-keygen -t rsa -C "johnsmith@yourdomain.com"

You will then be prompted to choose a location to save your new key. Simply hit the Enter button to accept the location and continue.

Finally, enter and re-enter a passphrase when prompted, and your new SSH key will be generated.

Generate a new SSH key

Was this helpful?

   
0 people found this article helpful
34SP.com Rated 9.2 out of 10 based on 172 reviews Trust Pilot