:_newdoc-version: 2.18.5
:_template-generated: 2025-08-13
:_mod-docs-content-type: REFERENCE

[id="vm-connection-commands_{context}"]
= VM connection commands

[role="_abstract"]
You use can use the following `virtctl` commands to expose ports and connect to virtual machines (VMs) and VM instances (VMIs).

.VM connection commands
[width="100%",cols="1a,2a",options="header"]
|===
|Command |Description
|`virtctl console <vm_name>`
|Connect to the serial console of a VM.

|`virtctl expose vm <vm_name> --name <service_name> --type <ClusterIP\|NodePort\|LoadBalancer> --port <port>`
|Create a service that forwards a designated port of a VM and expose the service on the specified port of the node.

Example: `virtctl expose vm rhel9_vm --name rhel9-ssh --type NodePort --port 22`

|`virtctl scp -i <ssh_key> <file_name> <user_name>@vm/<vm_name>`
|Copy a file from your machine to a VM. This command uses the private key of an SSH key pair. The VM must be configured with the public key.

|`virtctl scp -i <ssh_key> <user_name@vm/<vm_name>:<file_name> .`
|Copy a file from a VM to your machine. This command uses the private key of an SSH key pair. The VM must be configured with the public key.

|`virtctl ssh -i <ssh_key> <user_name>@vm/<vm_name>`
|Open an SSH connection with a VM. This command uses the private key of an SSH key pair. The VM must be configured with the public key.

|`virtctl vnc <vm_name>`
|Connect to the VNC console of a VM.

You must have `virt-viewer` installed.

|`virtctl vnc --proxy-only=true <vm_name>`
|Display the port number and connect manually to a VM by using any viewer through the VNC connection.

|`virtctl vnc --port=<port-number> <vm_name>`
|Specify a port number to run the proxy on the specified port, if that port is available.

If a port number is not specified, the proxy runs on a random port.
|===


