How can I take a screenshot of the login screen?

I do not want to recreate my Ubuntu installation in a virtual machine.


9 Answers 9


This blog might be helpful: http://ptspts.blogspot.com/2010/02/how-to-create-screen-shot-of-gdm-login.html

Install ImageMagick for the image file format conversion below:

sudo apt-get install imagemagick

Create a helper script:

echo 'DISPLAY=:0 XAUTHORITY=/var/lib/gdm/:0.Xauth xwd -root' >/tmp/shot.sh

Make sure your login screen is active (log out or reboot the machine, and wait until you see the login screen). Log in in text mode (by pressing Ctrl-Alt-F1), or using SSH. Create the screen shot by running

sudo bash /tmp/shot.sh >/tmp/shot.xwd

You can log in now (by pressing Ctrl-AltF7 first to get back to the GDM login screen). Convert the screen shot to JPEG and/or PNG:

convert -quality 50 /tmp/shot.xwd /tmp/shot.jpg
convert /tmp/shot.xwd /tmp/shot.png

View the screen shot in your favourite image viewer.

  • 4
    I ended up using sudo sh -c 'sleep 5s; xwd -display :0 -root | convert - screenshot.png' from a virtual console and switching to the login screen during the 5-second sleep.
    – ændrük
    Commented May 17, 2011 at 23:23
  • 3
    I tweaked this for lightdm. $ echo 'DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 xwd -root' >/tmp/shot.sh
    – popey
    Commented Jun 10, 2012 at 17:03

For 11.10 and Lightdm and later

You can try running unity-greeter --test-mode in a terminal. It displays the login screen within the session. You can then take a screenshot of the login screen like you normally do with any other application.

enter image description here

  • but thats too generic, any modifications cannot be see . is there any way to test current modifications ?
    – Ubuntuser
    Commented May 12, 2012 at 7:35
  • @Ubuntuser Not that I know of. Which modification are you testing for?
    – jokerdino
    Commented May 12, 2012 at 7:44
  • i am testing fingerprint reader . on login screen and the lock screen it displays nicely. i want to take a screenshot of both.
    – Ubuntuser
    Commented May 12, 2012 at 8:09
  • @Ubuntuser I am guessing the modifications you made affects the lightdm directly and not the Unity-greeter? I am not sure. I am just speculating. You might want to ask a new question..
    – jokerdino
    Commented May 12, 2012 at 8:14

You can try this:

gnome-screenshot -d 10

you don't need to install any thing just enter the command and lock the screen, the screen will be shot within 10 seconds after the command is executed.

Even more .. the command will lock the screen , copy the screenshot to clipboard and unlock the screen again. All by it self.

gnome-screensaver-command -l && sleep 2 && gnome-screenshot -c && loginctl unlock-session

screenshot of Ubuntu lock screen

  • 3
    This is by far the easiest solution I found.
    – Caustic
    Commented Jul 16, 2017 at 4:14
  • 1
    After trying everything and getting nothing, these simple commands finally solves my problem. Thank you very much
    – thiggy01
    Commented Feb 27, 2020 at 21:40
  • OP question is about login screen not lock screen
    – vmemmap
    Commented May 28, 2022 at 8:41

Type this in a terminal:

dm-tool add-nested-seat --fullscreen

That's it! take a screenshot as usual

Press Alt + F4 to close the fullscreen window of your login screen

  • That's a beauty! Genius!
    – Anwar
    Commented Aug 16, 2016 at 12:41
  • I can also confirm this trick works perfectly on Ubuntu 18.10. I think this trick is easier and quicker than shell script. Thank you @afriend. Commented Sep 29, 2018 at 9:46

For Ubuntu 14.04

The answers above did not work for me in Ubuntu 14.04 - I searched around and found this that works.

  1. Install ImageMagick

     sudo apt-get install imagemagick
  2. Create a file in your home directory named shot.sh preferably in your home folder and paste the following code inside it:

     chvt 7;
     sleep 5s;
     DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 xwd -root -out ~/screenshot.xwd;
     convert ~/screenshot.xwd ~/screenshot.png;
     rm ~/screenshot.xwd
  3. Make it executable

     sudo chmod +x shot.sh
  4. Logout of the system. Press Ctrl+Alt+F1 to go to the console (tty1) and login. Run the script using this command:

     sudo ./shot.sh

It will take you back to login screen graphical interface (chvt 7) and after five seconds it will take and save the screenshot in your home directory with a file name screenshot.png.

Here's mine:

enter image description here

Source: How to Take Screenshot of Login Screen in Ubuntu Linux

  • I can confirm this shell script still works on Ubuntu 18.10 Cosmic Cuttlefish with Unity 7.5.0. I can take screenshot successfully in one try. Thank you @Parto. Commented Sep 29, 2018 at 9:43

