Creating SSH Keys for Use with Oracle Cloud Services

 

Before You Begin

Purpose

This tutorial covers how to create a secure shell (SSH) key pair in two ways:

  • By using PuTTY on Windows.

  • By using a command line with an SSH utility, such as those already included in many UNIX and UNIX-like systems such as Linux, Solaris, etc. Alternatively, you can install and use OpenSSH on UNIX or Cygwin on Windows.

Time to Complete

Approximately 30 minutes.

Background

Oracle Cloud services such as Oracle Java Cloud Service and Oracle Database Cloud - Database as a Service are built on top of infrastructure and functionality that are provided by Oracle Compute Cloud Service. When you create a service instance of one of these Oracle Cloud services, all the Oracle Compute virtual machines (VMs) required to support the service instance are provisioned and configured for you.

You can access the service instances and resources provided by the VMs by logging into the machine through a secure shell (SSH). To do so, you need an SSH public/private key pair for the VM. You will need the public key when creating a service instance, and you will need the paired private key when you access it using an SSH utility. This tutorial shows how to create the key pair.

Note: You can associate a single SSH public key with multiple service instances. However, you cannot associate an SSH public key with a service instance after you have created the instance.

Scenario

You are ready to create an Oracle Cloud service instance, and you need to create an SSH public key to use when creating it. Later, you will need the paired private key to access the VM remotely.

What Do You Need

  • PuTTY

    PuTTY is a free, open-source implementation of several network protocols, including SSH. It is available for Windows and for UNIX platforms. PuTTY includes several utilities including a terminal emulator, an SSH key generator, and a network transfer application. For this tutorial we will use the PuTTY Key Generator (puttygen.exe) for Windows.

    PuTTY is available from many sites, but you can reach the main download site http://www.putty.org.

  • An implementation of the UNIX ssh-keygen utility and a command line shell for running it. Many implementations of UNIX and UNIX-like operating systems already include ssh-keygen, so you don't have to install it yourself. Check the documentation for your operating system to see if you have ssh-keygen already (or simply try typing it at the command line).

    If you don't already have ssh-keygen installed, you can obtain it from any of a number of sources and install it yourself. Popular options are OpenSSH for UNIX and Cygwin for Windows. OpenSSH is available from http://www.openssh.com/portable.html. Cygwin is available from https://cygwin.com/install.html.

Before starting this tutorial, you should have:

  • Installed PuTTY on your computer with a Windows operating system.

  • Installed the ssh-keygen utility by either:

    • Making sure your UNIX or UNIX-like operating system already includes ssh-keygen; or

    • Installing an SSH utility with a command line interface, such as OpenSSH for UNIX or Cygwin for Windows.

  • Some knowledge of UNIX, for working at the command line.

 

Generating an SSH Key Pair Using PuTTY Key Generator

 

Creating an SSH Key Pair on the Command Line

To create an SSH key pair on the command line using ssh-keygen:

  1. Open a shell for entering the commands.

  2. At the prompt, enter the following:

       ssh-keygen -t rsa -N "" -b "2048" -C "key comment" -f path/root_name

    where the arguments are as follows:

    -t rsa Use the RSA algorithm.
    -N "passphrase"

    Passphrase to protect the use of the key (like a password). If you don't want to set a passphrase, don't enter anything between the quotes.

    Note: While a passphrase is not required, you should specify one as a security measure to protect the private key from unauthorized use.

    -b "2048"

    Generate a 2048 bit key. You don't have to set this if 2048 is acceptable, as 2048 is the default.

    Note: A minimum of 2048 bits is recommended for SSH-2 RSA.

    -C "key comment" A name to identify the key.
    -f path/root_name

    The location where the key pair will be saved and the root name for the files. For example, if you give the root name as id_rsa, the name of the private key will be id_rsa and the public key will be id_rsa.pub.

    For example,

    Command prompt - creating key pair, specifying parameters
    Description of this image
  3. Alternatively, you can simply enter ssh-keygen and then enter responses when prompted for a name and a passphrase. The keys will be created with default values: RSA keys of 2048 bits.

    Command prompt, creating key pair without parameters
    Description of this image
  4. To see that the files were created, type ls path/root_name*, for example,

    Command prompt, using li command to see files
    Description of this image
  5.  

 

Want to Learn More?