40 SSH Public Key

This section describes the Compute Classic CLI commands you can use to add, delete, update, and view SSH public keys.

To connect to an instance using SSH, you must associate it with one or more SSH public keys. You must first generate the required SSH key pairs by using a tool such as ssh-keygen, and then upload the public keys to Oracle Cloud. For instructions to generate SSH key pairs, see Generating an SSH Key Pair in Using Oracle Cloud Infrastructure Compute Classic.

Before running the CLI commands described in this section, make sure that you've installed the CLI client and set up the required environment variables as described in Preparing to Use the CLI.

ssh-key add

Adds an SSH public key to Compute Classic.

You must first generate the required SSH key pairs by using a tool such as ssh-keygen, and then upload the public keys to Compute Classic. For instructions to generate SSH key pairs, see Generating an SSH Key Pair in Using Oracle Cloud Infrastructure Compute Classic.

After adding SSH public keys, you can associate them with instances by specifying the key names in launch plans, as described in launch-plan add.

Required Role

To complete this task, you must have the Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key add name key [--enabled]

For help with the parameters and options of this command, run the command with the -h option.

Example

The following command adds an SSH public key with the specified name and value. You can provide the value of the SSH key directly at the command line or you can provide the value in a file. By default, the SSH key is enabled. If you want to create an SSH key and disable it, set the --enabled option to false while adding the SSH key. You can’t associate disabled SSH keys with instances.

  • opc -f json compute ssh-key add /Compute-acme/jack.jones@example.com/adminkey file://~/.ssh/id_rsa.pub
  • The SSH key value has been truncated with ellipses (...) for readability. Provide the entire value of the SSH key when you run the command.
    opc compute ssh-key add /Compute-acme/jack.jones@example.com/adminkey "ssh-rsa AAAAB3NzaC1yc2EAAAABIwA ..."

Sample Output

Some lines have been truncated with ellipses (...) for readability. When you run the command in your environment, you'll see the full output.

{
   "enabled": true,
   "uri": "https://api-z999.compute.us0.oraclecloud.com/sshkey/Compute-acme/jack.jones@example.com/adminkey",
   "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0ibAEmysI4o1z...",
   "name": "/Compute-acme/jack.jones@example.com/adminkey"
}

ssh-key list

Retrieves details of all the SSH public keys in the specified container that match the specified query criteria. You can pass one or more query parameters to filter the search results. If you don't specify any query criteria, then details of all the SSH public keys in the container are displayed.

Required Role

To complete this task, you must have the Compute_Monitor or Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key list container [--name name]

For help with the parameters and options of this command, run the command with the -h option.

Example

opc -f json compute ssh-key list /Compute-acme/jack.jones@example.com

Sample Output

Some lines have been truncated with ellipses (...) for readability. When you run the command in your environment, you'll see the full output.

{
 "result": [
  {
   "enabled": true,
   "uri": "https://api-z999.compute.us0.oraclecloud.com/sshkey/Compute-acme/jack.jones@example.com/dev_sshkey",
   "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA...",
   "name": "/Compute-acme/jack.jones@example.com/dev_sshkey"
  },
  {
   "enabled": false,
   "uri": "https://api-z999.compute.us0.oraclecloud.com/sshkey/Compute-acme/jack.jones@example.com/prod_sshkey",
   "key": "ssh-rsa AAAAB3NmbD2zw2EDDDDEMcDDD...",
   "name": "/Compute-acme/jack.jones@example.com/prod_sshkey"
  }
 ]
}

ssh-key discover

Required Role

To complete this task, you must have the Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key discover container

For help with the parameters and options of this command, run the command with the -h option.

Example

opc -f json compute ssh-key discover /Compute-acme/jack.jones@example.com

Sample Output

{
 "result": [
		/Compute-acme/jack.jones@example.com/dev_sshkey
		/Compute-acme/jack.jones@example.com/prod_sshkey
 ]
}

ssh-key get

Retrieves details of the specified SSH public key.

You can use the get command to verify whether add and update operations were completed successfully. Use the -F option (for example, -F enabled) to filter the output for specific attributes.

Required Role

To complete this task, you must have the Compute_Monitor or Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key get name

For help with the parameters and options of this command, run the command with the -h option.

Example

opc -f json compute ssh-key get /Compute-acme/jack.jones@example.com/dev_sshkey

Sample Output

Some lines have been truncated with ellipses (...) for readability. When you run the command in your environment, you'll see the full output.

{
   "enabled": false,
   "uri": "https://api-z999.compute.us0.oraclecloud.com/sshkey/Compute-acme/jack.jones@example.com/dev_sshkey",
   "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0ibAEm...",
   "name": "/Compute-acme/jack.jones@example.com/dev_sshkey"
}

ssh-key update

Updates the status or value of an SSH public key.

Required Role

To complete this task, you must have the Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key update name key [--enabled]

For help with the parameters and options of this command, run the command with the -h option.

Example

The following command disables the /Compute-acme/jack.jones@example.com/adminkey key. You can’t associate disabled SSH keys with instances. While updating an SSH key, you can provide the value of the SSH key directly at the command line or you can provide the value in a file.

  • opc -f json compute ssh-key update /Compute-acme/jack.jones@example.com/adminkey file://~/.ssh/id_rsa.pub --enabled=false
  • The SSH key value has been truncated with ellipses (...) for readability. Provide the entire value of the SSH key when you run the command.
    opc -f json compute ssh-key update /Compute-acme/jack.jones@example.com/adminkey "ssh-rsa AAAAB3NzaC1yc2EAAAABIwA ..." --enabled=false

Sample Output

Some lines have been truncated with ellipses (...) for readability. When you run the command in your environment, you'll see the full output.

{
   "enabled": false,
   "uri": "https://api-z999.compute.us0.oraclecloud.com/sshkey/Compute-acme/jack.jones@example.com/adminkey",
   "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0ibAEmysI...",
   "name": "/Compute-acme/jack.jones@example.com/adminkey"
}

ssh-key delete

Deletes an SSH public key. No response is returned.

Ensure that the SSH key that you want to delete is no longer being used by any instance.

Caution:

When you delete a key that’s associated with an instance, the instance continues to be accessible using ssh. But before re-creating the instance, you must remove the deleted key from the orchestration of that instance. Otherwise, the orchestration won’t start.

Required Role

To complete this task, you must have the Compute_Operations role. If this role isn’t assigned to you or you’re not sure, then ask your system administrator to ensure that the role is assigned to you in Oracle Cloud Infrastructure Classic Console. See Modifying User Roles in Managing and Monitoring Oracle Cloud.

Syntax

opc compute ssh-key delete name

For help with the parameters and options of this command, run the command with the -h option.

Example

opc compute ssh-key delete /Compute-acme/jack.jones@example.com/adminkey