Ssh to KVM virtual machine

Ho Yipyik
1 min readMar 22, 2022
  • [ Host OS ] Open your kvm machine via virtual-machine-manager
  • [ Guest OS ] Make sure you have your guest OS installed with openssh-server service
  • [ Guest OS ] Enable ssh port access of firewall
sudo ufw allow ssh

Reload

sudo ufw reload
  • [ Guest OS ] Gaining the IP of your guest OS
ip addr

You can find the guest OS IP 192.168.122.100 at the bottom part of the output

  • [ Guest OS ] Enable sshd service
sudo systemctl start sshd
sudo systemctl enable sshd

You can also learn the statues to guarantee the running of sshd service

sudo systemctl status sshd
  • [ Host OS ] List all your kvm machines
sudo virsh list --all
  • [ Host OS ] Start your kvm via cli
sudo virsh start Manjaro

( You should replace the Manjaro with the domain of your kvm machine, which has shown above after using list command )

  • [ Host OS ] Use ssh to access
ssh manjaro@192.168.122.100

( I use the info my kvm machine as an example )

  • [ Host OS ] Use key to guarantee the safety and convenience
  1. Install ssh-keygen to generate a random key
ssh-keygen -t ed25519

I recommend using ed25519 to keep safety

  1. Pass your key to your guest

We use an awesome tool named ssh-copy-id here, which will automatically finish the copy work.

ssh-copy-id manjaro@192.168.122.100

What you need is merely inputing the username@hostname just like using ssh.

  • Now, everything has done.

--

--