10

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 ?

5
  • Do you see the remote system suspend or sleep? I also noticed SSH connections to drop the link after a while idle. I solved this issue by installing and using screen on the remote machine. Might work for you as well.
    – user86969
    Commented Mar 6, 2015 at 10:01
  • The system go to sleep (no more log during the sleep time) and the nic came down. So using screen will not help me. Commented Mar 6, 2015 at 10:45
  • Then disable power savings in your power management applet. The name of the latter depends on what desktop environment you are using: KDE, GNOME, Xfce, LXDE...
    – user86969
    Commented Mar 6, 2015 at 23:54
  • The F21 system actually goes into some powersave mode? Or does the F21 SSH server just drop the connection due to inactivity? Have you tried setting a ServerAliveInterval?
    – rickhg12hs
    Commented Mar 7, 2015 at 6:24
  • The F21 system goes into PM Mode and before entering sleep mode F21 stop the network interface. As i don't log into the Graphical environment (the server is in multi-user target, not graphical.target) changing option in desktop environment like GNOME, KDE, will not help. Commented Mar 8, 2015 at 12:15

3 Answers 3

3

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
3

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.

2
  • Besides not working on my Fedora 25, these commands actually caused the system to become unstable while sleeping. Whenever I press the "Sleep" button on my keyboard, the screen gets black with strange characters printed each time I press "Sleep" or "Wake" again. Even worse, if I ever manage to get successfully back to my Gnome desktop, all the applications are closed and unsaved work lost. To undo the commands, I simply repeated them with unmask instead of mask. Commented Mar 13, 2017 at 19:50
  • There are no such targets in fedora 26 Commented Jul 13, 2017 at 1:26
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .