Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To run sudo commands on a ec2 instance

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.

like image 636
Jaimin Shah Avatar asked Dec 09 '11 05:12

Jaimin Shah


2 Answers

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

like image 103
ymnk Avatar answered Oct 13 '22 06:10

ymnk


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.

like image 29
bdonlan Avatar answered Oct 13 '22 05:10

bdonlan