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
kannu kcAsked:
Who is Participating?
 
arnoldCommented:
sudo requires an interactive session. not sure what you are trying to do, but yours does not seem to be an interactive session which is why your connection is not allocated a TTY/PTS

It might be simpler to address what it is you are looking to do, and then work through to a solution that will achieve what you want with the methodology you are using.
1
 
arnoldCommented:
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.
1
 
kannu kcAuthor Commented:
so what is the solution????
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
kannu kcAuthor Commented:
How to establish the session
0
 
Dan CraciunIT ConsultantCommented:
You can always use Putty instead of Powershell.

HTH,
Dan
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
0
 
simon3270Commented:
There may be an option on the Powershell command to start a tty, similar to the "-t" option on ssh.
0
 
serialbandCommented:
Try ssh -t to force an interactive session.
0
 
Peter SchultzSenior Network AdministratorCommented:
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
0
 
PberSolutions ArchitectCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.