Skip to main content
rbiswas1
Gold ⭐️
Apr 5, 2017 12:20 AM UTC

Trying to use sudo to run commands(as root) in a cluster gives error " Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal. sudo: sorry, you must have a tty to run sudo"

  • Oct 5, 2026 8:49 AM UTC
  • 1 reply
  • 5356 views
  • Translate All
Problem:

Trying to use sudo to run commands(as root) in a cluster gives error

" Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.

sudo: sorry, you must have a tty to run sudo"

This is a common situation where you are login as some other user in a terminal and then sudo to root to perform the task. And you can only ssh from the user you logged in and not from root.

Solution:

Note: You have to install pssh if it is not already installed. in your cluster.

Keep all host names in a file say all_hosts

This kind of execution will fail:

pssh -i -h all_hosts "sudo whoami;hostname -f"
Will fail to execute and give error:
Stderr: sudo: sorry, you must have a tty to run sudo

OR

pssh -i -h all_hosts -x "-t" "sudo whoami;hostname -f"
Will fail to execute and give error:
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal. sudo: sorry, you must have a tty to run sudo

The correct command should be run like this:

pssh -i -h all_hosts -x "-t -t" "sudo whoami;hostname -f"

And you can safely ignore this error: "Stderr: tcgetattr: Invalid argument"

Your command will run in the way you intent it and you will be able to manage your cluster from one terminal

Hope this helps.

Thanks

    1 reply

    Seaport
    Gold ⭐️
    Nov 18, 2021 9:30 PM UTC

    rbiswas1, 

     

    I tried your code but pssh returned a timeout error. It was waiting for the password but I never got the prompt to enter the password.

     

    Could you elaborate more about your method? 

     

    Thanks.

    Translate