suspend AND lock screen on closing lid in arch/systemd












20















what is the most straightforward way to lock the screen AND suspend when closing the lid? I'm using event hooks in /etc/systemd/logind.conf and successfully suspend upon closing the lid. However I'm lost when it comes to the locking part - am I supposed to enable some screensaver service and how can I trigger two events at once in logind.conf?










share|improve this question

























  • Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

    – pzkpfw
    Dec 20 '18 at 14:31
















20















what is the most straightforward way to lock the screen AND suspend when closing the lid? I'm using event hooks in /etc/systemd/logind.conf and successfully suspend upon closing the lid. However I'm lost when it comes to the locking part - am I supposed to enable some screensaver service and how can I trigger two events at once in logind.conf?










share|improve this question

























  • Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

    – pzkpfw
    Dec 20 '18 at 14:31














20












20








20


3






what is the most straightforward way to lock the screen AND suspend when closing the lid? I'm using event hooks in /etc/systemd/logind.conf and successfully suspend upon closing the lid. However I'm lost when it comes to the locking part - am I supposed to enable some screensaver service and how can I trigger two events at once in logind.conf?










share|improve this question
















what is the most straightforward way to lock the screen AND suspend when closing the lid? I'm using event hooks in /etc/systemd/logind.conf and successfully suspend upon closing the lid. However I'm lost when it comes to the locking part - am I supposed to enable some screensaver service and how can I trigger two events at once in logind.conf?







arch-linux systemd suspend screen-lock






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 4 '13 at 2:47









slm

251k67529685




251k67529685










asked Jul 4 '13 at 1:06









pldimitrovpldimitrov

203125




203125













  • Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

    – pzkpfw
    Dec 20 '18 at 14:31



















  • Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

    – pzkpfw
    Dec 20 '18 at 14:31

















Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

– pzkpfw
Dec 20 '18 at 14:31





Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since mod+L was already assigned to blurlock for me, it was easy to have mod+S be blurlock && systemctl suspend -i instead. So, not when closing the lid, but works very well to choose whether I just want to lock, or lock and suspend.

– pzkpfw
Dec 20 '18 at 14:31










2 Answers
2






active

oldest

votes


















16














There are a couple of examples in the Arch Wiki.



Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.



If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:



[Unit]
Description=Lock the screen on resume from suspend

[Service]
User=jason
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

[Install]
WantedBy=suspend.target


Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.






share|improve this answer


























  • Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

    – pldimitrov
    Jul 5 '13 at 1:24













  • If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

    – CMCDragonkai
    Jan 27 '16 at 5:25











  • @CMCDragonkai you want physlock then...

    – jasonwryan
    Jan 27 '16 at 5:31






  • 1





    This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

    – Martin Ueding
    Mar 26 '16 at 16:58






  • 1





    @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

    – Rolf
    Mar 29 '18 at 19:51



















0














If you use openrc with elogind is there an alternative solution (which is not systemd dependent):



#!/bin/sh
#
# /lib/elogind/system-sleep/lock.sh
# Lock before suspend integration with elogind

username=lerax
userhome=/home/$username
export XAUTHORITY="$userhome/.Xauthority"
export DISPLAY=":0.0"


case "${1}" in
pre)
su $username -c "/usr/bin/slock" &
sleep 1s;
;;
esac


ref: https://gist.github.com/ryukinix/bd0c1ddcbbafdb4149ae70e41b7c822b



