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.
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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With