How do I force detach Screen from another SSH session?

T. Brian Jones picture T. Brian Jones · Dec 27, 2013 · Viewed 128.8k times · Source

I had Screen running inside an SSH session. Terminal froze. After restarting Terminal, that Screen session still thinks it's attached. Maybe it is. Perhaps I don't really know what that means.

I'd like to attach to that Screen session from a fresh SSH login. I do not want to kill that Screen session as important things are happening over there. : )

The options I think I have ( none of which I know how to solve ):

  • How do I detach that Screen session?
  • How do I kill the SSH session that that Screen session is attached to?

Answer

Matt S. picture Matt S. · May 2, 2014

As Jose answered, screen -d -r should do the trick. This is a combination of two commands, as taken from the man page.

screen -d detaches the already-running screen session, and screen -r reattaches the existing session. By running screen -d -r, you force screen to detach it and then resume the session.

If you use the capital -D -RR, I quote the man page because it's too good to pass up.

Attach here and now. Whatever that means, just do it.

Note: It is always a good idea to check the status of your sessions by means of "screen -list".