Tille - I can see you, read those man pages!   Tille's Site

How to take screenshots in Linux

General problems

The [PrintScrn] button usually works when you are running Gnome or KDE, because it has been mapped to a screenshooter applet. The first problems arise when you want screenshots of menus, screenshots of message or error windows and screenshots of login screens. In those cases, just pressing the button on your keyboard doesn't work anymore.

Some resources suggest to run a nested X server, or an automated solution such as gdmflexiserver that comes with the gdm package, but I couldn't figure that out. Another solution would be to run import from a text console, when the DISPLAY variable is set to the correct graphical display, but that didn't work for me either (the image was all scrambled).

General solution

So, after many hours of sweat, blasphemy and confusion, this is a solution that works for me:

What do you need?

  • Two machines, host1 and host2. The first one displays the screen, the second takes the screenshot. It doesn't really matter what sort of host the second machine is, I guess, as long as it has a Secure SHell (SSH) client installed.
  • On the first machine, the xwd (X window dump) utility, that comes with the XFree86 package.
  • The convert tool, included in the ImageMagick package.

It also works with a machine with two displays configured (e.g. display 0 on [F7], display 1 on [F8]), that's what I have.

Preparation

On the machine that you want to take the screenshots from, host1, edit the xdm configuration file /etc/X11/xdm/Xsession, so that access to the display is granted even before a user logs in; add the line

xhost +localhost

(Or the name of the second host when you do this with two machines.)

Restart X ([Ctrl]+[Alt]+[Backspace]) after that. The same procedure if you use gdm, the Gnome Display Manager, which refers to xdm control scripts.

Check that you have access to this display from the second host, that you use for connecting to the first. Export the DISPLAY variable to reflect the display number on which you want to test. This is usually zero, but check anyway by logging in on that display on host1, opening a terminal window and checking the DISPLAY variable. In my case, I have two displays configured, and I tested on the second one:

[tille@host1 ~] echo $DISPLAY
:1

When this information is known, you can log out again or start up any program, or open any menu for taking screenshots.

Still in the checking phase, display a test application such as xeyes, xlogo or xclock on the login screen of host1, from host2:

tille@host2 ~> ssh host1

[tille@host1 ~] echo $DISPLAY
:10

[tille@host1 ~] export DISPLAY=:1

[tille@host1 ~] xlogo

The application is then displayed on host1, and not on host2. If it gives errors, check access to the display. This stage can be executed even if the display to test is not in view (e.g. when I switch back to display zero on host1, or, if you only have one display, when switching to text mode). When you switch back to the test display, your test application is visible.

The capturing of images

For taking the screenshot, the screen that you want to capture should be visible on host1. On host2, you are still logged in to host1, using ssh, and the DISPLAY variable is still set to reflect the (active) display on host1. Now use the xwd utility to capture the screen:

[tille@host1 ~] xwd -out screenshot.xwd -root
[bell] [bell]

There are many options to capture only the active window or another part of the screen, and the bell can be turned off and such. The -root option indicates to capture the entire screen.

Read man xwd.

Converting the screenshots

For using the screenshots in webpages or printed material, convert them to the desired format using the convert tool:

convert screenshot.xwd screenshot.eps
convert screenshot.xwd screenshot.jpg
etc.

And where is my pointer?

You'll have to paste it into your screenshot using gimp or such. You can find a lot of useful material issuing a command like

locate cursor

Using RH8.0, I found /usr/share/control-center-2.0/pixmaps to hold all pointers I need.

Screenshot of installation screens

RedHat 9 is thus far the only system I've ever heard of that supports this. It's vmware for the rest, afaik.

Home
© 1995-2010 Machtelt Garrels - tille - Powered by vIm - Best viewed with your eyes - Validated by W3C - Last update 20100511