No announcement yet.

How to Fix - SSH Login Fails: pty allocation request failed on channel 0

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Fix - SSH Login Fails: pty allocation request failed on channel 0

    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.

    When you connect to server:

    ssh -p 22
    And, it gave the error message as:

    PTY allocation request failed on channel 0
    shell request failed on channel 0

    This is due to multiple reasons, so let's fix it:

    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.

    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.

    Various other things to try:

    Method 1:

    You can prevent the difference in behaviour by using always giving the -T option so that the client (any version) never requests a pty from the server:

    ssh -T username@YourServer -p 22

    Method 2:

    If you have shell access:

    root@unix:~# /sbin/MAKEDEV tty
    root@unix:~# /sbin/MAKEDEV pty
    If you don't have access to any shell, you could try sending the command via ssh :

    geek@localmachine:~$ ssh root@unix "/sbin/MAKEDEV tty"
    geek@localmachine:~$ ssh root@unix "/sbin/MAKEDEV pty"
    Or you can also define the shell when ssh:

    ssh user@host "/bin/bash -i"