I'm posting this because was very difficult to find it a proper way that it works and this thread appears on first results of google about "lock after suspend" or whatever.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f81692%2fsuspend-and-lock-screen-on-closing-lid-in-arch-systemd%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    16














    There are a couple of examples in the Arch Wiki.



    Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.



    If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:



    [Unit]
    Description=Lock the screen on resume from suspend

    [Service]
    User=jason
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/slock

    [Install]
    WantedBy=suspend.target


    Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.






    share|improve this answer


























    • Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

      – pldimitrov
      Jul 5 '13 at 1:24













    • If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

      – CMCDragonkai
      Jan 27 '16 at 5:25











    • @CMCDragonkai you want physlock then...

      – jasonwryan
      Jan 27 '16 at 5:31






    • 1





      This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

      – Martin Ueding
      Mar 26 '16 at 16:58






    • 1





      @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

      – Rolf
      Mar 29 '18 at 19:51
















    16














    There are a couple of examples in the Arch Wiki.



    Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.



    If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:



    [Unit]
    Description=Lock the screen on resume from suspend

    [Service]
    User=jason
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/slock

    [Install]
    WantedBy=suspend.target


    Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.






    share|improve this answer


























    • Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

      – pldimitrov
      Jul 5 '13 at 1:24













    • If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

      – CMCDragonkai
      Jan 27 '16 at 5:25











    • @CMCDragonkai you want physlock then...

      – jasonwryan
      Jan 27 '16 at 5:31






    • 1





      This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

      – Martin Ueding
      Mar 26 '16 at 16:58






    • 1





      @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

      – Rolf
      Mar 29 '18 at 19:51














    16












    16








    16







    There are a couple of examples in the Arch Wiki.



    Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.



    If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:



    [Unit]
    Description=Lock the screen on resume from suspend

    [Service]
    User=jason
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/slock

    [Install]
    WantedBy=suspend.target


    Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.






    share|improve this answer















    There are a couple of examples in the Arch Wiki.



    Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.



    If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:



    [Unit]
    Description=Lock the screen on resume from suspend

    [Service]
    User=jason
    Environment=DISPLAY=:0
    ExecStart=/usr/bin/slock

    [Install]
    WantedBy=suspend.target


    Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 17 '17 at 23:33









    Martin Monperrus

    4451514




    4451514










    answered Jul 4 '13 at 1:40









    jasonwryanjasonwryan

    50k14134188




    50k14134188













    • Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

      – pldimitrov
      Jul 5 '13 at 1:24













    • If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

      – CMCDragonkai
      Jan 27 '16 at 5:25











    • @CMCDragonkai you want physlock then...

      – jasonwryan
      Jan 27 '16 at 5:31






    • 1





      This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

      – Martin Ueding
      Mar 26 '16 at 16:58






    • 1





      @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

      – Rolf
      Mar 29 '18 at 19:51



















    • Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

      – pldimitrov
      Jul 5 '13 at 1:24













    • If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

      – CMCDragonkai
      Jan 27 '16 at 5:25











    • @CMCDragonkai you want physlock then...

      – jasonwryan
      Jan 27 '16 at 5:31






    • 1





      This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

      – Martin Ueding
      Mar 26 '16 at 16:58






    • 1





      @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

      – Rolf
      Mar 29 '18 at 19:51

















    Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

    – pldimitrov
    Jul 5 '13 at 1:24







    Thanks, I saw that example but did not realize the ExecStart=/usr/bin/slock bit refers to locking at first glimpse.

    – pldimitrov
    Jul 5 '13 at 1:24















    If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

    – CMCDragonkai
    Jan 27 '16 at 5:25





    If I suspend and come back, my X display manager has a screen lock, that's great. But what about my ttys? What if I'm logged in, and I suspended and I forgot to exit from my ttys, people could switch to there and continue their operations.

    – CMCDragonkai
    Jan 27 '16 at 5:25













    @CMCDragonkai you want physlock then...

    – jasonwryan
    Jan 27 '16 at 5:31





    @CMCDragonkai you want physlock then...

    – jasonwryan
    Jan 27 '16 at 5:31




    1




    1





    This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

    – Martin Ueding
    Mar 26 '16 at 16:58





    This does work, but only if you are the only user of the system. A cleaner solution is to use xss-lock (available in Debian, Arch Linux; also Fedora next week) and run that as a user together with i3lock or slock.

    – Martin Ueding
    Mar 26 '16 at 16:58




    1




    1





    @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

    – Rolf
    Mar 29 '18 at 19:51





    @MartinUeding and @jasonwryan, User is hardcoded. The assumption that this machine will only be used by jason (or someone who knows his password, like his girlfriend, for example). Ideally, we'd want User to be whoever initiated the suspend, but I haven't found a solution for that (yet).

    – Rolf
    Mar 29 '18 at 19:51













    0














    If you use openrc with elogind is there an alternative solution (which is not systemd dependent):



    #!/bin/sh
    #
    # /lib/elogind/system-sleep/lock.sh
    # Lock before suspend integration with elogind

    username=lerax
    userhome=/home/$username
    export XAUTHORITY="$userhome/.Xauthority"
    export DISPLAY=":0.0"


    case "${1}" in
    pre)
    su $username -c "/usr/bin/slock" &
    sleep 1s;
    ;;
    esac


    ref: https://gist.github.com/ryukinix/bd0c1ddcbbafdb4149ae70e41b7c822b



    I'm posting this because was very difficult to find it a proper way that it works and this thread appears on first results of google about "lock after suspend" or whatever.






    share|improve this answer




























      0














      If you use openrc with elogind is there an alternative solution (which is not systemd dependent):



      #!/bin/sh
      #
      # /lib/elogind/system-sleep/lock.sh
      # Lock before suspend integration with elogind

      username=lerax
      userhome=/home/$username
      export XAUTHORITY="$userhome/.Xauthority"
      export DISPLAY=":0.0"


      case "${1}" in
      pre)
      su $username -c "/usr/bin/slock" &
      sleep 1s;
      ;;
      esac


      ref: https://gist.github.com/ryukinix/bd0c1ddcbbafdb4149ae70e41b7c822b



      I'm posting this because was very difficult to find it a proper way that it works and this thread appears on first results of google about "lock after suspend" or whatever.






      share|improve this answer


























        0












        0








        0







        If you use openrc with elogind is there an alternative solution (which is not systemd dependent):



        #!/bin/sh
        #
        # /lib/elogind/system-sleep/lock.sh
        # Lock before suspend integration with elogind

        username=lerax
        userhome=/home/$username
        export XAUTHORITY="$userhome/.Xauthority"
        export DISPLAY=":0.0"


        case "${1}" in
        pre)
        su $username -c "/usr/bin/slock" &
        sleep 1s;
        ;;
        esac


        ref: https://gist.github.com/ryukinix/bd0c1ddcbbafdb4149ae70e41b7c822b



        I'm posting this because was very difficult to find it a proper way that it works and this thread appears on first results of google about "lock after suspend" or whatever.






        share|improve this answer













        If you use openrc with elogind is there an alternative solution (which is not systemd dependent):



        #!/bin/sh
        #
        # /lib/elogind/system-sleep/lock.sh
        # Lock before suspend integration with elogind

        username=lerax
        userhome=/home/$username
        export XAUTHORITY="$userhome/.Xauthority"
        export DISPLAY=":0.0"


        case "${1}" in
        pre)
        su $username -c "/usr/bin/slock" &
        sleep 1s;
        ;;
        esac


        ref: https://gist.github.com/ryukinix/bd0c1ddcbbafdb4149ae70e41b7c822b



        I'm posting this because was very difficult to find it a proper way that it works and this thread appears on first results of google about "lock after suspend" or whatever.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 26 mins ago









        Manoel VilelaManoel Vilela

        1417




        1417






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f81692%2fsuspend-and-lock-screen-on-closing-lid-in-arch-systemd%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Loup dans la culture

            How to solve the problem of ntp “Unable to contact time server” from KDE?

            ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux