Practices: Create a Compute Instance
Try this hands-on lab with the Oracle Cloud Free Tier. If you do not have a free
account, click here to get one.
Overview
You will perform the following tasks in this practice:
• Launch Cloud Shell
• Generate SSH Keys
• Create Compute Instance
Copyright © 2021, Oracle and/or its affiliates.
Oracle Cloud Infrastructure Foundations 1
Practice: Launching the Cloud Shell
Overview
In this practice you will launch the Cloud Shell session for the OCI user account assigned to
you in preparation for the upcoming practices.
Cloud Shell
Oracle Cloud Infrastructure (OCI) Cloud Shell is a web browser-based terminal accessible from
the Oracle Cloud Console. Cloud Shell is free to use (within monthly tenancy limits), and
provides access to a Linux shell, with a pre-authenticated OCI CLI and other useful tools.
It provides:
• An ephemeral machine to use as a host for a Linux shell, preconfigured with the latest
version of the OCI CLI and several useful tools
• 5GB of storage for your home directory
• A persistent frame of the Console which stays active as you navigate to different
pages of the console
Note:
• The OCI CLI will execute commands against the region selected in the Console's
Region selection menu when the Cloud Shell was started. Changing the region
selection in the console will not change the region for existing Cloud Shell instances;
you will need to open a new Cloud Shell instance to change regions.
• Cloud Shell sessions have a maximum length of 24 hours, and time out after 20
minutes of inactivity. However, this should not impact this practice.
Prerequisites
Login with your OCI username and password, create the below policy in root
compartment:
allow group ocilabs-group to use cloud-shell in tenancy
Tasks
1. Log into your Oracle Cloud Free Tier Account
2. Login as ocilabs-user
3. Click the Cloud Shell icon in the OCI Console header, highlighted in the below screenshot.
Copyright © 2021, Oracle and/or its affiliates.
2 Oracle Cloud Infrastructure Foundations
4. This will launch the Cloud Shell in a “drawer” at the bottom of the console. Once it is ready
you will see the terminal as show below:
5. You can use the icons in the upper-right corner of the Cloud Shell window to minimize,
maximize, and close your Cloud Shell session.
You can also use the menu icon in the upper-left corner of the cloud-shell window to
upload or download files, restart console and different setting options.
6. For clipboard operations:
• Windows users can use Ctrl-C or Ctrl-Insert to copy, and Ctrl-V or Shift-
Insert to paste.
• For Mac OS users, use Cmd-C to copy and Cmd-V to paste.
To get started with Cloud Shell, you can run the below OCI CLI command. Your Cloud
Shell comes with the OCI CLI pre-authenticated, so there is no setup to do before you can
start using it.
7. This command will display the name space of your OCI Tenant.
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ oci os ns get
{
"data": "bm6rwnfgnfbj"
}
This completes the task of launching Cloud Shell. Keep this session active for the next
practice.
Copyright © 2021, Oracle and/or its affiliates.
Oracle Cloud Infrastructure Foundations 3
Practice: Generating SSH Keys
Overview
Instances use an SSH key pair instead of a password to authenticate a remote user. A key pair
file contains a private key and public key. You keep the private key on your computer and
provide the public key every time you launch an instance. In this practice, you will generate
SSH keys to be used later while launching an instance.
Tasks
1. Launch the Cloud Shell session as described in the previous practice.
2. Execute the below commands to generate ssh-keys, which will be used to create Compute
instance. As long as an id_rsa and id_rsa.pub keypair is present, they can be reused.
By default these are stored in ~/.ssh/ directly.
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key
(/home/ocilabs_us/.ssh/id_rsa):
Created directory '/home/ocilabs_us/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in
/home/ocilabs_us/.ssh/id_rsa.
Your public key has been saved in
/home/ocilabs_us/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zxQogNbEvQJIAbJb+3x1r8QEJN8ZWlUYHHyZge5lZ10
ocilabs_us@804708cc8ef6
The key's randomart image is:
+---[RSA 2048]----+
|=+.=o.. . o++*o+ |
|o.+ o..+ = o= + E|
|.... ..= +. . o|
| o .. .. . .. o +|
|. . . S +. o o |
| o . B .. |
| o . = . |
| . . . |
| . |
+----[SHA256]-----+
Copyright © 2021, Oracle and/or its affiliates.
4 Oracle Cloud Infrastructure Foundations
3. Make sure permissions are restricted, as sometimes ssh fails if private keys have
permissive file permissions.
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ chmod 0700 ~/.ssh
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ chmod 0600 ~/.ssh/id_rsa
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ chmod 0644
~/.ssh/id_rsa.pub
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ ls -l ~/.ssh
total 8
-rw-------. 1 ocilabs_us oci 1675 Jun 29 17:10 id_rsa
-rw-r--r--. 1 ocilabs_us oci 405 Jun 29 17:10 id_rsa.pub
4. Copy the contents of ~/.ssh/id_rsa.pub on a Notepad. This is your ssh key to connect
to the instances.
ocilabs_us@cloudshell:~ (ap-mumbai-1)$ cat ~/.ssh/id_rsa.pub
ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDEUsgq5R/5PcdS1+Mws2Y6vli0HcCw9g3l
uI0x/yFDwE+stlnfyzv4c73+uS35VD6kgFMo5izZKx3fV0JpqhUPjwtwuyigP9jc
6cgJmWjYhkbCHD8r8bFvrdVv0KuUPi+oKQUI4Zr4EtuTao3kkLywWz6aEJgS6GY2
19JSXqBH27QjgGk4l4sdeb9VuTuQ07Z7VyzyAUfKK5oqlJfLC6a/JhdfTLYnv++W
y3lnVZUojEQK57bOD7jVDTTErs0PSWXzMedretrEXtsBU+Tm1DZBe7QWoqghMTkI
a3hegu1qIwVxujfy7xDNPE1FHR/LG0978CyJwAfRShjXAYQtSwMF
ocilabs_us@804708cc8ef6
This completes the task of creating the ssh key.
Copyright © 2021, Oracle and/or its affiliates.
Oracle Cloud Infrastructure Foundations 5
Practice: Creating a Compute Instance
Overview
In this practice, you create Compute VM instances in each of the two subnets in your VCN.
An Oracle Cloud Infrastructure VM Compute instance runs on the same hardware as a Bare
Metal instance, leveraging the same cloud-optimized hardware, firmware, software stack, and
networking infrastructure.
Tasks
1. In the OCI Console, navigate to Menu > Compute > click Instances.
2. Click Create Instance.
Note: You should select your compartment before creating an instance.
3. Fill in the following details for your Compute instance:
• Name: OCI_Compute
• Compartment: ocilabs
• Placement: Select default
• Image or Operating System: Select the default Oracle Linux image
• Availability Domain: Select any Availability Domain
• Shape: VM.Standard.E2.1.Micro
Note:
To change the Image, you can click Change Image; however, you cannot change the
Shape in Always Free Account.
Click Show Shape, Network, and Storage Options and explore the details.
• Networking: OCI_VCN
• Add SSH Keys: Select the Paste SSH keys option and paste the content of your
Public SSH key copied in the previous practice. (Also available in
~/.ssh/id_rsa.pub)
• Boot Volume: Select default
4. Finally, click Create to create the Compute instance.
Copyright © 2021, Oracle and/or its affiliates.
6 Oracle Cloud Infrastructure Foundations
5. Once the instance state changes to Running, you can SSH to the Public IP address of the
instance. To do this, make a note of the Public IP address that gets assigned to the
OCI_Compute.
6. You will use Cloud Shell to connect to the Compute instance. Bring up the minimized
Cloud Shell terminal, or launch it again and enter the following command, and enter Yes
when prompted to continue connecting.
$ ssh opc@<Public_IP_of_Compute>
Note: In general, for OCI Linux-based compute instances, the default username is opc.
Once successfully connected, you can see the change in the command prompt to
ensure you are now logged in to your ‘OCI_Compute’ Compute instance.
This completes the task of creating a Compute instance.
Copyright © 2021, Oracle and/or its affiliates.
Oracle Cloud Infrastructure Foundations 7