suspend AND lock screen on closing lid in arch/systemd
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
add a comment |
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
Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Sincemod+L
was already assigned toblurlock
for me, it was easy to havemod+S
beblurlock && 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
add a comment |
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
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
arch-linux systemd suspend screen-lock
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. Sincemod+L
was already assigned toblurlock
for me, it was easy to havemod+S
beblurlock && 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
add a comment |
Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Sincemod+L
was already assigned toblurlock
for me, it was easy to havemod+S
beblurlock && 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
add a comment |
2 Answers
2
active
oldest
votes
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.
Thanks, I saw that example but did not realize theExecStart=/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 usexss-lock
(available in Debian, Arch Linux; also Fedora next week) and run that as a user together withi3lock
orslock
.
– Martin Ueding
Mar 26 '16 at 16:58
1
@MartinUeding and @jasonwryan,User
is hardcoded. The assumption that this machine will only be used byjason
(or someone who knows his password, like his girlfriend, for example). Ideally, we'd wantUser
to be whoever initiated the suspend, but I haven't found a solution for that (yet).
– Rolf
Mar 29 '18 at 19:51
|
show 9 more comments
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Thanks, I saw that example but did not realize theExecStart=/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 usexss-lock
(available in Debian, Arch Linux; also Fedora next week) and run that as a user together withi3lock
orslock
.
– Martin Ueding
Mar 26 '16 at 16:58
1
@MartinUeding and @jasonwryan,User
is hardcoded. The assumption that this machine will only be used byjason
(or someone who knows his password, like his girlfriend, for example). Ideally, we'd wantUser
to be whoever initiated the suspend, but I haven't found a solution for that (yet).
– Rolf
Mar 29 '18 at 19:51
|
show 9 more comments
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.
Thanks, I saw that example but did not realize theExecStart=/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 usexss-lock
(available in Debian, Arch Linux; also Fedora next week) and run that as a user together withi3lock
orslock
.
– Martin Ueding
Mar 26 '16 at 16:58
1
@MartinUeding and @jasonwryan,User
is hardcoded. The assumption that this machine will only be used byjason
(or someone who knows his password, like his girlfriend, for example). Ideally, we'd wantUser
to be whoever initiated the suspend, but I haven't found a solution for that (yet).
– Rolf
Mar 29 '18 at 19:51
|
show 9 more comments
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.
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.
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 theExecStart=/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 usexss-lock
(available in Debian, Arch Linux; also Fedora next week) and run that as a user together withi3lock
orslock
.
– Martin Ueding
Mar 26 '16 at 16:58
1
@MartinUeding and @jasonwryan,User
is hardcoded. The assumption that this machine will only be used byjason
(or someone who knows his password, like his girlfriend, for example). Ideally, we'd wantUser
to be whoever initiated the suspend, but I haven't found a solution for that (yet).
– Rolf
Mar 29 '18 at 19:51
|
show 9 more comments
Thanks, I saw that example but did not realize theExecStart=/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 usexss-lock
(available in Debian, Arch Linux; also Fedora next week) and run that as a user together withi3lock
orslock
.
– Martin Ueding
Mar 26 '16 at 16:58
1
@MartinUeding and @jasonwryan,User
is hardcoded. The assumption that this machine will only be used byjason
(or someone who knows his password, like his girlfriend, for example). Ideally, we'd wantUser
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
|
show 9 more comments
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.
add a comment |
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.
add a comment |
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.
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.
answered 26 mins ago
Manoel VilelaManoel Vilela
1417
1417
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Outside of scope so I'm commenting: in i3 it's very easy to assign keybindings to commands. Since
mod+L
was already assigned toblurlock
for me, it was easy to havemod+S
beblurlock && 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