I connect to a Fedora 21 workstation with SSH, but after several minutes not using the connection the system go to sleep and I loose my connection.
So how can I disallow completely the system to go into suspend/sleep mode ?
I resolv my problem with creating a init.d script that use the systemd-inhibit command:
#!/bin/bash
nohup systemd-inhibit --why="Disable sleep" --mode=block /usr/bin/bash -c "while true; do sleep 120; done" >/dev/null 2>&1 &
exit 0
use:
sudo systemctl mask suspend.target
sudo systemctl mask sleep.target
because:
Systemd manages all of this. There's a million ways for something to trigger a shutdown, including gnome/kde, NetworkManager
and of course systemd itself. The sleep and suspend targets, just like shutdown are "static" i.e. core built-in units that can not be disabled. You can however mask them and prevent systemd
from ever entering them.
unmask
instead of mask
.
Commented
Mar 13, 2017 at 19:50
EDIT: Removed --what=idle
from the command - apparently this is not enough. The default is --what=shutdown:sleep:idle
, which works better (but --what=sleep:idle
should work too).
Old question, but another variant of the systemd-inhibit solution is to put the following in ~/.profile
(in my case, just before byobu is launched). Then, sleep will be inhibited as long as there are login shells open (i.e. mostly SSH sessions unless you also log in from the non-GUI console).
# Inhibit idle sleep. This background process waits for the current shell to exit.
nohup systemd-inhibit --who=Bash --why="Byobu running" tail --pid=$$ -f /dev/null &
I found out about the tail --pid
part here: https://stackoverflow.com/a/41613532/827828
screen
on the remote machine. Might work for you as well.ServerAliveInterval
?