Do you have trouble when logging into a server through ssh?
SSH errors are quite frustrating, especially when doing server changes at the last minute.
One such error is the pty allocation request failed on channel 0 error.
At Bobcares, we help server owners resolve SSH errors as part of our Server Management Services.
Today, let’s discuss the pty allocation request failed error and see how our Support Engineers fix it.
What is the pty allocation request failed on channel 0 error?
As the first step, let’s check the details of the error “pty allocation request failed on channel 0“.
It is one of the common errors that happen when we ssh into the server.
The error mainly occurs when the SSH server isn’t assigning a TTY instance for the connection. In simple words, this affects the interactivity in the shell.
This typically happens when SSH command has an alias set on the server.
One of our customers contacted us with a similar error. He was trying to connect to the server through ssh like this:
ssh username@my-server.com -p 22
And, it gave the error message as:
PTY allocation request failed on channel 0
shell request failed on channel 0
How we fix the pty allocation error?
Now, we know the scenario that causes this pty allocation request failed error.
Let’s see the major causes and how our Support Engineers fix this error.
1. Incorrect Mount options
One of the top reasons for SSH channel error will be incorrect mount option set for /dev/pts.
The /dev/pts is a virtual filesystem in the kernel for the pseudo-terminal. Usually, init scripts or daemons like systemd takes care of the proper mounting of the devpts filesystem. In general, there is a limit of 256 pseudo terminals on a system. And, when any application running on the server starts leaking pseudo terminals, SSH returns TY allocation failure.
Here, our Support Engineers first check and see what processes have open pseudo-terminals using:
lsof /dev/pts/*
And, fix the error by unmounting and remounting /dev/pts.
For this, we use the command:
$ umount /dev/pts
$ mount devpts /dev/pts -t devpts
And that resolves the error effectively.
In case, if the server becomes inaccessible, we suggest the customers reboot the server to single user mode and add these lines to your /etc/mtab & /etc/fstab entry.
To do this, we open the file /etc/mtab or /etc/fstab. Then after, we add the line into these files.
none /dev/pts devpts defaults 0 0
At last, we reboot the system to make the changes effective.
2. SSH settings
In a similar way, incorrect SSH settings can also trigger this error. For example, when the SSH binary is aliased to ‘ssh –t’ it can result in an error.
Additionally, the same error pops up when access to PTY is prohibited in .ssh/authorized_keys file.
Or when the SSH configuration file holds entries like “PermitTTY yes“, it can even cause the TTY error. Ultimately, this results in a failed login.
Therefore, we edit the configuration and set the entry as:
PermitTTY no
That fixes the problem and makes SSH working again.
[Need help to solve the pty allocation request failed on channel 0 error? We’ll help you.]
Conclusion
In short, the ssh pty allocation request failed on channel 0 error happens when the server isn’t assigning a TTY instance for the connection. Today’s write-up also discussed the reasons for this error and how our Support Engineers fixed it for our customers.
Is it possible to come a member, is this a forum? kinldy advise
Hello Jacqueline,
This is the Bobcares blog and not a forum. To read on the latest article simply bookmark the link https://bobcares.com/blog/