The Guide to Generating and Uploading SSH Keys (2024)

An SSH key is a form of authentication in the SSH protocol. It is similar to a password, but allows for authentication without entering in a password or any manual input. SSH keys generally speaking are more secure, and convenient than password authentication.

Command Line

If you currently have access to SSH on your server, you can generate SSH keys on the command line using thessh-keygenutility which is installed by default on our servers. Run it on your server with no options, or arguments to generate a 2048-bit RSA key pair (which is plenty secure).

$ ssh-keygen

You will be prompted to select a file for the key pair. The default directory for SSH keys is~/.sshwith the private key namedid_rsaand the public key namedid_rsa.pub. By using the default file names, the SSH client will be able to automatically locate the keys during authentication so it is strongly recommended to not change them. You can use the default by pressing the Enter key.

Generating public/private rsa key pair. Enter file in which to save the key (/home/USER/.ssh/id_rsa):

If /home/USER/.ssh/id_rsa or a key of the name you chose already exists, you will be prompted to overwrite the keys. If you do overwrite the existing keys, you will not be able to use them to authenticate anymore.

After you have selected the file for the key pair, you be will be prompted to enter a passphrase to encrypt private key file. Encrypting the private key with a passphrase isoptional, but it will improve security the keys. If you enter a passphrase you will have to provide each it time you use the key. You can press the Enter key to not use a passphrase; we strongly recommend the use of a passphrase with SSH keys.

Created directory '/home/USER/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: 

A public and private key will now be generated.

Your identification has been saved in /home/USER/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:boo2WmwU41qy/IxmJCgDjjsg7xvvcXmHhHa7BKhoCPY root@server.domain.tld The key's randomart image is: +---[RSA 2048]----+ | | |o | |+. . . . | |=o. o . + o | |O+.. = .S= o | |X=oEo o.o = + | |*+= . ooo o | |oO+. ..o . | |*+.+. . | +----[SHA256]-----+

WHM

You can generate SSH key pairs forrootinWHM >> Home Security Center >> Manage root's SSH Keys.

The Guide to Generating and Uploading SSH Keys (1)

ClickGenerate a New Keyto get started.

The Guide to Generating and Uploading SSH Keys (2)

There are several fields on this page:Key Name,Key Password,Key Type, andKey Size.

The Guide to Generating and Uploading SSH Keys (3)

The defaultKey Nameisid_rsa. Keys are generated in/root/.ssh/so the default key name would create a private key in/root/.ssh/id_rsa, and a public key in/root/.ssh/id_rsa.pub. Using the default name will allow SSH clients to automatically locate the keys so it is strongly recommend you use the default name (simply leave the field blank or fill it withid_rsa).

The Guide to Generating and Uploading SSH Keys (4)

TheKey Passwordencrypts the private key file using a password to add an extra layer of security. The password must be provided each time the key is used for authentication to decrypt the private key. ThePassword Strengthfield indicates how strong your password is. 0 indicates a very weak password, and 100 indicates a very strong password. ClickPassword Generatorto have a strong password generated for you.

Key TypeandKey Sizeare RSA and 2048 by default, and are secure enough for most purposes so these can be left alone.

The Guide to Generating and Uploading SSH Keys (5)

ClickGenerate Keyto generate the SSH key pair. WHM will then display the location of the key.

The Guide to Generating and Uploading SSH Keys (6)PuTTY

PuTTY is an open Windows SSH client. You will need to have the PuTTYgen utility installed to generate an SSH key pair. PuTTYgen is included in Windows installer on theDownload PuTTYsite, but you can download it separately if you installed PuTTY without its extra utilities. SeeConnect using PuTTY to a Linux Serverto learn more about PuTTY.

Open PuTTYgen.

The Guide to Generating and Uploading SSH Keys (7)

TheParametersat the bottom can be adjusted to affect how secure the key is, but the default options are plenty secure for most purposes.

The Guide to Generating and Uploading SSH Keys (8)

If you're satisfied with the parameters, clickGenerateinActionsto generate the key pair.

The Guide to Generating and Uploading SSH Keys (9)

You may be asked to "generate some randomness by moving the mouse over the blank area" to generate the key. The randomness is used to generate your keys securely, and make it difficult to reproduce them.

The Guide to Generating and Uploading SSH Keys (10)

Once the key is generated, you will see the public key in PuTTYgen.

The Guide to Generating and Uploading SSH Keys (11)

