How to activate screen with user enviornment?

I run a screen with a few screens, every boot time, and it works, but when I login and if I create new screen it will load without shell, so I basically have to do exec bash to get nice working terminal. Is it possible to activate screen via cron/@boot so that it will be started as if I start it from terminal my self.
I start screen in rc.local like following:

  screen -dmS d bash -c 'ytop; exec bash'
  screen -S d -X screen 1 bash -c 'podman run -it --name f35_ovpn; exec bash'

Are you in the dialout group with the user you call it?

No screen gets executed as a root, and when I login and su I enter screen. Neither my account nor root is not in dialout group

I do not know how you use rc.local ? Just know that the old (before systemd) way it is depreciated.

See on the bottom the “update” section too.

I do not know which DE you are using? … in my case on Gnome & Mate I can activate under the “Terminal preferences” , Command > Run command as a login shell.

Are you in the dialout group with the user you call it?

About the dialout group I mentioned because last time I used Screen I was connecting to an UART chip via serial. So the group was still needed to be able to do so. Seams to be old stuff from the modem times.

To add to what @ilikelinux is saying.

You may also want to take a look at: systemd/User - ArchWiki

Thanks

It’s a server environment, so I don’t use DE. Systemd has an option to activate rc.local service
systemctl enable rc-local.service so that you can run any manual scripts on startup.

But same happens if I run/start screen from crontab. Looks like that it doesn’t start as if from interactive session, so I wonder how to activate screen as if manually, at terminal I would type screen -S myscr

In the rc.local have you tried,
su - username -c commands you want to run

1 Like

Yes I have tried but result is the same. No environment.

I’m curious if reset in this context helps reinitialize the bashrc/profile for your shell? Otherwise you can try:

. ~/.bash_profile; . ~/.bashrc ; <some other command>

Here’s something I was playing with, make a user systemd service:

[Unit]
Description=Playing around with screen

[Service]
Type=simple
ExecStart=%h/bin/screen.bash

[Install]
WantedBy=default.target

screen.bash

#!/bin/bash
screen -d -m -S bash 'bash'

make the script executable
enable the user service
systemctl --user enable screen.service
enable lingering for your user
loginctl enable-linger $USER

I’ve tried this in crontab, but it is the same. New screen again is without bash environment

But is it working for you?
For me it didn’t even start the screen. I didn’t restart computer, I’ve just did systemct --user start screen.serviceand I did enable it and loginctl enable-linger $USER (although I don’t know what it does.

what does
systemctl --user status screen.service
indicate

man loginctl |grep -B2 -A2 linger

       enable-linger [USER...], disable-linger [USER...]
           Enable/disable user lingering for one or more users. If enabled for a specific user, a user manager is spawned
           for the user at boot and kept around after logouts. This allows users who are not logged in to run long-running
           services. Takes one or more user names or numeric UIDs as argument. If no argument is specified,
           enables/disables lingering for the user of the session of the caller.

I get

○ screen.service - Playing around with screen
     Loaded: loaded (/etc/xdg/systemd/user/screen.service; enabled; preset: disabled)
     Active: inactive (dead) since Thu 2023-01-12 17:25:58 CET; 6s ago
   Duration: 5ms
    Process: 774353 ExecStart=/etc/cron.b/tst-scr (code=exited, status=0/SUCCESS)
   Main PID: 774353 (code=exited, status=0/SUCCESS)
        CPU: 6ms

Jan 12 17:25:58 bs5 systemd[3978]: Started screen.service - Playing around with screen.

Sorry about the other, I could’ve swore that worked earlier but it did not today.

This appears to work through reboots and manual stop/starts.


[Unit]
Description=Screen Service
After=multi-user.target

[Service]
Type=forking
ExecStart=/bin/bash -c "/usr/bin/screen -d -m -S d bash"
Remainonexit=true

[Install]
WantedBy=default.target
1 Like

So it looks like it’s not possible to start screen with user environment via crontab/rc.local/service. It only works when started via interactive terminal. I’ve been trying to find this solution for a while, but no luck, so normally, I have to redo all screens after reboot, but at least it starts some utils, that I need on boot time, namely interactive podman sessions, and some other utils

Would it work to configure autologin on one of the VTs? Then you’d probably also want to have screen auto-lock on startup?

I’m not sure how to do this?