[SOLVED] Why is Screen closing all detached screens after I close my SSH Client (Putty)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why is Screen closing all detached screens after I close my SSH Client (Putty)
Hi everybody,
So, I started I little project in Debian with my friends. We suposed to run a wowserver to play together and remember the old times. Long history short.
First we where using a Mint linux in another VPS provider. But because of high ping, we changed. This vps uses Debian 8.7. Same hardware as the other one.
I installed everything in the same way.
I run screen -AmdS to start the server (It needs 2 windows to work)
Everything fine, screen -ls show both screens detached from session.
By the minute I type exit or close the SSH client (Putty in my case), the screens are instantly terminated. Everyone gots DC.
I used to do the same commands in the other VPS, I could just close putty, relog putty, type screen -ls and the screens would be there.
I don't know how to configure my new vps to work like that, I don't know what can be causing that. After days of google research, heres a small list of stuff i tried:
nohup (Don't know how to use properly, followed some tips, no deal)
tmux
disown
screen (offcourse)
add session timeout line in sshd_conf (+ssh_conf)
Old system information uname -a
Linux vps58ed942a796dd 2.6.32-042stab123.1 #1 SMP Wed Mar 22 15:21:30 MSK 2017 x86_64 GNU/Linux
New system information uname -a
Linux vps3755 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2+deb8u2 (2017-06-26) x86_64 GNU/Linux.
Hope anyone can help, It kinda sux need my laptop on to keep a server running in another machine.(And pointless)
The output from "lsb_release -rd" would help more, but since you mention Debian 8.x you're using a version with systemd. systemd kills all your processes on the way out unless the system has been configured to restore the normal behavior of not killing them. It kills even the ones you've told to stay with nohup and such. If it is the case that systemd is killing your processes, then you'll have to look for the right place to put "KillUserProcesses=no" or some other mitigation.
The output from "lsb_release -rd" would help more, but since you mention Debian 8.x you're using a version with systemd. systemd kills all your processes on the way out unless the system has been configured to restore the normal behavior of not killing them. It kills even the ones you've told to stay with nohup and such. If it is the case that systemd is killing your processes, then you'll have to look for the right place to put "KillUserProcesses=no" or some other mitigation.
nano /etc/systemd/logind.conf
went here, and actually there was a #KillUserProcesses=no
So I removed the #, saved the file and reboot the system (Because this is the way I think changes are applied)
started screen -AmdS server
Closed putty, and the processes died.
That might have to be set via one of their own tools, such as loginctl https://www.freedesktop.org/software...#enable-linger
I'm not sure though. I use Devuan nowadays where I used Debian and don't have Debian anywhere any more beccause of systemd.
What happens when you try to manually control systemd when you run tmux or screen in a detached session before logging out?
Code:
systemd-run --scope --user screen -AmdS server
or
Code:
systemd-run --scope --user tmux new-session -Ads server
When you re-connect to the machine are the sessions still there?
That might have to be set via one of their own tools, such as loginctl https://www.freedesktop.org/software...#enable-linger
I'm not sure though. I use Devuan nowadays where I used Debian and don't have Debian anywhere any more beccause of systemd.
What happens when you try to manually control systemd when you run tmux or screen in a detached session before logging out?
Code:
systemd-run --scope --user screen -AmdS server
or
Code:
systemd-run --scope --user tmux new-session -Ads server
When you re-connect to the machine are the sessions still there?
Failed to create bus connection: Connection refused
when I try to start with both commands.
loginctl list-sessions
0 sessions listed.
loginctl list-users
0 users listed.
loginctl list-seats
seat0
Don't trying anything, because is a unknow territory for me, don't want to screw up anything.
Basically someone filed this as a bug with Debian and the response was that this was a feature of systemd and not a bug. Though it changed traditionally default behavior.
Anyway, they say that setting "KillUserProcesses=no" in logind.conf and to enable "lingering" via loginctl will restore this functionality
From the loginctl manpages it looks like running
Code:
loginctl enable-linger
should do it. And then you will probably need to restart the service for it to work
Code:
systemctl restart systemd-logind
Last edited by TheEzekielProject; 07-16-2017 at 03:00 PM.
Basically someone filed this as a bug with Debian and the response was that this was a feature of systemd and not a bug. Though it changed traditionally default behavior.
Anyway, they say that setting "KillUserProcesses=no" in logind.conf and to enable "lingering" via loginctl will restore this functionality
From the loginctl manpages it looks like running
Code:
loginctl enable-linger
should do it. And then you will probably need to restart the service for it to work
Code:
systemctl restart systemd-logind
In logind.conf it was already KillUserProcess=no (With #) I don't know if I should keep the # or remove it.
The loginctl enable-linger root? Is that right? If I type without root it says to few arguments.
Yes, I would remove the "#" to enable that option. And yes, you would enter your username
Just tried it, still not working.
After reading the link you posted, I read something about systemd-run. But still not figured out how it works
lingering is enable, the options to kill processes is deactivated, the service was restarted. No success.
Just tried it, still not working.
After reading the link you posted, I read something about systemd-run. But still not figured out how it works
lingering is enable, the options to kill processes is deactivated, the service was restarted. No success.
I'll experiment with this at some point, since I use Debian on all of my computers (but I don't use screen yet).
One thing to clarify the previous advice is:
Whenever you modify /etc/systemd/logind.conf, you must run the following for the changes to be used:
Code:
systemctl restart systemd-logind.service
Your confusion about "#" is that "#" comments out code. That way, a lot of example lines can be included in a config file without actually having them do anything at all. The basic idea is that you can uncomment the line by removing the "#", and also modify the line if desired.
If you don't already know this, then it can look confusing.
Also, in some config files, position is important. There are sometimes lines that look like [XDMCPServer] or something, which specify that the following lines only apply to XDMCPServer
or something. If you modify or put lines after one of those, they will only apply to something you don't expect and will not modify what you want.
However, in /etc/systemd/logind.conf, there is only one such section. Therefore, it is unlikely that you have the position wrong. So long as your customized configuration lines are after the [Login] line, it should be good.
I'll experiment with this at some point, since I use Debian on all of my computers (but I don't use screen yet).
One thing to clarify the previous advice is:
Whenever you modify /etc/systemd/logind.conf, you must run the following for the changes to be used:
Code:
systemctl restart systemd-logind.service
Your confusion about "#" is that "#" comments out code. That way, a lot of example lines can be included in a config file without actually having them do anything at all. The basic idea is that you can uncomment the line by removing the "#", and also modify the line if desired.
If you don't already know this, then it can look confusing.
Also, in some config files, position is important. There are sometimes lines that look like [XDMCPServer] or something, which specify that the following lines only apply to XDMCPServer
or something. If you modify or put lines after one of those, they will only apply to something you don't expect and will not modify what you want.
However, in /etc/systemd/logind.conf, there is only one such section. Therefore, it is unlikely that you have the position wrong. So long as your customized configuration lines are after the [Login] line, it should be good.
Thanks for all explanation. After hours of reading I managed to solve it. I actually dont know how, because I did so many things (All in this post also)
But the last thing I did and solved (After removing the #, enable lingering) was:
apt-get install libpam-systemd dbus
grep -i UsePAM /etc/ssh/sshd_config
systemd-run --scope --user myservicehere (exactly like the first guys said, but It was notworking because of this libpam-systemd dbus and UsePAm seting).
Thanks everyone for the help, hope this helps the others.
Thanks for the followup post with your solution. It is interesting to know. It sure is annoying that its promoters get away with calling it an init system. For my tastes that utility has too many scope and design flaws, not just bugs, so I moved to Devuan. You might consider it for future projects. It's mostly a seemless transition from Jessie. Aside from being free of systemd it is identical to Debian GNU/Linux. (No kFreeBSD yet)
I see there is another, old thread about systemd still active that you may want to visit.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.