Score:0

How to access virtual machine in KVM without ssh?

ie flag

How can I access virtual machine in KVM without ssh, ssh port is disabled and I want to enter the virtual machine and enable it. I tried virsh console and VNC solutions , they did not work because it is not enabled from inside. It seems it is impossible to enter the virtual machine. IS there any way to enter?

Elvin Jafarov avatar
ie flag
what you mean physically access?
raj avatar
cn flag
raj
Try `virt-manager` (requires a graphical X display) on the host computer. It can access "physical" consoles of the VMs (`virsh console` can access only serial consoles AFAIK, so if you haven't enabled a serial console, it will not work).
Elvin Jafarov avatar
ie flag
@raj can I download virt-manager, in host server? because i tried in local machine, it did not work.
Elvin Jafarov avatar
ie flag
@user68186 server is in the office, how can I login to guest machine? it is server not desktop. I quite don't understand what you mean by locally login.
Score:1
cn flag
raj

The easiest method to access virtual machine consoles is the program called virt-manager. It is a GUI program that is an "all in one" solution to manage virtual machines in general - create, modify, start/stop them etc.

You may have virt-manager already installed on your server as a part of KVM installation. If not, install it as you usual install any software, using the command

sudo apt install virt-manager

You should run virt-manager with root privileges (otherwise it may have trouble communicating with libvirtd daemon on your machine), ie.

sudo -b virt-manager

(the -b parameter to sudo tells to run the program in background - as GUI programs are usually run - to avoid blocking the terminal).

The program is basically self-explanatory and you can easily access the VM console with it.

However, because it is a GUI program, the tricky part is how to get it running on a remote server that you access via SSH (I suppose so, because you didn't specify exactly how do you access the server).

Running a GUI program on a remote server requires two things:

  1. an X server running on the local machine (from which you SSH to the server), to be able to display the GUI, and
  2. configured X forwarding over SSH between remote and local machine.

As for 2), you need to edit the file /etc/ssh/sshd_config on your server and check if it contains a line that says

X11Forwarding yes

It usually doesn't, so you have to add that line and save the modified file (note: you must do it as root, eg. use sudo to call your preferred editor on the file). After this, you need to restart the ssh service:

sudo service ssh restart

As for 1) the easiest case is when your local machine is also a Linux machine, as it already has a X server running to operate its local GUI :). In that case you don't need to do anything special besides adding a -X parameter to ssh command when you connect to the server:

ssh -X youruser@yourserver

The -X parameter tells ssh to forward the GUI over SSH to the local X server, so the program running on server will display its GUI on your local computer.

If your local machine is a Windows machine, then you need to install locally some software that provides the X server functionality (for example Xming). After X server is started, you need to tell your SSH client to forward the GUI. The exact way how to do it depends on the SSH client you use.

If you are using the built-in ssh command in Windows 10/11, it should support the -X option similarly to the Linux one (but I haven't tested it).

If you are using PuTTY (which is probably the most popular SSH client for Windows), before opening the connection you should go to Connection -> SSH (click "+" to expand) -> X11 in the options screen, and then tick the check box "Enable X11 forwarding" - this is equivalent to specify the -X parameter in ssh command (I have tested it and can confirm it works).

Below you can see a screenshot of virt-manager accessing a VM console on the server (the server in this case is CentOS, the local machine is a quite old version of Ubuntu, the VM is OpenWRT :)) :

enter image description here

Elvin Jafarov avatar
ie flag
my local machine is Mac , server is ubuntu,X11Forwarding will be fine?
raj avatar
cn flag
raj
I haven't used a Mac, but from what I know it's basically a BSD system, so it should work similarly to Linux. After you configure X Forwarding on the server side, `ssh -X` command on the Mac should work.
Elvin Jafarov avatar
ie flag
thanks, i will try tomorrow in office
Elvin Jafarov avatar
ie flag
Thanks man, you saved me , I posted what I did differently
Score:0
ie flag

As previously mentioned, the suggestion given by Raj and made the following changes to resolve the issue I was encountering:

I used "virt-manager" instead of "sudo -b virt-manager".

I used "sudo usermod -a -G libvirt $USER" to add user to the "libvirt" group because it was encountering a permission error.

The use of "virt-manager" instead of sudo -b virt-manager is meant to avoid using the "sudo" command, which elevates privileges and can cause issues with the display. The use of sudo usermod -a -G libvirt $USER adds the user to the "libvirt" group to resolve the permission error that was preventing the connection to the libvirt daemon.

raj avatar
cn flag
raj
One more correction: use `virt-manager &` instead of just `virt-manager` to run the program in background and avoid blocking the terminal.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.