sudo command does not work in remote session to Linux machine


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.


kannu kcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
kannu kcAuthor Commented:
so what is the solution????
kannu kcAuthor Commented:
How to establish the session
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan CraciunIT ConsultantCommented:
You can always use Putty instead of Powershell.

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.
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.
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
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:

-- 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.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.