Every sysadmin and developer who's worked with unreliable networks knows this frustration: your SSH session drops, but your precious screen
session refuses to reattach. The standard screen -D -RR
command hangs indefinitely, leaving you staring at an unresponsive terminal.
The issue typically occurs when:
- The socket file in
/var/run/screen/S-username/
gets corrupted - Process permissions become misaligned after abrupt disconnects
- Network timeouts don't properly clean up the session
When standard reattachment fails, try this sequence:
# First attempt graceful detach
screen -D
# If that hangs, find all screen processes
ps aux | grep '▼显示creen' | awk '{print $2}' | xargs kill -9
# Clean up socket files
rm -f /var/run/screen/S-$(whoami)/*
# Then retry
screen -D -RR
If the standard approach fails, try specifying the exact session:
# List available sessions
screen -ls
# Reattach specific session forcefully
screen -r -d 12345.pts-1.server
Add these to your ~/.screenrc
to minimize issues:
# Increase keepalive packets
deflogin on
autodetach on
altscreen on
# Reduce timeout to 30 seconds
escape ^Zz
msgwait 30
For persistent screen issues, consider tmux
as a more resilient alternative:
# Basic tmux commands:
tmux new -s session_name
tmux attach -t session_name
# Detach with Ctrl-b d
For Putty users, these settings help prevent disconnections:
- Connection → Seconds between keepalives: 30
- Connection → Enable TCP keepalives
- Terminal → Features → Disable anti-idle (OFF)
As a developer working with remote servers through PuTTY, I frequently encounter unstable wireless connections. GNU Screen has been my lifeline for maintaining persistent sessions, but sometimes reattaching becomes impossible. The classic screen -D -RR
command just hangs indefinitely, leaving me stranded.
When this happens, several processes might be involved:
$ ps aux | grep screen
user 1234 0.0 0.1 12345 6789 ? S Jan01 0:00 SCREEN -d -m
user 1235 0.0 0.1 23456 7890 pts/1 S+ Jan01 0:00 screen -D -RR
The session exists but becomes unresponsive, often due to:
- Terminal state corruption
- Permission issues
- Broken pipe connections
Method 1: Forceful Detach and Reattach
Try this sequence:
$ screen -D # force detach
$ screen -r # attempt reattach
$ screen -list # verify session status
Method 2: Kill All Screen Processes
More aggressive approach:
$ pkill -9 screen
$ rm -f /run/screen/S-$USER/*
$ screen -wipe
$ screen -Rd
Method 3: Terminal Reset
Sometimes the terminal needs resetting:
$ reset
$ stty sane
$ screen -r
Add these to your .screenrc
:
autodetach on
defescape ^Zz
zombie az
For PuTTY specifically, configure:
- Seconds between keepalives: 30
- Enable TCP keepalives
- Disable Nagle's algorithm
Consider these more modern alternatives:
$ tmux new -s mysession
# or
$ byobu
Both handle network interruptions more gracefully than GNU Screen.