Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been able to successfully hibernate and resume my Ubuntu 12.04 Desktop PC using procedure that I've documented in this answer. However, I now have a problem that whenever the PC resumes, it does not locks the screen.

How can I lock the screen after the system resumes back from hibernation?

share|improve this question

I have added an alias into ~/.bashrc file

alias hibernate='sudo echo "Hibernating..."; gnome-screensaver-command -l; sudo pm-hibernate;'

So that it locks the screen before hibernating.

share|improve this answer

I've been able to workaround this issue, by using the following command

sudo pm-hibernate; gnome-screensaver-command -l

Do note that, you should run this as a normal user and not as root user for locking to work, because by default in Ubuntu, there is no password for the root user so after resume, lock-screen can be unlocked by simply shaking the mouse.

share|improve this answer
+1 Thanks a lot for the note that screensaver have to be run as normal user (not as root). It completely makes sense... That's the point... Thank you! – zbynour Jun 10 '15 at 12:56
Worked fine for me: (Ubuntu 15.04 - 3.19.0-25-generic #26-Ubuntu SMP Fri Jul 24 21:17:31 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux) – cantoni Aug 6 '15 at 12:00

i have another workaround. i copied this from /etc/acpi/ to /etc/acpi/ just before pm-hibernate

if [ x$LOCK_SCREEN = xtrue ]; then
    if pidof xscreensaver > /dev/null; then
    for x in /tmp/.X11-unix/*; do
        displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
        if [ x"$XAUTHORITY" != x"" ]; then
        export DISPLAY=":$displaynum"
        . /usr/share/acpi-support/screenblank

now i can hibernate with lock from power menu or a sleep button

share|improve this answer
It works beautifully on 14.04 with encrypted swap (and home), however I can't see there – just to share experience and push some keywords. – AliNa Oct 1 '14 at 19:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.