Just wanted to note that I had a bunch of problems doing this on Ubuntu 10.04 LTS with this - here's my solution:

I'm on machine A, and I log on to machine B via ssh:

myusername@pcA:~$ ssh pcB
myusername@pcB's password: 
Linux pcB 2.6.32-44-generic #98-Ubuntu SMP Mon Sep 24 17:32:45 UTC 2012 i686 GNU/Linux
Ubuntu 10.04.4 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/


Then, I proceed with several attempts to grab screenshot, which all failed. The problem can be reduced down to xwininfo being unable to probe for the window state:

myusername@pcB:~$  xwininfo
xwininfo:  unable to open display ''

myusername@pcB:~$ sudo xwininfo
[sudo] password for myusername: 
xwininfo:  unable to open display ''

myusername@pcB:~$ DISPLAY=:0.0 xwininfo
No protocol specified
xwininfo:  unable to open display ':0.0'

myusername@pcB:~$ DISPLAY=:0 xwininfo
No protocol specified
xwininfo:  unable to open display ':0'

Well, it turns out that for some reason, the correct invocation for targeting X-windows via ssh is DISPLAY=:0.0 sudo xwininfo ... - that is, the DISPLAY=:0.0 environment variable goes first; the sudo goes second - and then the corresponding X command:

myusername@pcB:~$ DISPLAY=:0 sudo xwininfo

xwininfo: Please select the window about which you
          would like information by clicking the
          mouse in that window.

myusername@pcB:~$ DISPLAY=:0.0 sudo xwininfo -root

xwininfo: Window id: 0x109 (the root window) (has no name)

  Absolute upper-left X:  0
  Absolute upper-left Y:  0
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 1366
  Height: 768
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: ForgetGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +0+0  -0+0  -0-0  +0-0
  -geometry 1366x768+0+0

Now that we know xwininfo can probe the state, there is also no problem with capturing the screenshot via xwd:

myusername@pcB:~$ DISPLAY=:0.0 sudo xwd -root > /tmp/shot.xwd
  • Thank you, this helped me find what DISPLAY gdm3 was using. However, your solution won't have access to the DISPLAY used by gdm because you are not setting the XAUTHORITY variable, resulting in an xwd: unable to open display: 0.0 error.
    – thiggy01
    Commented May 8, 2020 at 16:05

For Lubuntu 20.04, you can use the SDDM version of jokerdino's answer, adjusting the theme. Run this command to display the greeter in your session:

sddm-greeter --test-mode --theme /usr/share/sddm/themes/lubuntu

Press the print screen key, select the area you want and save. No need to log out.


For Ubuntu with GDM3 as display manager

I adapted the answers given by @Niroshan, @Parto and @sdaau to work on recent versions of Ubuntu like 19.04 (Disco Dingo) and 20.04 (Focal Fossa). It's a really simple process, as shown below.

First, you will have to install the imagemagick package which has all the programs that'll be used in a script to take the shot.

sudo apt install imagemagick

Second, you will need to create a file and paste the contents of the script that change the virtual console to the gdm3 tty, wait 10 seconds and, when the image is loaded on the screen, it takes the shot of the entire window in the desired format.

#!/usr/bin/env bash
chvt 1
sleep 10
DISPLAY=:0.0 \
XAUTHORITY=/run/user/125/gdm/Xauthority \
import -window root gdm_shot.png

As you can see, the script sets the $DISPLAY variable to the display number that gdm3 is using and also sets the $XAUTHORITY variable to the file used by gdm3 to gain access to its X server. It's a little different from the previous answers because gdm3 changed its display number and the place where it stores its Xauthority file. That was a little tricky to find out.

We used the imagemagick import command instead of xwd because it not just take the shot, but converts it to .jpg or .png, for example, in one go.

Finally, after you set the script to be executable, such as, chmod +x gdm_screenshot.sh, you will have to logout from your current gnome-session and go to any available console(tty), pressing Ctrl+Alt+F2, for example. After that, you'll need to login and run the script as root with sudo ./gdm_screenshot.sh.

You'll end up with an .png image file of you GDM3 screen in the directory where you run the script.

Here is the screenshot I took when I run this script for the first time.

enter image description here

  • gdm3 in Ubuntu 22.10 (and probably some earlier versions) allows you to take a screenshot from the keyboard. @thiggy01 or anyone: do you know where those screenshot image files might be placed?
    – rphair
    Commented Mar 22, 2023 at 10:25

I edited "/etc/mdm/Init/Default" and added:

scrot -d 5 -e 'mv $f /root' &

before the line with "exit 0".

The next time I login, I count to five, beep, and I got my screenshot in "/root".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .