I'm wondering if this is possible. I'd like users to be able to launch screen on some of our hosts for the purpose of multiplexing their terminal login sessions. However, I don't want them to be able to detach the screen and leave it running in the background.

The reason for this being that the only way to log in to these machines is through a cluster job submission system, so if a screen becomes detached and the user logs off the only way to get back would be if they happened to land back on the same node on their next job submissions.

echo autodetach off >> ~/.screenrc

Read the screen manpage for autodetach. This will make sure it simply kills everything if their connection is disabled.

You'll still want the other solutions mentioned...

| improve this answer | |
  • This combined with with rebinding the detach key will probably do what I want. – Kamil Kisiel Jun 25 '09 at 23:19

You can do a 'soft' disable of detaching by putting

bind d

in .screenrc, which removes the default ^A D keybinding for detach. Or maybe

bind d echo Don't detach screens, it won't work because of the cluster.

Doing a hard disable of detach, including the command line forms, would take forking your own version of screen and coding out the capability. Which, y'know, can be done, it being an open source project and all.

| improve this answer | |
  • 3
    +1 for mentioning custom modifications to an open source project. Yay open source! – Evan Anderson Jun 25 '09 at 18:05

Here is a hack you could put into a bash script and run every minute with cron to kill detached sessions. Not the cleanest solution though :-P

screen -S $(screen -ls | grep Detached | awk '{ print $1}') -X kill
| improve this answer | |

They'll always be able to just disconnect without closing their terminal(s), unless you hack auto-kill into screen of course.

| improve this answer | |
  • The dirty hack of turning off autodetach... – womble Jun 26 '09 at 0:19

Since detaching screen leaves the user logged in, you could add into the login script a check to see which server the user is already logged in to. This would be more work than just disabling detach, but would be far more useful to your users.

An idea for the script: iterate through the servers, greping the outpot of who, and then logging the user in to the server that reports them logged in first; otherwise, log them in as they would be now (to handle when a user logs out cleanly).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.