Updating a VM
After you create a VM, you can edit its name, description, tags, 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. - Edit the VM parameters, e.g., rename it by editing the Name field.
- Click Save changes.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a 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 the
ID
orNAME
of the VM you need, e.g.,first-instance
. -
Change the VM parameters, e.g., rename it:
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 the FQDN. For more information about generating the FQDN, see Host name and internal FQDN.
Examples
Viewing a list of configurable parameters
To view the list of configurable parameters, run the 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 command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using 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 the
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 update the VM name if the VM belongs to a Managed Service for Kubernetes cluster node group. The names of these VMs are generated automatically, and updating them will disrupt cluster operations.
Changing metadata
Metadata based on different operating systems may differ. When you change an existing set of metadata, it is completely replaced by the set passed in the command.
To update VM metadata, follow these steps:
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using 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 the
ID
orNAME
of the VM, e.g.,first-instance
. -
Retrieve VM information with its metadata. All user-defined metadata is specified in the
user-data
key.yc compute instance get --full first-instance
-
Update the VM metadata. You can change the metadata using the flags:
--metadata
: To change a value from a single string.--metadata-from-file
: To change a value from multiple strings.
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 command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a description of the CLI command to remove 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 you need. - In the top-right corner, click
Edit VM. - Under Access, select Access via OS Login.
- Click Save changes.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a 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 the
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
In the metadata
field, set 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 deleted from the metadata. - After disabling access to a VM via OS Login, the deleted keys are recreated.