Skip to main content Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed

Remote desktop on NetBSD with Xnest (no VNC)

Published: 22-08-2021 | Author: Remy van Elst | Text only version of this article

❗ This post is over two years old. It may no longer be up to date. Opinions may have changed.

After I recently wrote about NetBSD on the DEC Alpha CPU in QEMU, I decided to play with NetBSD some more. One x86_64 virtual machine later, I'm starting to appreciate the beauty and simplicity. Great documentation, both online and via the manpages, low resource usage and boy oh boy does it feel fast. But, you're not here for my love letter, you want to have a remote desktop. In the earlier article, we set up VNC, both because it shows you how to install packages and because native X11 crashes. In this article, we are going to set up X11 forwarding via SSH, but with Xnest instead of VNC. Xnest allows you to have a full desktop / window manager inside a window. If you did a full install of NetBSD, then all you need is included on the system, no need to install any packages. This is an advantage if you are on an architecture that has no precompiled binary packages or if compiling from source takes too long.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.

Here is a screenshot of my native NetBSD X desktop, running the default ctwm window manager, the Clion IDE, a web browser and my favorite game, OpenTTD:


If you have XFCE installed, you can run a full desktop session as well:


Other nostalgic desktop environments are available as well, like CDE and WindowMaker:


Note that performance is slightly worse than with VNC and you might have some artifacts when dragging windows around. I also have an issue where, once a window manager is running, xterm will not start. If I start xterm before I start ctwm or xfce it runs fine. Here is a screenshot of the artifacts after dragging a window around. They're gone when you refresh that screen area, for example, by dragging another window around over that affected area:


In this article, the terms server and NetBSD host are used interchangeably, they both mean the NetBSD machine on which you want to run the GUI. The term client means the machine you forward the desktop to, the machine from which you SSH into the NetBSD server. On the client, the window is displayed, but the actual X server / GUI is coming from the server.

Setup X11 forwarding via SSH

This part assumes you installed NetBSD with X11 via the installer. That way, both Xnest and the default window manager, ctwm are installed.

By default SSH does not allow X11 forwarding. Edit the following file on the NetBSDS server to allow X11 forwarding:

vi /etc/ssh/sshd_config

Add the following line (or uncomment/change it) to allow X forwarding system wide for all users:

X11Forwarding yes

You can also add a Match block to enable X11 for just one user:

Match User remy
    X11Forwarding yes

Restart the ssh server to make this new setting active:

service sshd restart

Test it out with the following SSH command on your client machine:

ssh -Y

After logging in to your NetBSD machine, start a terminal:


It should pop up on your client (the one you used to SSH into the NetBSD server). I'm using the -Y flag instead of the -X flag because it saves you fiddling with xauth.

Continue on to the next section to use an actual window manager inside a window (nested X, or, a better name, Xnest).

Xnest and ctwm

The next section assumes you are logged in via SSH to the NetBSD server with the -Y flag. The manpage describes what Xnest is very well:

Xnest is both an X client and an X server. Xnest is a client of the real server which manages windows and graphics requests on its behalf. Xnest is a server to its own clients. Xnest manages windows and graphics requests on their behalf. To these clients, Xnest appears to be a conventional server.

Start Xnest with the following options on the NetBSD machine:

Xnest :1 -ac -once &
  • :1: The display which the new nested X server will use.
  • -ac: disable access control restrictions
  • -once: Terminate server after one session
  • &:

Start the default window manager ctwm, with our new display as an option:

ctwm -display :1

This is what you should see in the Xnest window on your client:


I have an error when launching xterm (or xcalc) once Xnest is running:

X Error of failed request:  BadAlloc (insufficient resources for operation)
  Major opcode of failed request:  45 (X_OpenFont)
  Serial number of failed request:  12
  Current serial number in output stream:  13

As stated before, when I launch xterm directly, it works, when in Xnest, it fails. Tried setting up the xfs (x font server) and all kinds of xset +fp variants to inform Xnest of fonts. The default font path has all files required and my client machine also has the same files in the same paths (the xnest manpage mentions this). Not being able to run xterm is annoying, but since I have xfce installed, I can run xfce-terminal or execute commands right on the SSH session shell.

Do note that you do not have to use $DISPLAY=:1. Before starting Xnest you can query the current DISPLAY variable (that SSH X forwarding uses):




Since we've started SSH with -Y, we can use :10 as the display variable in Xnest, ignoring the localhost part:

Xnest -ac -once :10 &

Now you do not need to specify -display :1 or export a new display variable in your terminal. I'm used to explicitly specifying one, which is why I do it that way in this guide.


If you have a network connection and binary packages available, you can install XFCE, a modern desktop. It works quite well when forwarded via Xnest. This section contains a mini XFCE install guide as a bonus. Make sure you have pkgin, the binary package manager, installed and use pkgin to install xfce plus some dependencies:

pkgin install xfce fam dbus

xfce is a group of packages. Once all of them are installed, copy the example dbus startup script to the required location:

cp /usr/pkg/share/examples/rc.d/dbus /etc/rc.d/dbus

Edit /etc/rc.conf and add:


Start dbus:

service dbus start

You only have to start dbus on this session, after a reboot it will be started automatically.

Repeat the same for fam and rpcbind, also required for XFCE:

cp /usr/pkg/share/examples/rc.d/famd /etc/rc.d/
echo rpcbind=YES >> /etc/rc.conf
echo famd=YES >> /etc/rc.conf
service rpcbind start
service famd start

Make sure you have an empty Xnest session started. Export the DISPLAY variable so XFCE knows in which X session it should run:

export DISPLAY=:1

Start XFCE in that new Xnest session:

dbus-launch /usr/pkg/bin/xfce4-session

It takes a few seconds to load. The background image took a bit longer for me than the rest of the session. Here is how it should look:


Other window managers are available as well. I've tried fluxbox and lumina-desktop, the latter taking a while to compile. windowmaker is fun to play with as well. Here is a screenshot after installing the windowmaker-desktop meta-package and running wmaker -display :1 to start:


If you're feeling really nostalgic, CDE, the Common Desktop Environment is also available for NetBSD. Astr0baby has a guide to run CDE on NetBSD on the Pinebook Pro.

Tags: articles , cde , netbsd , openttd , unix , vnc , window-maker , x11 , xfce