Nested X sessions with Xephyr

I was searching for a way to establish a multi-seat setup for my laptop display and a monitor using a single graphics card when i came across Xephyr. (Thanks to bodhi.zazen’s post in ubuntuforums )

In this post, I have used Arch Linux with openbox running on my Lenovo Z560. The process should, however, work with all Linux Distros.

KDE session nested inside an openbox session through Xephyr

What is Xephyr?

From the Xephyr manual page

Xephyr – X server outputting to a window on a pre-existing X display

Xephyr  is  a kdrive server that outputs to a window on a pre-existing “host” X display.

In simple words, Xephyr allows you to nest X server within a X server. You can always create a new X server with startx — :1 , but what it actually does is create a new parallel X server in a new tty, which means only one X instance is handled at a time and you need to perform a Control, Alt, and Function combination each time you need to switch between X instances which is quite frustrating and inconvenient. Here is where Xephyr differs. It creates a new instance of X server within the current X server. The new X server behaves like any other application window. You can execute applications, as well as full Desktop sessions in the nested X server.

Advantages? Well, it is quite cool! Other than that, you can use it for conveniently testing out different Desktop Environments and window managers without any disruption to the current X session. You can also use it to forward X sessions via ssh without VNC. Although you can forward X applications using ssh without anything else, imagine forwarding multiple applications or a whole Desktop session.


Xephyr should be available on your Distro’s repository. Install it from there. Arch Linux users can install it from

$ sudo pacman -Syy xorg-server-xephyr

or download and compile it from

Using Xephyr

$ Xephyr -ac -screen 800x600 -reset :1 &

-ac : Disables access control restrictions and allows to forward the session
-screen : sets the resolution of the new X session. Set it according to your need.
:1 : This specifies that the new X session is display number “1“. Your current Display is most probably “0
-reset: Resets the X server when the last X client is closed.

The Xephyr should start and you will get a blank new window.
The $DISPLAY environment variable tells the X client to which X server it should send its output to. Thus, $DISPLAY controls in which X server an X application pops up. As you must have figured it out, by default, $DISPLAY is set to “:0“.

Now, set the $DISPLAY to “:1” so that you can send output to the Xephyr window.


Then shoot up any X application and it will get displayed in the new X Server.

$ xterm &
$ chromium &

Running Applications inside Xephyr window

Running Desktop Sessions

Time for some cool stuffs.

Running complete Desktop sessions is also possible in the new server. After setting the $DISPLAY to “:1”, run the command which shoots up the Desktop Session. eg. for awesome window manager, it would be awesome -c ~/.config/awesome/

For KDE, dbus-launcher /usr/bin/startkde worked for me. The process is similar and simple for most other Desktop Environments and Window manager.

Here is a snapshot of my main openbox session in which an awesome (window manager) session is nested, in which in turn is a nested KDE4 session.

A KDE within an Awesome within an Openbox :p

Forwarding the nested X session

One advantage of running nested X sessions using Xephyr is the ease and flexibility of forwarding the new X session.

Start the ssh daemon on the server machine. On Arch Linux, do this by

$ sudo rc.d start sshd

In this example, i will use the same machine as client and server. Start the new X server with Xephyr just as the above examples

$ Xephyr -ac -screen 800x600 -reset :1 &

Time to forward a X application (here, xterm) to the server,

$ ssh -XfC -c blowfish nimesh@localhost xterm 

The usage is

ssh -XfC -c blowfish user@server application

I had a problem in forwarding the X session where i would get the following error

X11 forwarding request failed on channel 0
xterm: Xt error: Can’t open display:
xterm: DISPLAY is not set

This is caused when ipv6 is enabled but there are no ipv6 interfaces. I solved this by adding the following lines in /etc/ssh/sshd_config

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
AddressFamily inet

Ending Lines

As i said in the first lines of this post, my next aim is to use Xephyr to configure multi-seat using only one graphics card. Will post about it later.

Anyways, any corrections, feedback, queries, etc, feel free to comment.


5 thoughts on “Nested X sessions with Xephyr

  1. Pingback: SSH -X

  2. Pierre13fr

    For the sake of clarity I would mention that :
    you start the sshd daemon on a REMOTE “application server”, which is DIFFERENT than the Xephyr server.
    Then, on the Xephyr machine, you start Xephyr AND open an ssh session to your “app and ssh server” enabling X11 forwarding (which means in fact “forwarding X11 request from the REMOTE ssh server to THE X-server of the local ssh CLIENT, the CLIENT= the machine where we run the ssh command”).
    So that your instructions should be :
    Start the ssh daemon on the REMOTE APPLICATION server machine. On Arch Linux, do this by
    REMOTE-SERVER$ sudo rc.d start sshd

    In this example, i will use the same machine as client and server. Start the new X server with Xephyr just as the above examples
    XEPHYR-SERVER$ Xephyr -ac -screen 800×600 -reset :1 &

    Time to forward a X application (here, xterm) to the server,
    Very important, on the Xephyr server before ssh-ing :
    XEPHYR-SERVER$ ssh -XfC -c blowfish nimesh@REMOTE-SERVER xterm

    Of course, you can work on a very same machine to test other window manager and so on, and then XEPHYR-SERVER=SSH-SERVER=LOCALHOST. In that case the ssh step is useless and replaced by a direct execution of your X-application, but the export DISPLAY is still necessary.


How did you feel about this post? Push in your reply!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s