The error occurs because the terminal device (/dev/ttys002) you're trying to use with screen is owned by root, but you're logged in as a non-root user via SSH. Here's how to resolve it:
Quick Fix (Recommended)
-
Reconnect via SSH with -t flag (forces pseudo-terminal allocation):
ssh -t your_username@hostname
This usually assigns a correctly owned terminal (e.g., /dev/ttys003 with your user).
-
Run screen again:
screen
If the Issue Persists
Option 1: Use sudo to Correct Ownership (Temporary Fix)
# Identify your current terminal (e.g., /dev/ttys002)
tty
# Change ownership (replace /dev/ttys002 with your terminal)
sudo chown $(whoami) /dev/ttys002
Note: This resets on disconnect. Repeat if needed.
Option 2: Use script to Create a New Terminal
script /dev/null # Creates a new pseudo-terminal owned by you
screen # Now run screen
Option 3: Verify SSH Terminal Allocation
Ensure your SSH client isn’t blocking TTY:
- Add
RequestTTY yes to ~/.ssh/config on your local machine:
Host *
RequestTTY yes
Why This Happens
- SSH assigns terminals dynamically (e.g.,
/dev/ttys002, /dev/ttys003). Occasionally, a terminal may retain root ownership from prior sessions.
screen requires write access to your terminal device. Non-root users can’t access root-owned terminals.
Prevention
- Always use
ssh -t or configure RequestTTY yes in SSH to ensure proper terminal allocation.
- Avoid manual operations as root on terminals used by non-root users.
After trying these steps, screen should work correctly. Let me know if you need further assistance!