Reattaching to a still attached GNU Screen session

Josh Sherman
1 min read
Command-line Interface

While tmux is my daily driver for local terminal multiplexing, I still use GNU screen when I’m working on remote servers. The primary reason for this is to avoid nesting tmux sessions. I can use tmux locally, ssh to a remote server, start up a screen session and I’m off to the races.

Where things came to a grinding halt recently, was when I was disconnected from a remote server. No big deal, ssh back out and use screen -r to reattach to the now disconnected session.

No dice. The screen session was still showing as attached for some reason, and it couldn’t be resumed. Passing in the screen session’s ID didn’t help matters.

With the screen session attached, the only logic way to go about it would be to detach the session. To do so, I found the ID of the session with the -ls argument:

% screen -ls
There is a screen on:
	22381.pts-6.server	(Attached)

To detach the still attached session and then reattach, simply run:

% screen -D 22381
[22381.pts-6.server power detached.]

% screen -r

Or you can streamline things by chaining the two arguments together:

% screen -Dr 22381

Which will attempt to reattach, detaching any attaching sessions if need be.

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles