Solve OSX keyboard issues running virt-manager through SSH

    

While testing Linux KVM on Debian 6, I choose to access the management tool, virt-manager, from my Mac, running OSX Lion, through an SSH connexion. I’m using a french keyboard and discovered that it was sending garbage to the virtual machines console. I couldn’t even use the default Ctrl+Alt key binding to get out of the console.

There are a few tricks to apply to solve this.

Fix the Ctrl+Alt key binding

First of all, to be able to get out of the console, you have to modify the X11 keybindings. On my Mac, from a Terminal:

# vi ~/.Xmodmap
clear Mod1
keycode 66 = Alt_L
keycode 69 = Alt_R
add Mod1 = Alt_L
add Mod1 = Alt_R

You have to restart X11 to apply the changes. Since then, you can issue ctrl+alt to get out of the console.

Fix the console keyboard

From the KVM server, I’ll force the kvm system to use a French keyboard layout:

# mv /usr/bin/kvm /usr/bin/kvm.bin
# cat > /usr/bin/kvm
#!/bin/sh
exec /usr/bin/kvm.bin -k fr "$@"
^D
# chmod 755 /usr/bin/kvm

The virt-manager has to be restarted to apply changes.

Running virt-manager through SSH

I installed the management tool on the KVM server itself (no matter how unsecure this is). To run it using the OSX X11 system via SSH, ensure that SSH on the server-side allows X-forwarding:

# grep X11Forwarding /etc/ssh/sshd_config 
X11Forwarding yes
# ssh -X kvm-server "virt-manager"

Note that to use virt-manager as a regular user, you have to include that particular user in the libvirt KVM server’s group. It seems, on some other implementation, the group is named kvm.

Source