Posts Tagged x11

X11 forwarding a chroot

I figured I’d blog this so I wouldn’t stop forgetting how to do this and possibly learn a “better” way to do this. I’m going to assume that vanilla x11 forwarding works outside the chroot as a starting point.

The process is relatively simple that I use. First I ssh into my server as a user using the -Y option like so:

ssh -Y ken@fooserver

Then I su to root:

su

Now comes the part that makes the forwarding work. We need to export the magic cookie that our current session is using so that the chroot can import it and use it. We do this like so:

xauth list > /tmp/X

This saves the magic cookie info into a file under /tmp so that we may access it later. Now its time to chroot in:

chroot /mnt/devchroot/ /bin/zsh

and I generally like to set my PS1 to remind me that it’s a chroot but is not necessary:

PS1="dev $PS1"

Now we need to import the magic cookie after chrooting in:

xauth add $(cat /tmp/X)

At this point x11 forwarding should now be working in the chroot. An easy way to test is to simply launch an xterm inside the chroot. xterm&

If the xterm appears everything is in working condition. At this point you should probably delete the /tmp/X file for security.

, ,

No Comments