Solved: Cannot open your terminal ‘/dev/pts/2’ – please check

The Problem: When trying to reconnect to an existing screen session on a Linux system (Fedora, RedHat Ubuntu, etc), you will see a message like the following:

Cannot open your terminal '/dev/pts/2' - please check

(Note: your terminal identifier may vary)

This is a rare occurrence and is indeed one of the stranger issues to have come across my desk in recent months, but thankfully there’s a very easy solution.

2 Solutions: How to re-gain access to your screen session

Solution #1
Run the following command from your terminal. After doing so, you will then be able to reconnect to your screen session.
script /dev/null

So why does running the command ‘script /dev/null’ work? To be honest, when I first found this solution, I really didn’t care why it worked, only that it did work! That’s right. Sometimes you just need to get the job done and why a given solution works isn’t always needed in the heat of the moment. If you want to get into the details about why running the aforementioned command works, read on:

The short answer as to why running ‘script /dev/null’ lets you connect back to your screen session is the following:

First of all, the script man page states that “script makes a typescript of everything on your terminal session”.  So if we are to understand that there is something wrong with our current session/terminal (the original message is that terminal /dev/pts/x cannot be opened), this implies that running script /dev/null sends the contents of your current session to /dev/null. By doing so,  this then creates a new “pseudoterminal“.  This new terminal now can be opened and the result is that we can now access our screen session.

Solution #2
This solution requires fewer keystrokes than Solution #1 so it may be your preferred way of getting around the ‘Cannot open your terminal’ screen initiation issue. Simply ssh to your current host and you will get around the issue like so:
ssh localhost

Why does this issue occur?

The final burning question is why do we end up in this situation in the first place? That is a harder question to answer as the issue can manifest for different reasons on different systems. The issue itself may be environmental as well as system dependent. You can however usually clear this type of issue by rebooting your machine or server but doing so would wipe your screen session, so rebooting is usually not an option if you wish to preserve said screen session.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.