Creating an SSH key from a Terminal

In this article, we will outline the process for creating an SSH key for various Operating Systems. This is useful when managing your server over a command-line interface (CLI) and is a necessary step when deploying a site using Ansible.

Linux / Mac

Macs and most Linux distributions should ship with OpenSSH, making the process for either platform pretty much identical.

  1. Generate an SSH key pair:
    ssh-keygen

    You will see something similar to the following.

    Generating public/private rsa key pair. Enter file in which to save the key (/home//.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home//.ssh/id_rsa. Your public key has been saved in /home/$(whoami)/.ssh/id_rsa.pub. The key fingerprint is: SHA256:SG8TNL9l7V5hg2CgBfFmh1JfdX2RHkGjegouKsXmLeg @ The key's randomart image is: +---[RSA 2048]----+ |       o=+.o .o**| |       .=o+ o.oo=| |      .o.=.oooo+o| |     . o+..+....o| |    . . S... .. .| |     + .... o. . | |    = .. . .  .  | |   o o...        | |  .E...          | +----[SHA256]-----+
  2. (Optional) Ensure your ~/.ssh permissions are correct. Correct permissions of the ~/.ssh folder:
    chmod 0700 ~/.ssh 

    Correct permissions of the files within the ~/.ssh folder:

    chmod 0600 ~/.ssh/*

Windows 10

Windows 10 provides OpenSSH natively, which may be accessed from the Command Prompt or PowerShell.

  1. Generate an SSH key pair:
    > ssh-keygen

    You will then see something similar to the following.

    Enter file in which to save the key (C:\Users\/.ssh/id_rsa):	 	 
    Enter passphrase (empty for no passphrase):	 	 
    Enter same passphrase again:	 	 
    Your identification has been saved in C:\Users\/.ssh/id_rsa.	 	 
    Your public key has been saved in C:\Users\/.ssh/id_rsa.pub.	 	 
    The key fingerprint is:	 	 
    SHA256:m9eb6SIE28EmCLLR6Uj1A/UdFy6iZE48AEsJnMiu0Jc @	 	 
    The key's randomart image is:	 	 
    +---[RSA 2048]----+	 	 
    |*+==.. . o. |	 	 
    |=*= = . . + |	 	 
    |oO . @ + o . |	 	 
    |+.o E * = . |	 	 
    |o . o *S. |	 	 
    |. . oo . |	 	 
    | .o . . |	 	 
    | ... + |	 	 
    | . o= |	 	 
     +----[SHA256]-----+	 	 
    
  2. (Optional) Ensure your ~/.ssh permissions are correct:
    cd .ssh
    icacls id_rsa.pub /inheritance:r
    icacls id_rsa.pub /grant:r username:"(R)"

    Replace username above with your Windows username

Pay for only what you need with our scalable Cloud Server Hosting plans.

Was this article helpful? Let us know!