问题
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