When we have to take screenshots in Ubuntu, we usually use the Screenshot application or the Print Screen utility. This way of taking screenshots is mostly helpful but it lacks one feature; taking screenshots of the login and lock screens. Sometimes taking such screenshots becomes extremely important; for example, a few days back I was writing a tutorial on how to change the background image of the login and lock screens. I needed to capture the before and after images of the tutorial and came up with a workaround that I would like to share here. This tutorial will teach you the following few things:

  • Taking a screenshot of the lock screen
  • Taking a screenshot of the login screen

Please note that we are performing the steps described in this tutorial on an Ubuntu 18.04 system.

Taking a Screenshot of the Lock screen

Taking a screenshot of the Ubuntu lock screen is fairly simple. Follow these steps to do so through the Screenshot application:

Open the Screenshot application from the Ubuntu Applications list. It is the default screen capturing application that comes with the latest versions of Ubuntu.

Set the “Grab after a delay of” value to 10 seconds:

Grab after delay off

Lock your computer through the Super(windows)+L shortcut.

Try unlocking the system by hitting any key within 10 seconds.

Your lock screen will be captured. When you unlock your computer, the screenshot application will ask you to save the image to the desired location. You can choose to copy the image to the clipboard as well.

Captured lock screen

Taking a Screenshot of the Login Screen

We will install and use the ImageMagick tool to take a screenshot of our Login screen by following these steps:

Open the Terminal through Ctrl+Alt+T or the Ubuntu Dash.

Enter this command to install the ImageMagick tool if it is already not installed on your system:

$ sudo apt-get install imagemagick

The next step is to create a script that captures your screen after 10 seconds of running it. Create a new text file in your home directory and enter the following script in it:

chvt 7; sleep 10s; DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 xwd -root -out ~/loginscreen.xwd; convert ~/loginscreen.xwd ~/loginscreen.png; rm ~/loginscreen.xwd

Note: This script can only run on a lightdm display, therefore you will need to switch to lightdm display manager through the following command:

$ sudo dpkg-reconfigure lightdm

You can use the same dpkg-reconfigure command to switch back to gdm3

Save this file by the name of screencapture.sh.

In this tutorial, I have used the graphical Text Editor application to create this script.

Before running a script in Linux, we need to give it permission to be executed. We will be giving executable permission to screencapture.sh script through the following command:

$ sudo chmod +x screencapture.sh

Change mode of our screen capture script

The next step is to restart your system.

Press Ctrl+Alt+F2 on the login screen to shift to virtual command line console.

Login by providing username and password and then enter this command:

$ sudo ./screencapture.sh

Stay on the login screen for 10 seconds as the time delay for screen capturing has been set to 10 seconds in our .sh script. After that, the screenshot by the name of loginscreen.png will be saved in your home folder. If that doesn’t work, try logging in once for the screenshot to be captured.

Screenshot of login screen

This image shows the .png file captured through this tutorial. In this tutorial, we have learned how customizing our screenshot application and running a simple script can help us in capturing the seemingly impossible screenshot of our Ubuntu login and lock screens.

How to Take Screenshots of Lock and Login Screens in Ubuntu 18.04