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:-
name: Username for connecting to the VM. The above example sets the value of the machine’sUSERenvironment variable as the username for the VM. 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;Falsedisables 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.
Configure the VM
When you create the VM, set the following parameters in thenebius compute instance create command:
-
--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.
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
If your private key is stored in a custom location, specify the path to it with the-iparameter:
Shared access to the VM
To let the other users connect to your VM:- Ask them to generate an SSH key pair and share the contents of their public key with you.
-
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: