Set up the VM
To be able to connect to the VM, define specific information during the VM creation.Generate a key pair
Generate a key pair for SSH access to the VM and save it in the default location: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. The configuration has the cloud-init format and contains the following data:-
name: Username for connecting to the VM. You can set the name explicitly or use your default one (the value of your machine’sUSERenvironment variable). Do not use therootoradminusernames. They are reserved for internal needs and are not allowed to connect to a VM by SSH. -
sudo: Sudo policy.ALL=(ALL) NOPASSWD:ALLallows users unrestricted sudo access.Falseprevents sudo access for users. -
shell: Default shell to use. -
ssh_authorized_keys: The public key contents.
Configure the VM
During the creation of the VM, configure thespec field as follows:
-
Pass the user data with your username and public key to the
spec.cloud_init_user_datafield. -
To enable public access to the VM, pass an empty object (
{}) to thespec.network_interfaces.public_ip_addressfield. You will not be able to allocate the public IP address to the already created VM.
spec.network_interfaces.public_ip_address.allocation_id field. This way the public IP address will be saved like an allocation object and you can use it after deleting this VM for another new one. You will not be able to allocate the public IP address to the already created VM.
How to create an allocation
How to create an allocation
-
Get the default subnet’s ID:
-
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.
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.
-
Get your VM’s IP address and save it to an environment variable:
- Connecting from the internet
- Connecting from another VM
To connect to the VM from the internet (if you have enabled public access to it), get its public IP address: -
Connect to the VM:
- Connecting from the internet
- Connecting from another VM
Shared access to the VM
To let the other users to connect to your VM:-
Ask them to generate an SSH key pair and share the contents of the public SSH key (e.g.
id_ed25519.pub). -
Connect to the VM under the name used when creating the VM:
-
Create a new user for VM access, named
newuserin this example: -
Switch to the new user:
-
Create the
sshdirectory: -
In the directory, create the
authorized_keysfile: -
Add the new user’s public key to the created file:
-
Change the directory’s access permissions:
-
Exit the new user’s shell:
-
Restart the VM:
-
Ask the other user to check the connection:
Example
Set of commands to connect to the VM namedtraining-instance from the internet: