How to solve Error "Pseudo-terminal will not be allocated”

How to solve Error "Pseudo-terminal will not be allocated”

08:59, 28.05.2024

Article Content
arrow

  • Causes of the Error
  • Solutions for the Error
  • Pseudo-TTY Allocation Enforcement
  • Pseudo-TTY Allocation Deactivation
  • Shell Specification
  • To Sum Up

While using Secure Shell (SSH) protocol to access a remote computer, an error described as “Pseudo-terminal will not be allocated because stdin is not a terminal” can come up.

Pseudo-terminal is a substitute for a physical terminal that maintains all the functionality of the latter. When we try to connect to the device through SSH, the first thing it’s going to do is try to connect it to a terminal. But what if we want to connect to a remote device without a terminal?

For instance, we want to redirect command’s the standard input (stpin) to another command. Such a scenario may be associated with issues like “Pseudo-terminal will not be allocated…”.

In this article, we will look at why the error occurs, and how to fix it.

Causes of the Error

Based on our experience, there are a few possible causes for the “Pseudo-terminal will not be allocated because stdin is not a terminal” error. Here, we are going to list some of them.

  • Running an interactive command on a remote device without a terminal, for example:
$ ssh user@host 'vim file.txt'Copy
  • Attempting to run a command requiring sudo privileges without a terminal on a remote device, like this one:
$ ssh user@host 'sudo apt update'Copy
  • Trying to run a stdin redirection command from a file or another command on the remote machine:
$ ssh user@host 'cat file.txt' < input.txtCopy
  • Running an SSH command from a script.

Solutions for the Error

Even though there are many potential causes of the error, there are also a number of ways to fix it. We are going to review three: pseudo-TTY allocation enforcement, pseudo-TTY allocation deactivation, and shell specification.

Pseudo-TTY Allocation Enforcement

To eliminate the error through pseudo-TTY allocation enforcement we need to use a -t option for ssh. It forces ssh to allocate a pty even if stdin is not a terminal.

This method is especially useful if you want to run commands with sudo privileges on the remote machine. The following command allows you to remotely access a server and interactively edit a file through the Vim text editor:

$ ssh -t user@host 'vim file.txt'Copy

Then you can update the package list (on Ubuntu OS) through the sudo command and admin privileges it provides within the remote server:

$ ssh -t user@host 'sudo apt update'Copy

In these two examples, what the -t option does is force a terminal to be allocated. However, the -t option is not a one-fit-all solution; in some cases, we have to use double -t, or -tt. The -tt option streamlines tty allocation without a local tty. Such a command is useful for running stdin redirection on the remote machine:

$ ssh -tt user@host 'cat file.txt' < input.txtCopy

The -t option forces pseudo-TTY allocation and through it resolves an error.

Pseudo-TTY Allocation Deactivation

We can also use the SSH’s -T option to deactivate pseudo-TTY allocation overall. The -T option forces ssh to not perform any allocation of the remote machine. So, for commands that don’t need a terminal, this option will be useful:

$ ssh -T user@host 'ls -l'Copy

Here, the Is -I command terminates the allocation immediately.

Shell Specification

To eliminate the “Pseudo-terminal will not be allocated because stdin is not a terminal” error we can also do a specification of the shell on the remote machine. The default SSH setting includes using the remote user’s login shell for running commands. However, some shells are not compatible with stdin redirection, which can cause errors like ours to arise.

To avoid that, we can specify the shell:

$ ssh user@host '/bin/bash -c "cat file.txt < input.txt"'Copy

This command targets the Bash shell to link the contents of file.txt and input.txt.

To Sum Up

In this guide, we’ve focused on the three methods to resolve the “Pseudo-terminal will not be allocated because stdin is not a terminal” error such as pseudo-TTY allocation, disabling pseudo-TTY allocation, and shell specification.

Using these methods will help you carry out commands without facing any more issues related to terminal allocation.

views 3m, 22s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.