TheKey passphrasefield sets a password used to decrypt the private the key. This field is optional, and the private key will not be encrypted if it is omitted.Using a passphrase increases the security of your SSH keys, and we strongly recommend setting one.

Be sure to save both the public and private keys on your local machine so they can be used by PuTTY for authentication in the future by clicking theSave public keyandSave private keybuttons.

The Guide to Generating and Uploading SSH Keys (12)

If you don't use a passphrase, it will prompt you to confirm before allowing you to save the private key. The private key will be saved as a.ppkfile. The public key isn't given an extension by default, but.pubis a common extension for public key files. It can be saved as a.txtfile as well as the public key file only stores the public key in plain text.

Command Line

If you currently have access to SSH on your server, you can upload the key over the command line.

Retrieve the contents of the public key. If the key was created in the default location, this can be done by outputting the contents of~/.ssh/id_rsa.pub.

$ cat ~/.ssh/id_rsa.pub

The output will look similar to the following:

ssh-rsa AAAAB9NzaC1yc2EAAAADAQABAAABAQDBej/3XAjhwTwWXsOJmDdKTLtjnpGXsHOAEIYC12qQ r51+AVJPNsqcDlFdv+Lr/XufQDCh2gXz+ieA/LJNb5luxReaVVbKtvAONZgv8uLD1J8kzRXike3h9L53 oIo2j8Lt4fuzB8yAWkwBelurn4OWfk0K6gFXN86RgprKSPN3GbwG6MINAor7NwCHzJhVK9u6Jpw9EPJv Dl4co+N9L+CGgudvY7iBNzIofE9MP68lXcql4bMWz3+2H0FWKHZ1rSJz56KjoCKBPWTqdFq5o1AIcauc ECgiTaEGcSNk4+T0A8BuAOd3a4O9Gr6y8C4Sn4ghYajJVWsszP2B1tTGAc3L

