Skip to main content
Safe connection to the VM over SSH uses a key pair: you place the public key on the VM and store the private key on your device.

Prerequisites

Set up the VM

To be able to connect to the VM, define specific information during the VM creation.

Generate a key pair

Generate an SSH key pair. You will need the contents of the public key and the path to your private key in later steps.

Configure the user data

User configuration helps to quickly create VMs with identical user data: it stores your username and the public key for the access to the VM.
Create a configuration in the cloud-init format:
The configuration contains the following parameters:
  • name: Username for connecting to the VM. The above example sets the value of the machine’s USER environment variable as the username for the VM. Do not use the root or admin usernames. They are reserved for internal needs and are not allowed to connect to a VM by SSH.
  • sudo: Sudo policy. ALL=(ALL) NOPASSWD:ALL allows users unrestricted sudo access; False disables sudo access for users.
  • shell: Default shell.
  • ssh_authorized_keys: User’s authorized keys. Allows configuring SSH access to the VM. To create the key pair, follow the instructions in Generating SSH keys.
You can specify several users and their public SSH keys.For more information, see cloud-init configuration examples.

Configure the VM

When you create the VM, specify the user data, network settings and boot disk:
In the nebius compute instance create command, set the following parameters:
  • --cloud-init-user-data: Pass the user data with your username and public key.
  • --network-interfaces: To enable public access to the VM, include "public_ip_address": {} in the network interface specification. Alternatively, to enable public access to the VM, set "public_ip_address": {"allocation_id": "<allocation_ID>"} with an allocation ID. This way the public IP address is preserved as an allocation object and you can reuse it for another VM after deleting this one.
  1. Get the default subnet’s ID:
  2. Create an allocation by using the default subnet’s ID:
If an allocation with a public address has not been assigned to any resource for 30 days, Nebius AI Cloud can delete this allocation and release its address. If you want to preserve the address, assign its allocation to a Nebius AI Cloud resource.
Example:
For the full set of parameters and more examples, see How to create a virtual machine in Nebius AI Cloud.

Connect to the VM by using SSH

Requirements to connect to a private IP address or FQDNTo connect to a VM from another VM by using a private IP address or an FQDN, both VMs must be in the same network.
  1. Get your VM’s IP address:
    To connect to the VM from the internet (if you have enabled public access to it), get its public IP address:
  2. Connect to the VM:
    If your private key is stored in a custom location, specify the path to it with the -i parameter:

Shared access to the VM

To let the other users connect to your VM:
  1. Ask them to generate an SSH key pair and share the contents of their public key with you.
  2. Connect to the VM under the name used when creating the VM:
  3. Create a new user for VM access, named newuser in this example:
  4. Switch to the new user:
  5. Create the ssh directory:
  6. In the directory, create the authorized_keys file:
  7. Add the new user’s public key to the created file:
  8. Change the directory’s access permissions:
  9. Exit the new user’s shell:
  10. Restart the VM:
  11. Ask the other user to check the connection:

Example

Example of getting the public IP address of the VM named training-instance and connecting to it from the internet: