OCI - Create a Linux public instance using keypair generated with ssh-keygen commands in Linux Terminal.

Create a Linux public instance using keypair generated with <b>ssh-keygen</b> commands in Linux Terminal.
Disclaimer :

There are lots of wrong and right articles in internet, when you try to execute Hands-on Labs by yourself, there is chance that you could get drifted away or get severely confused, We strictly adhere to Official Oracle Cloud Documentation, offering you reliable and precise information without personal interpretations. This means you can trust our content 100% Genuine.

Prerequisites

Before you create a VCN and Subnets, ensure you have the following:

  • An active OCI account.
  • Necessary IAM policies to create and manage networking components.
  • A clear plan of your network topology and CIDR blocks to avoid overlapping IP addresses.

Lab Task:

Create a Linux public instance using keypair generated with ssh-keygen commands in Linux Terminal.

Lab Task Explanation:

Before we begin the Lab we need to create the SSH keypair using Commands in OCI Linux Terminal.

At the time of Instance creation, you will be presented with option to upload or paste the public key, use any of this option to create a New Instance.

Lab Task Flow:

    Task 1: Prepare a clear sample Architectural Diagram

    Our OCI Architectural diagram for this Lab is

    img:Instance with Public key

    Note : If you want to create such Cloud Architectural diagrams check this link Click here :

    Task 2: Create VCN and public subnet with CIDR in refer to the above sample Architectural Diagram

    To proceed with this Lab, we need to have a VCN and Subnets first, we assume that you already have an compartment, else kindly create Architecture by following below Guided Hand-on Lab Link and finish this Task of Creating a VCN or Subnet.

    Task 3: Create Key Pairs using key-generator Command in your Linux Machine

    Note : In case of any doubt - Jump to the Detailed vedio explantion given below

    Step 1 : Access your Linux Machine
    Step 2 : Setting the Folder Ready
    • Open Linux Terminal.
    • List the folders in the path your are in, using "ls" Command
    • Create a New Folder named "LinuxKeys" using the Command "mkdir LinuxKeys"
    • Conform the presence of our Newly created Folder, using "ls" Command
    • Get into the Folder using "cd LinuxKeys"
    • Description of the image
    Step 3 : Understanding the Keypair generation Command
    • Keypair generation command is
    • ssh-keygen -t rsa -b 2048 -f [filename]

    • -t ➜ means which algorithm is selected.
    • rsa ➜ means RSA algorithm, RSA is an old algorithm based on the difficulty of factoring large numbers. All SSH clients support this algorithm.
    • -b ➜ means keysize. A key size of at least 2048 bits is recommended for RSA; 4096 bits is better.
    • -f ➜ means [filename] with Path. don't use brackets "[]" while entering the real command.
    Step 4 : KeyPair Generation
    • Check once again are you inside the Correct directory.
    • Generate a new keypair using the following command:
    • Copy below Command and paste it in your Terminal $
      ssh-keygen -t rsa -b 2048 -f linuxkey
    • When prompted, enter a file name for the keypair and a passphrase(optional), press enter in your keyboard to generate the keypairs.
    • The keygeneration process will look like this
    • Description of the image
    Step 5: Get the Public Key Ready
    • within the Linux Terminal, get into the folder where both public and private keys are, and using Linux "cat" command open the public key file (.pub) and copy its code.
    • Description of the image

    Task 4: Create Linux Public instance with the use of these keys

      Step 1: Identify Sample Input
      • Subnet A is Public subnet.
      • Subnet A should have CIDR ip of 10.0.1.0/29.
      • Instance should have a private ip of 10.0.1.5.
      • Instance should be a Linux machine.
      Step 2: Create a Linux Instance using keypair generated with ssh-keygen commands in Linux Terminal
      Precautions

      When creating your instance and generating your keypair, remember to keep your private key secure. It’s also important to choose a strong passphrase (optional) for your keypair to ensure the security of your instance.


      1. Sign in to the OCI console.
      2. Open the navigation menu and click Compute > Instances.
      3. Click Create Instance.
      4. In the Create Compute Instance dialog box, provide the necessary information for your instance.
      5. In the Add SSH Keys section, select Paste SSH keys and paste the public key code which we copied previously.
      6. Description of the image
      7. Click Create to create your instance.


      Common Errors :

      Some common errors you might encounter include

      1. Invalid SSH Keys: Make sure your SSH keys are in the correct format.
      2. Permission Errors: Ensure you have the necessary permissions to create instances and generate keypairs.

    Detailed Video Explanation:

    Required concept knowledge

      Types of Keys?

      img: Keypairs

      There are two types of Keys in a Key pair - public key and private key

      Use of SSH Keypair?

      • You provide the public key when you create an instance.
      • And you keep the private key on a safe place.
      • When you connect to the instance using SSH, you provide the path to the private key in the SSH command.
      • The public key will be compared with private key for authentication.
      • Thus by using both keys you can create and get connected to your instance and do your administrative tasks.

      What is "SSH" in SSH keypair means?

      • The Secure Shell (SSH) protocol is a method for securely sending commands to a computer or a server over an unsecured network.
      • The SSH network protocol encrypts all traffic between the client and the server while it is in transit.
      • SSH utilizes public key cryptography, which involves the use of public and private keys to authenticate and establish a secure connection.
      • Thus anyone who requires managing a computer remotely namely, System and network administrators use this protocol to manage remote servers and machines, they can connect to a server and run commands as if they were sitting at the machine.

      Difference in Creating Linux Instance and Windows Instance

        web console keypair creation

      when is the Key pair generated

      Linux / Unix instance Windows instance
      Linux instances use an SSH keypair instead of a password to authenticate a remote user. Windows instances use username & password to authenticate a remote user.
    • Download keypair from pre-given OCI Web Console.
    • Generated keypair with ssh-keygen commands.
      1. using OCI "cloudshell" terminal.
      2. using windows "powershell".
      3. using windows "cmd" command prompt
      4. using "Gitbash" (old windows ver)
      5. using Open SSH tools (wsl2)
    • Generated keypair using GUI - PuTTY Key generator.
    • Usernames & passwords are provided by OCI at the time of instance creation.

      What is Oracle VM VirtualBox ?

      Oracle VM VirtualBox is a powerful, open-source virtualization software that allows users to run multiple operating systems on a single physical machine. It creates virtual machines (VMs) that emulate the hardware of a physical computer, enabling users to install and run different operating systems, such as Linux, Windows, or macOS, within their existing OS environment. This flexibility makes VirtualBox an excellent tool for testing software, learning new operating systems, or running applications that require a different OS without the need for additional hardware.

      How to launch a Linux OS in VirtualBox ?

      To launch a Linux OS in VirtualBox, you first need to download the ISO file of your preferred Linux distribution. Open VirtualBox and create a new VM by clicking “New” and following the prompts to configure the VM’s settings, such as memory allocation and disk space. Once the VM is created, start it and select the downloaded ISO file as the boot disk. The VM will boot from the ISO, allowing you to proceed with the Linux installation as you would on a physical machine. After installation, you can run Linux within the VM, providing a safe and isolated environment for experimentation and learning.

Post a Comment