Open the (and create if it doesn't exist)~/.ssh/authorized_keysfile using a text editor such asnano,pico, orvim.

$ nano ~/.ssh/authorized_keys

If you had to create the ~/.ssh/ directory, or the authorized_keys file, you need to verify the permissions are correct, or you won't be able to login.

$ chmod 700 ~/.shh
$ chmod 600 ~/.ssh/authorized_keys

Paste the public key at the bottom of the file, and then save and close the file.

Alternatively, you can append the public key to~/.ssh/authorized_keyswith a single command.

You can use thecatcommand if the public key is stored in a file.

$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

If the public key is not stored as a file on the server, you can use theechocommand.

$ echo "ssh-rsa AAAAB9N...sszP2B1tTGAc3L" >> ~/.ssh/authorized_keys

Be sure to includethe entire public key in quotes afterecho.

Once the public key is added to theauthorized_keysfile, you should be able to login using your SSH keys.

WHM

You can import an existing SSH key forrootinWHM >> Home Security Center >> Manage root's SSH Keys.

The Guide to Generating and Uploading SSH Keys (13)

ClickImport Key.

The Guide to Generating and Uploading SSH Keys (14)

The next page has a few fields to fill in.

The Guide to Generating and Uploading SSH Keys (15)

You need to name the SSH key in theChoose a name for this keyfield. The default key name isid_rsa.Using the default name will allow SSH clients to automatically locate the keys so it is strongly recommend you use the default name (simply leave the field blank or fill it withid_rsa).

The Guide to Generating and Uploading SSH Keys (16)

If you are importing a PPK (PuTTYgen key) file, enter its password (if applicable) in thePrivate key passphrasetext box.

The Guide to Generating and Uploading SSH Keys (17)

Paste the publickey into the appropriate box, but donotpaste the private key into the box; private keys should always remain on the servers that generated them.

The Guide to Generating and Uploading SSH Keys (18)

ClickImport.

The Guide to Generating and Uploading SSH Keys (19)

WHM will display the name of the keys imported, from there you will need to authorize the SSH key you just imported by clicking "Manage Authorization" and "Authorize". Once you have authorized the key you should now be able to authenticate over SSH using the key.

The default name for SSH key pairs isid_rsa, and that name will allow an SSH client to locate the key automatically. When an SSH key pair doesn't use the default name, you will need to specify the name of key used.

$ ssh user@server.domain.tld -i /path/to/ssh/key
The Guide to Generating and Uploading SSH Keys (2024)

FAQs

How to upload SSH keys to server? ›

How to add new SSH key to a cloud server
  1. Connect to the server using your current key. ssh cloud-user@1.2.3.4 -i /current_private_ssh_key.
  2. Add a public key to the "authorized_keys" file. You can add a public key to the "authorized_keys" file using "nano" text editor (or any text editor of your choice): ...
  3. Verify new key.

How does SSH key generation work? ›

The ssh-keygen command is a component of most SSH implementations used to generate a public key pair for use when authenticating with a remote server. In the typical use case, users generate a new public key and then copy their public key to the server using SSH and their login credentials for the remote server.

How to do SSH keys? ›

The SSH public key authentication has four steps:
  1. Generate a private and public key, known as the key pair. ...
  2. Add the corresponding public key to the server.
  3. The server stores and marks the public key as approved.
  4. The server allows access to anyone who proves the ownership of the corresponding private key.
Aug 10, 2021

How to generate SSH key online? ›

Generating a new SSH key
  1. Open TerminalTerminalGit Bash.
  2. Paste the text below, replacing the email used in the example with your GitHub email address. ssh-keygen -t ed25519 -C "your_email@example.com" ...
  3. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."

What type of SSH key to generate? ›

RSA is the default key type when generated using the ssh-keygen command. To generate SSH keys with given algorithm type, supply -t flag to ssh-keygen command. Below is an example of generating ed25519 key: $ ssh-keygen -t ed25519 -C "unique name to identify this key."

How to generate SSH key and copy to server? ›

Copy the ssh key into remote servers
  1. Open a terminal on your local computer.
  2. Generate an SSH key pair if you haven't already done so by running the command: ssh-keygen . ...
  3. Once the key pair is generated, run the command: ssh-copy-id user@remote_server . ...
  4. You'll be prompted to enter the password for the remote user account.
Apr 8, 2023

Where should SSH keys be stored? ›

The default directory for SSH keys is ~/. ssh with the private key named id_rsa and the public key named id_rsa.

Where is the SSH authorized key file? ›

Location of the Authorized Keys File

With OpenSSH, the authorized keys are by default configured in . ssh/authorized_keys in the user's home directory. Many OpenSSH versions also look for ssh/authorized_keys2 . Some organizations use custom OpenSSH builds with different default paths.

How do I know if my SSH key is generated? ›

Checking for existing SSH keys
  1. Open TerminalTerminalGit Bash.
  2. Enter ls -al ~/. ssh to see if existing SSH keys are present. ...
  3. Check the directory listing to see if you already have a public SSH key. ...
  4. Either generate a new SSH key or upload an existing key.

How to generate SSH key terminal? ›

Generating SSH key pairs locally
  1. In a terminal, type the command ssh-keygen -t rsa, and press enter.
  2. When asked to enter file in which to save the key, press enter without typing in a name. ...
  3. Enter a password for the key pair, and press enter. ...
  4. Upload the public key file (the one ending in .

How to generate multiple SSH keys? ›

Table of Contents
  1. Step 1: Double-check if you have an existing SSH key. ...
  2. Step 2a: If you don't have an existing SSH key, generate a new SSH key. ...
  3. Step 2b: Save the SSH key in the according file of your choice. ...
  4. Step 3: Adding the SSH to the ssh-agent. ...
  5. Step 4: Add your SSH private key to the ssh-agent.

How to find SSH key by command? ›

How to view your SSH public key on Linux
  1. The first method is to use the cat command: Using the run command. Execute the following command. cat ~/.ssh/id_rsa.pub. ...
  2. The second method involves using both the ssh-agent and ssh-add commands:: Using the ssh-agent command. Run the following command.
Sep 12, 2023

What are the SSH key keys? ›

An SSH key is an access credential for the SSH (secure shell) network protocol. This authenticated and encrypted secure network protocol is used for remote communication between machines on an unsecured open network. SSH is used for remote file transfer, network management, and remote operating system access.

How to generate SSH public key in Linux? ›

Procedure
  1. In a terminal, run the ssh-keygen command.
  2. Generate the public/private RSA key pair.
  3. Specify the directory in which to save the key pair. For example, /Users/mymac/. ssh/id_rsa... mysftpkey.
  4. Enter the passphrase. Then, enter the same passphrase again. Enter empty if you don't want to use a passphrase.

How do I generate SSH keys for SFTP? ›

Users can generate their own SSH keys by logging in with their username and password, selecting their username at the top right of the page, selecting My account > SFTP keys > Add SFTP key, selecting the Generate in browser option, then selecting Generate key pair.

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5798

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.