I've run into the problem where I have users logging in to servers under customer accounts, opening a screen session as that user, and then never closing it. Ordinarily this wouldn't be much of a concern, however we're running into an issue where if a customer is migrated off the server [which deletes their user account] with an active screen session under their username that screen session sits idle. While that's still not much of a problem there is yet another step in this clustercuss.

If a client that was previously resident on a server, which has an old screen session still active, is migrated back to the server screen refuses to start because /var/run/screen/S-username still exists and is owned by the old UID, and the user [with a spanking new UID] isn't allowed to touch any of these files in their named directory.

I've tried:

  • Simply killing the screen processes, but that does not clean up /var/run/screen/S-username.
  • To find some combination of screen arguments that will let me gracefully kill these sessions, but screen does not want to let me touch anything but the current user's sessions, even if I'm logged in as root.
  • sudo -u '#uid' screen -r but sudo will not let you do anything if you specify a nonexistant UID.

How can I make screen shut down properly and clean up all of its files when the user no longer exists?

  • How are these users being migrated? Instead of killing it after the fact, can't you just fix the migration tool to kill off any processes running as that user before the migrate completes?
    – Zoredache
    Sep 27, 2013 at 22:56
  • @Zoredache Hello again, still Plesk, so everything's buried in their proprietary binaries and RoundCube-protected PHP sources.
    – Sammitch
    Sep 27, 2013 at 23:12

2 Answers 2


If you're fine with killing them off and really just want a way to deal with the unowned sockets sitting in /var/run/screen, I would just set up a cron job using find with the -nouser flag to clean up the old files:

# touch owned notowned && chown 12345:54321 notowned
# ls -l
total 0
-rw-r--r-- 1 12345 54321 0 Sep 27 21:59 notowned
-rw-r--r-- 1 root  root  0 Sep 27 21:59 owned
# find . -nouser
  • Of course this only works if the UID of the previous account hasn't gotten re-used by another account.
    – Zoredache
    Sep 27, 2013 at 22:59

Does screen -wipe do what you're looking for? It works well for removing defunct screen processes.

# screen --help |grep wipe
-wipe         Do nothing, just clean up SockDir.

You must log in to answer this question.

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