일. 8월 3rd, 2025

Why screen Matters

When working on remote servers via SSH, network disruptions or accidental terminal closures can abruptly terminate running processes. screen solves this by creating persistent terminal sessions that survive disconnections. Your commands continue executing in the background, and you can seamlessly resume work—ideal for long-running tasks like scripts, compilations, or system updates.


Step 1: Installing screen

Most Linux/Unix systems include screen, but if missing:

# Debian/Ubuntu  
sudo apt install screen  

# CentOS/RHEL  
sudo yum install screen  

# macOS (via Homebrew)  
brew install screen  

Verify with: screen --version


Step 2: Core Workflow

Start a New Session

screen -S session_name  # Replace "session_name" with your task (e.g., "data_backup")  

You’re now inside a virtual terminal. Run commands as usual (e.g., python long_script.py).

Detach from Session

Keep processes running while returning to your main terminal:

Press Ctrl + A, then D  

Visually: Ctrl+A → Release → Press D

List Active Sessions

screen -ls  

Output:

There is a screen on:  
    12345.session_name    (Detached)  

Reattach to a Session

screen -r session_name  # Or use the session ID (e.g., 12345)  

Your session resumes exactly where you left off.

Terminate a Session

Exit normally inside the session:

exit  

Or force-kill detached sessions:

screen -X -S session_name quit  

Step 3: Pro Tips

Window Management

  • Create new tabs: Ctrl+AC
  • Switch between tabs: Ctrl+A0-9 (window number)
  • Split panes vertically: Ctrl+A|
  • Navigate panes: Ctrl+ATab

Session Sharing

Collaborate in real-time by granting access:

screen -S shared_session -x  # Attach multiple users to the same session  

Log Output

Record all terminal activity:

Ctrl+A` → `:logfile screenlog.log  # Start logging  
Ctrl+A` → `H`                     # Toggle logging on/off  

Password Protection

Secure sessions with a password:

Ctrl+A` → `:password  

Common screen Commands Cheat Sheet

Command Action
screen -S [name] Create named session
screen -r [name] Reattach session
screen -ls List sessions
Ctrl+A + D Detach session
Ctrl+A + ? Show all keyboard shortcuts

When to Use screen vs. Alternatives

  • Use screen: Long SSH tasks, unstable networks, background processes.
  • ⚠️ Consider tmux: For advanced features (better scripting, pane management).
  • Avoid nohup alone: Lacks session resumption and interactive control.

Conclusion

screen transforms unreliable remote workflows into resilient sessions. No more panic when Wi-Fi drops! Practice core commands first (-S, -r, Ctrl+A+D), then explore splits/windows. Soon, you’ll wonder how you ever worked without it.

> Pro Tip: Always name sessions (-S meaningful_name). Future-you will thank past-you when restoring work! 💻🔒

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다