Resolving “Unable to open pty: No such file or directory” in OpenVZ VPS
Introduction
When attempting to access an OpenVZ virtual private server (VPS) using the vzctl enter command, you may encounter the following error:
vzctl enter <VEID> enter into VE <VEID> failed Unable to open pty: No such file or directory
In this situation, you may also be unable to establish an SSH connection to the VPS from an external system. This issue typically occurs because the pseudo-terminal (PTY) devices required for interactive shell sessions are missing or the udev service inside the container has removed or failed to create the necessary device nodes.
The resolution differs slightly depending on whether the VPS is running a Red Hat-based distribution (such as CentOS) or a Debian-based distribution.
Prerequisites
Before proceeding, ensure the following:
- Root or sudo access to the OpenVZ host node.
- The VPS (container) is running.
- The Virtual Environment ID (VEID) of the affected VPS.
- Basic familiarity with OpenVZ management commands (
vzctl).
You can verify that the VPS is running using:
vzlist
or
vzctl status <VEID>
Resolution
For Red Hat-based VPS (CentOS/RHEL)
Step 1: Recreate the PTY and TTY device nodes
Execute the following commands from the OpenVZ host:
vzctl exec <VEID> /sbin/MAKEDEV pty vzctl exec <VEID> /sbin/MAKEDEV tty
Step 2: Access the VPS
vzctl enter <VEID>
If the missing device nodes were the cause of the issue, the login should now succeed.
Prevent the Issue from Reoccurring (CentOS/RHEL)
To make the fix persistent:
Step 1: Edit the system initialization file
Open:
/etc/rc.sysinit
Step 2: Disable automatic udev startup
Locate:
/sbin/start_udev
Comment it out:
#/sbin/start_udev
Step 3: Add device creation commands
Immediately after the commented line, add:
/sbin/MAKEDEV tty /sbin/MAKEDEV pty
Step 4: Save the file and restart the VPS (optional)
Restart the VPS to verify the configuration:
vzctl restart <VEID>
For Debian-based VPS
On Debian systems, the issue is generally caused by the udev service.
Step 1: Disable the udev startup scripts
Run:
vzctl exec <VEID> update-rc.d -f udev remove
Step 2: Restart the VPS
vzctl restart <VEID>
Step 3: Verify access
Attempt to enter the VPS:
vzctl enter <VEID>
Verification
After completing the appropriate steps:
- Verify that
vzctl enter <VEID>opens a shell successfully. - Confirm SSH access to the VPS from an external machine (if SSH is enabled).
- Ensure no further “Unable to open pty” errors appear.
Conclusion
The “Unable to open pty: No such file or directory” error occurs when the pseudo-terminal devices required for interactive shell access are unavailable inside an OpenVZ container. On Red Hat-based systems, recreating the PTY/TTY devices and updating the startup configuration permanently resolves the issue. On Debian-based systems, disabling the udev startup scripts prevents the removal of the required device nodes.
After applying the appropriate fix, verify both console (vzctl enter) and SSH access to ensure the VPS is functioning normally. If the issue persists, further investigation of the container’s filesystem, device nodes, and OpenVZ host configuration may be required.
