How to: Generate an SSH Key
  • 17 May 2023
  • 1 Minute to read
  • Dark
    Light

How to: Generate an SSH Key

  • Dark
    Light

Article summary

The following guide shows how to generate an SSH key on Linux. 


If you're running a cPanel/WHM server, you can add your SSH key to the server via the WHM interface.

Please see the below documentation for instructions for cPanel/WHM users:

https://docs.cpanel.net/whm/security-center/manage-root-ssh-keys/


For non-cPanel/WHM users, or users that prefer the command line, please see below.

First, open your Linux terminal.

Now you can use the ssh-keygen command to start generating a key.

[root@myserver ~]# ssh-keygen 
Generating public/private rsa key pair.


Next, it will ask you to specify a path, just hit enter to use the default, unless you want to save it to a specific path. Using the default is usually the best, as your ssh client will automatically use this path once the key is generated.

Enter file in which to save the key (/root/.ssh/id_rsa): 


Next, enter your SSH key password. This is important, just in case your key is stolen. Note that you won't see anything while typing your password, this is normal.

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.        
Your public key has been saved in /root/.ssh/id_rsa.pub.        
The key fingerprint is:
SHA256:lxGS8vvHfcvifsWE7GBzboMg12GXoDF++uiQ9ZeMgxg root@myserver
The key's randomart image is:
+---[RSA 2048]----+
|        ..+ .. . |
|      . .o =o o  |
|       o  +o.+ . |
|        o o== + .|
|        E+=o B o |
|        .* =.o=.o|
|        +.o.=o+..|
|         o. o+o..|
|          ..ooo+.|
+----[SHA256]-----+


Once the SSH key is generated, you can provide our helpful support team with the pub key (the pub key is safe to send, it's like the lock to your key) to install on your server. It should look like this:

[root@myserver ~]# cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCdplDgaR0VvY4MiIN6QlM4/fcQJ30VEGAyHQGaSpVJgWJJXiDCcGwRtaKM+XuFVUqoJswS4aXtirSQrotgVtsKXixrWyQZ9nl0goCeh4Ft6awRd5rPH7LXUC6LWoEuT75XPw9r/Fi5v+PU4gecXX/txJ2tx/Wr9dnR8sweSGPYX3QwoLPFV2qgCinNe/RuUNufeUqCU8xWYiz8yi/MdpP5gbnbguGEBqfcRZkC/9c8xgXtfYOQPk38KDimhe72G1lCpU0rSPh8kex6UrQpen4Jkr2QtBDR0V0pKKBCCKeOBS0P1E+tUd9KrK6oo18rJlJBIatQUSwosqE0WeG7lXnz root@myserver


If you want to install it yourself, you can add it to the /root/.ssh/authorized_keys file. 

You'll need to SSH to the server as a user that has "sudo" permissions to do this.

echo "paste your SSH public key here" >> /root/.ssh/authorized_keys




Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy, a generative AI, facilitating knowledge discovery through conversational intelligence