Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Wanted: Reasonably clean way to keep my laptop from sleeping when I'm logged in remotely

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
beej
Posts: 2
Joined: 2022-06-15 16:26

Wanted: Reasonably clean way to keep my laptop from sleeping when I'm logged in remotely

#1 Post by beej »

Hi

I'm ssh'ing into my laptop running Debian 11 and lose control when said laptop goes to sleep.

I've read the "Disable suspend and hibernation" section of https://wiki.debian.org/Suspend and know that I can temporarily turn off this functionality, but what if I forget to turn it back on?

I'd love some clean-ish way to ensure my laptop doesn't go to sleep while I'm actively controlling it remotely.

Any help much appreciated.

Thanks for reading me!

codejp3
Posts: 24
Joined: 2022-12-28 06:29
Been thanked: 2 times

Re: Wanted: Reasonably clean way to keep my laptop from sleeping when I'm logged in remotely

#2 Post by codejp3 »

Here's the clean-ish way I've ever found. I used to use this when I had a old laptop acting as a temporary home dev server.

Install the "caffeine" package. If you use Gnome, there's also a shell extension available.

Try it out locally to make sure it's actually working right with any of these commands:

Code: Select all

caffeinate COMMAND

(to prevent suspend/hibernate only until whatever COMMAND you specified is done running)

Code: Select all

caffeinate -t 144000
(to prevent suspend/hibernate for X number of seconds (144000 = 4 hours) )


It doesn't always work right with all desktop environments, so test it out and debug it first if needed.


Once you've confirmed it's working, add this to your ssh_config in /etc/ssh/ssh_config on laptop/server within the "Host *" section:

Code: Select all

PermitLocalCommand yes
LocalCommand caffeinate -w $PPID &

You're basically saying: " hey ssh server - allow executing local commands whenever anyone ssh's into this machine".
ssh server say: "ok, what commands do you want me to allow?"
then you say back to it: "prevent hibernate/shutdown (caffeinate) but only for the current process id of this active ssh connection (-w $PPID) and run it invisibly in the background (&)"


From that point on, anytime you ssh in, hibernate/suspend will be prohibited. Hibernate/suspend return back to their default settings the second you end your ssh session. And it all happens automatically and invisibly with zero effort on your part.

Post Reply