systemd GNU screen autostart with favorite apps

By ValkaTR , 31 July 2026

systemd has ability to manage user units. all the user units will be placed in ~/.config/systemd/user/. this service autostarts screen:

~/.config/systemd/user/screen.service

[Unit]
Description=GNU screen
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/screen -DmS autoscreen -c ~/.screenrc_auto
ExecStop=/usr/bin/screen -S autoscreen -X quit

[Install]
WantedBy=default.target

screen options on start:

-D -m   Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

-S sessionname         When creating a new session, this option can be used to specify a meaningful name for the session.

-c file         override the default configuration file from $HOME/.screenrc to file.

-X   Send  the specified command to a running screen session.

service needs to be enabled:

[user@host ~]$ systemctl --user enable screen.service
Created symlink '/home/user/.config/systemd/user/default.target.wants/screen.service' → '/home/user/.config/systemd/user/screen.service'.

if user is not auto loggged in after a reboot, then the service will not start. to avoid this, lingering has to be enabled:

[user@host ~]$ loginctl enable-linger
[user@host ~]$ loginctl list-users 
UID USER  LINGER STATE    
1000 user yes    active

1 user listed.

to autostart favorite apps after the screen service start, we need a screenrc configuration file:

~/.screenrc_auto

screen -t irc 0 weechat
screen -t mc 1 mc
screen -t process 2 htop
screen -t bash 3

reboot or start the service:

[user@host ~]$ systemctl --user enable screen.service

to attach to running screen sessions, use this command:

[user@host ~]$ screen -x

if your host is remote and you want to attach to screen immediately after ssh, then you need to add '-t' option:

[user@local ~]$ ssh -t user@remote screen -x

-t      Force pseudo-terminal allocation.  This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing  menu  services.

common screen commands:

  • Ctrl+a ? Displays commands and their defaults
  • Ctrl+a : Enter to the command prompt of screen
  • Ctrl+a " Window list
  • Ctrl+a 0 opens window 0
  • Ctrl+a A Rename the current window
  • Ctrl+a a Sends Ctrl+a to the current window
  • Ctrl+a c Create a new window (with shell)
  • Ctrl+a k, Ctrl+a Ctrl+k Destroy current window.
  • Ctrl+a S Split current region horizontally into two regions
  • Ctrl+a | Split current region vertically into two regions
  • Ctrl+a tab Switch the input focus to the next region
  • Ctrl+a Ctrl+a Toggle between current and previous region
  • Ctrl+a [ Enter Copy Mode (use enter to select a range of text)
  • Ctrl+a ] Paste text
  • Ctrl+a Q Close all regions but the current one
  • Ctrl+a X Close the current region
  • Ctrl+a d Detach from the current screen session, and leave it running. Use screen -r to resume

 

Comments