Updating a VM
After you create a VM, you can edit its name, description, labels, platform, or metadata.
For information about editing a VM configuration, see Changing VM computing resources.
To update a VM:
- In the management console
, select the folder the VM belongs to. - Select Compute Cloud.
- In the left-hand panel, select
Virtual machines and click the name of the VM. - Click
Edit VM. - Change the VM parameters, e.g., rename the VM by editing the Name field.
- Click Save changes.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for updating VM parameters:
yc compute instance update --help
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Select
ID
orNAME
of the VM you need, e.g.,first-instance
. -
Change the VM parameters, e.g., rename the VM:
yc compute instance update first-instance \ --new-name windows-vm
To update a VM, use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.
Note
Changing the VM name does not change the host name or FQDN. For more information about generating the FQDN, see Host name and internal FQDN.
Examples
Viewing a list of configurable parameters
To view a list of configurable parameters, run this command:
yc compute instance update --help
Changing the name and description
To change the name and description of a VM, follow these steps:
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Select
ID
orNAME
of the VM you need, e.g.,first-instance
. -
Update the VM name and description:
yc compute instance update first-instance \ --new-name first-vm \ --description "changed description vm via CLI"
Use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.
Alert
Do not rename a VM if it belongs to a Managed Service for Kubernetes cluster node group. The names of these VMs are generated automatically, and changing them will disrupt the cluster.
Changing metadata
Metadata can vary across different operating systems. When you change the existing metadata, it is completely replaced by the data you provide in the command.
To change VM metadata, follow these steps:
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Select
ID
orNAME
of the VM you need, e.g.,first-instance
. -
Get the VM info with its metadata. All custom metadata is specified in the
user-data
key.yc compute instance get --full first-instance
-
Change the VM metadata. You can change it using these flags:
--metadata
: To change a single-line value.--metadata-from-file
: To change a multi-line value.
Note
The commands
yc compute instance create
|create-with-container
|update
|add-metadata
support substitution of environment variable values into VM metadata. When you execute a Yandex Cloud CLI command, these values, specified in theuser-data
key in$<variable_name>
format, will be substituted into the VM metadata from the environment variables of the environment the command is executed in.To change such behavior, i.e. to provide a variable name to the VM metadata in
$<variable_name>
format rather than take the variable value from the CLI command runtime environment, use the two-dollar syntax, e.g.,$$<variable_name>
.For more information, see Handling environment variables in metadata through CLI.
Removing SSH keys from metadata
- In the management console
, select the folder the VM belongs to. - Select Compute Cloud.
- Click the VM name.
- In the top-right corner of the page, click
Edit VM. - Open the Metadata menu and remove the keys by clicking
.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for removing metadata:
yc compute instance remove-metadata --help
-
Remove the keys:
yc compute instance remove-metadata <VM_ID> --keys <SSH_key_name>
To remove SSH keys from the VM metadata, use the updateMetadata REST API method for the Instance resource or the InstanceService/UpdateMetadata gRPC API call.
In your request, provide the delete
parameter with the SSH key.
REST API request example
curl \
--request POST \
--header "Authorization: Bearer <IAM_token>" \
--data '{"delete":["<SSH_key_name>"]}' \
https://compute.api.cloud.yandex.net/compute/v1/instances/<VM_ID>/updateMetadata
Enabling access via OS Login
To make sure users can connect to the VM via OS Login, enable this option in the VM settings:
- In the management console
, select the folder the VM belongs to. - Select Compute Cloud.
- In the left-hand panel, select
Virtual machines and click the name of the VM. - In the top-right corner, click
Edit VM. - Under Access, select Access by OS Login.
- Click Save changes.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for updating VM parameters:
yc compute instance update --help
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Select
ID
orNAME
of the VM you need, e.g.,first-instance
. -
Enable access via OS Login:
yc compute instance update first-instance \ --metadata enable-oslogin=true
Use the metadata
field to provide enable-oslogin=true
in the update REST API method for the Instance resource or in the InstanceService/Update gRPC API call.
Note
For users added via metadata:
- After enabling access to a VM via OS Login, the keys specified in
user-data
andssh-keys
are removed from the metadata. - After disabling access to a VM via OS Login, the removed keys are recreated.