To run sudo commands on a ec2 instance

只谈情不闲聊 提交于 2019-12-10 14:50:09

问题


I cannot run "sudo su" on my ec2 client , I ssh into the client through a java program and run the command through a program. I can run commands like "ls" and "ifconfig" though.

I get an error saying "sudo: sorry, you must have a tty to run sudo".

How can I run the command, I am using Jsch for ssh to my ec2 instance.


回答1:


You can do "sudo" without pseudo-tty with JSch, by using the -S option to sudo.

See the Sudo.java on the JSch website for a complete example.

(I'm the author of JSch.)




回答2:


Looks like by default Jsch doesn't allocate a pseudo-tty for the remote session - this can break some programs that expect to be run interactively. It looks like you might be able to use the ChannelExec.setPty function to request a pty - but I've not worked with Jsch and can't test this myself.



来源:https://stackoverflow.com/questions/8441637/to-run-sudo-commands-on-a-ec2-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!