Technical

Fix ‘Must be connected to a terminal’ when attaching screen inside a Proxmox LXC container

Fix ‘Must be connected to a terminal’ when attaching screen inside a Proxmox LXC container

Getting the “Must be connected to a terminal” error when you try screen -x inside a Proxmox LXC? It’s because pct exec doesn’t allocate a tty—you need to use pct enter or force a tty allocation.

Why the hell does this happen?

When you run pct exec <container-id> -- bash, Proxmox just fires off a command inside the container without giving it a terminal. Screen needs a real terminal to attach to, and without one it throws that stupid error. It’s not a screen bug—it’s Proxmox being too minimal with its exec.

The easy fix: use pct enter

Instead of pct exec, just do:

pct enter <container-id>

That drops you into a proper login shell with a tty allocated. From there, screen -x works like it should. This is the simplest way and I’d stick with it unless you have some script that needs exec.

Close-up of a retro computer screen displaying MS-DOS commands with a vibrant keyboard.

If you really need pct exec

Sometimes you’re scripting and can’t use enter. There is no tty flag on pct exec — the only options it takes are --keep-env and the extra args — so you have to allocate the pseudo-terminal yourself. script does it in one line:

pct exec <container-id> -- script -qc "screen -x" /dev/null

You can check that it worked before you bother with screen at all. Without the wrapper the container reports no terminal, with it you get a real pty:

pct exec 109 -- bash -c 'tty'
not a tty

pct exec 109 -- script -qc 'tty' /dev/null
/dev/pts/3

lxc-attach -n <container-id> is the other way in — it attaches to the container’s namespaces directly and gives you a terminal, which is effectively what pct enter wraps. As a one-liner:

lxc-attach -n <container-id> -- bash -c "screen -x"
Close-up image of ethernet cables plugged into a network switch, showcasing IT infrastructure.

Don’t overcomplicate it

Interactively, pct enter is the right tool and there is nothing to think about. The script wrapper above is not an extra layer for its own sake — it is the thing that supplies the terminal pct exec refuses to, so reach for it when you are scripting and skip it when you are not. setsid is the one that genuinely does not help here: it detaches from the controlling terminal, which is the opposite of what screen is asking for. If you hit this often enough to be annoyed, alias the script wrapper inside the container and stop thinking about it. This is your homelab—keep it simple.

If you’re dealing with other weird Proxmox boot issues, check out Proxmox Stuck at ‘Loading Initial Ramdisk’: Diagnosis and Fix. For more of the same “why isn’t this obvious” LXC territory, there’s fixing Beszel agent RAM reporting and resizing a container.

Nguyen

I write two things here: notes from a homelab that mostly runs Proxmox, and essays in Vietnamese about a country I left. The technical posts are whatever broke that week, written down so it costs you less time than it cost me.

All posts →

Leave a comment

Comments are reviewed before they appear. Your email is never published.