Using Cloud Shell

Getting Started with Cloud Shell

You can access Cloud Shell in two ways:

  • Via the OCI Console
  • Via the 'Try It' button that appears on many command line and code samples throughout the documentation
Note

Cloud Shell uses your user OCID to create your home directory. If you have multiple accounts in a tenancy (for example, you have a federated and a non-federated user account), you will get a separate, unique Cloud Shell home directory for each account.

To access Cloud Shell via the Console:

  1. Login to the Console.
  2. Click the Cloud Shell icon in the Console header. Note that the OCI CLI running in the Cloud Shell will execute commands against the region selected in the Console's Region selection menu when the Cloud Shell was started.

Cloud Shell launch icon

This displays the Cloud Shell in a "drawer" at the bottom of the console:

Cloud shell drawer example

You can use the icons in the upper right corner of the Cloud Shell window to minimize, maximize, restart, and close your Cloud Shell session.

Note

For clipboard operations, Windows users can use Ctrl-C or Ctrl-Insert to copy, and Shift-Insert or Ctrl-V to paste. For Mac OS users, use Cmd-C to copy and Cmd-V to paste.

To access Cloud Shell via the Try It button:

Many code and command samples in the OCI documentation include a Try It button. This button will copy the sample to the clipboard and open a Cloud Shell session so you can try out the sample.

Your Cloud Shell comes with the OCI CLI pre-authenticated, so there’s no setup required before you can start using it.

Try it with the following commands:

oci os ns get
oci iam compartment list

Interact with an OKE cluster from Cloud Shell

Follow the instructions in Setting Up Cloud Shell Access to Clusters to:

  1. Set up an OKE kubeconfig file for use with Cloud Shell:
    1. Select a cluster.
    2. Click the Access Cluster button.
    3. Click Cloud Shell Access.
    4. Click Launch Cloud Shell to display the Cloud Shell window.
    5. In the Cloud Shell window, run the Oracle Cloud Infrastructure CLI command to set up the kubeconfig file and save it in a location accessible to kubectl. For example:

      $ oci ce cluster create-kubeconfig --cluster-id ocid1.cluster.oc1.phx.aaaaaaaaae... --file $HOME/.kube/config  --region us-phoenix-1 --token-version 2.0.0
  2. Verify that kubectl is available and can connect to the cluster from the Cloud Shell window by entering the following command in the Cloud Shell window:

    $ kubectl get nodes

Transferring Files

You can transfer files to and from Cloud Shell, with the following limitations:
  • You can only select one file at a time to transfer with the File Transfer dialog, but you can select multiple files to transfer using drag and drop.
  • You cannot transfer directories.
  • The maximum file size is 4GB.
  • File permissions are not retained on transferred files.
  • File names are logged. Do not use Personally Identifiable Information (PII) in file names.
To upload a file to Cloud Shell using drag and drop:
  1. Drag one or more files into the Cloud Shell window.

To upload a file to Cloud Shell using the menu:

  1. Click the Cloud Shell menu at the top left of the Cloud Shell window and select Upload. The File Upload dialog appears.
  2. Drag and drop a file or click select from your computer.
    Note

    The File Transfer dialog only supports selecting one file at a time to transfer.
  3. Click the Upload button.
  4. The File Transfer dialog appears.
    1. File transfers that are in-process are shown with a progress bar
    2. You can cancel an in-progress file transfer by clicking the X next to the file's progress bar
    3. Completed file transfers are shown with a green check mark
    4. You can hide the File Transfer dialog by clicking Hide
    5. You can view the File Transfer dialog any time by selecting File Transfers from the Cloud Shell menu

To download a file from Cloud Shell:

  1. Click the Cloud Shell menu at the top left of the Cloud Shell window and select Download. The File Download dialog appears:
  2. Type in the name of the file in your home directory that you want to download.
    Note

    You can only download files from your home directory.
  3. Click the Download button.
  4. The File Transfer dialog appears.
    1. File transfers that are in-process are shown with a progress bar
    2. You can cancel an in-progress file transfer by clicking the X next to the file's progress bar
    3. Completed file transfers are shown with a green check mark
    4. You can hide the File Transfer dialog by clicking Hide
    5. You can view the File Transfer dialog any time by selecting File Transfers from the Cloud Shell menu

Customizing the Cloud Shell OCI CLI Configuration

Cloud Shell comes with a pre-authenticated OCI CLI, which is refreshed and provisioned for your user when you open a new Cloud Shell. The OCI config location and token are outside of the user's home directory, in /etc/oci. For example:


            example_user@cloudshell:~ (us-ashburn-1)$ ll /etc/oci
            total 20K
            drwxrwx---. 1 root oci 44 Oct 12 00:07 ./
            drwxr-xr-x. 1 root root 4.0K Oct 12 00:07 ../
            -rw-------. 1 jonathan_s oci 1.9K Jan 1 1970 config
            -rw-------. 1 jonathan_s oci 1.3K Jan 1 1970 delegation_token
            example_user@cloudshell:~ (us-ashburn-1)$

The location of the configuration file, OCI CLI authentication type, and profile choice are specified with environment variables:

OCI_CLI_AUTH=instance_obo_user
            OCI_CLI_CONFIG_FILE=/etc/oci/config
            OCI_CLI_PROFILE=us-ashburn-1

To customize the OCI CLI, you can create an OCI CLI RC file and put that in your local .oci directory:

$ oci setup oci-cli-rc --file path/to/target/file

For more information on configuring the OCI CLI, see Configuring the CLI.

Managing Cloud Shell Regions

Cloud Shell uses the CLI config file and ENV variables to determine which region that the OCI CLI is interacting with. The OCI CLI configuration file (specified by the environment variable OCI_CLI_CONFIG_FILE) contains the CLI profiles for Cloud Shell. Each region is its own CLI profile, and the current profile is specified via the OCI_CLI_PROFILE environment variable.

For example, if you open Cloud Shell from the Console with "US East (Ashburn)" selected in the Console region dropdown, Cloud Shell will open with the OCI_CLI_PROFILE set to us-ashburn-1.

Note

There is no [DEFAULT] profile value in Cloud Shell because the selected region changes depending on the Console configuration when Cloud Shell is opened.

If you would like to customize the OCI CLI settings in Cloud Shell you can use an OCI CLI configuration file. For example, to set a default compartment in your configuration file under the appropriate region profile in your RC file. For our "us-ashburn-1" example, you could add a default compartment setting like this:

[COMPARTMENT DEFAULTS]
[us-ashburn-1]
compartment-id = ocid1.compartment.oc1..xxxxxxxx

Resetting Your Cloud Shell Environment

You can use the csreset tool to reset your Cloud Shell environment to its default state. You can reset just your bash profile and emacs settings, or you can delete all of the data in your home directory and reset the bash and emacs settings.

To reset your bash files

You can use the --bashfiles (or -b) option to reset the $HOME/.bashrc, $HOME/.bash_profile, $HOME/.bash_logout and $HOME/.emacs files back to their default values:

csreset --bashfiles

or

csreset -b

To reset everything

You can use the --all (or -a) option to erase all the data in your $HOME directory and reset the $HOME/.bashrc, $HOME/.bash_profile, $HOME/.bash_logout and $HOME/.emacs files back to their default values:

csreset --all

or

csreset -a

Displaying help

To display usage options, use the --help or -h option:

csreset -h

or

csreset --help

Working with Python Versions

For maximum compatibility, Cloud Shell includes both Python versions 2 and 3. Python 2 is the default that will run when you enter 'python' at the command line.
python
To run Python 3, enter 'python3' at the command line.
python3