Community Articles

Find and share helpful community-sourced technical articles.
avatar
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

4,407 Views
Comments

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.