Link to home
Start Free TrialLog in
Avatar of kannu kc
kannu kc

asked on

sudo command does not work in remote session to Linux machine

Hi,


I am running linux commands from powershell. Made a connection from powershell to linux vm. it is working properly but when I use sudo command ( for ex . sudo useradd test) , it gives below error "sudo: sorry, you must have a tty to run sudo bash: could: command not found" .
I need to use sudo because I am not executing the script as 'root'. I need to execute this as a user.

PFA


Thanks
1.png
Avatar of arnold
arnold
Flag of United States of America image

to run sudo bash (sudo -i or sudo -s) it tells you that you have to have an established sessionv
sudo bash (sudo -i or sudo -s) envokes a shell, a shell needs a session.
sudo /usr/bin/useradd -----

there are many ways to execture a script remotely without the need to invoke a shell.
Avatar of kannu kc
kannu kc

ASKER

so what is the solution????
How to establish the session
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What arnold is suggesting is to try sudo -i $command or sudo -s $command (add -i + -s option) to determine if one of these options will circumvent problem you're seeing.

So the solution is... try each command + use the one that works.
There may be an option on the Powershell command to start a tty, similar to the "-t" option on ssh.
Try ssh -t to force an interactive session.
Solution is to edit the sudoers file. There is a Default "requiretty". Just comment this out and you're done

so - "visudo" to edit sudoers file as root

search for:
Defaults    requiretty

change to:
#Defaults    requiretty
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- arnold (https:#a42402153)
-- Dan Craciun (https:#a42402189)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer