72

I have a QEMU/KVM virtual machine created with Virtual Machine Manager.

I would like to be able to copy text on the host and paste it into the guest, and the other way around too.

How can I share the clipboard between the host and the guest?

elopio
  • 2,673
  • 1
  • 17
  • 20

4 Answers4

85

The solution is simple. Just install the package spice-vdagent in the guest virtual machine:

sudo apt install spice-vdagent

The clipboard is automatically shared - we can copy and paste between the host and the guest.

elopio
  • 2,673
  • 1
  • 17
  • 20
13

For my Linux Mint 18.2 Sonya machine timelf123 provided the answer:

  • In my Windows guest (Windows 7) downloaded and installed spice-guest-tools-latest.exe.
  • Before That, back in my QEMU/KVM Virtual Machine Manager I had to switch the guest machine's display to Spice.
  • Before That, back in my Linux host I had to fire up Synaptic Package Manager and install gir1.2-spice-client-gtk-3.0.
Melebius
  • 11,431
  • 9
  • 52
  • 78
  • 1
    Sorry. It's all right here. "“timelf123's link” is a reference his (timelf123's) comment on the preceding answer. I see that's not clear. In hindsight perhaps I should have commented rather than answered. –  Oct 11 '18 at 20:17
  • 1
    Thank you for the clarification! I included the links directly to your answer to make it clearer. – Melebius Oct 12 '18 at 06:30
7

In case the question pops up - what if it's Ubuntu server or similar?

Don't run around in circles - install openssh-server on the vm, and when you ssh in you cut and paste into your favourite terminal.

brianlmerritt
  • 194
  • 1
  • 6
  • although this might not directly answer the question, this is a viable option if you can reach the host via ssh from the network your favorite terminal is running from. It also seems that an X server needs to be running for the clipboard to work via SPICE if using virt-viewer but it should work with virt-manager with spice-vdagent installed. – Vincent Gerris Jan 15 '20 at 13:17
  • 1
    That's "out of the box thinking", and although it doesn't answer the question directly, it's the best answer, if the guest is a Linux type machine. Previously the answer was downvoted, but I find that a bit harsh. – ISparkes Mar 13 '20 at 12:09
4

In year 2021, qemu uses qemu-vdagent chardev for copy&paste, which turns off clipboard by default, so simply installing spice-vdagent package in guest OS does not work.

The solution of 2021 is:

  1. Install spice-vdagent package as the current answer said,

  2. Have qemu support spice (--enable-spice --enable-spice-protocol in ./configure option),

  3. Launch qemu using:

    qemu-system-x86_64 [ ... ] \
      -chardev qemu-vdagent,id=ch1,name=vdagent,clipboard=on \
      -device virtio-serial-pci \
      -device virtserialport,chardev=ch1,id=ch1,name=com.redhat.spice.0
    

    P.S. A side effect on my qemu is that the mouse moves more smoothly thanks to vdagent.

Reference: https://www.kraxel.org/blog/2021/05/qemu-cut-paste/

Greenonline
  • 2,081
zzzhhh
  • 247
  • 3
  • 10
  • 2
    don't work for me.. invalid parameter 'clipboard' – cesarpachon Jan 17 '22 at 13:46
  • Yeap invalid clipboard param. Is that because the spice isn't enabled? – fsevenm Jan 20 '22 at 02:14
  • I don't understand step 2 nor your reference mentions your step 2. Can you clirify? – João Pimentel Ferreira Jan 28 '23 at 18:09
  • 1
    @João Pimentel Ferreira: Thanks for asking. I built qemu myself from source. Step 2 of my answer mentions the building arguments for qemu to support spice. These arguments are written in a configuration file used by Makefile named `configure'. Because it is placed in the current folder, path "./" is specified. Details for configure scripts can be found here: https://www.gnu.org/prep/standards/html_node/Configuration.html – zzzhhh Jan 30 '23 at 03:54