要在EC2实例上运行sudo的命令要在、实例、命令、sudo

2023-09-11 23:44:25 作者:囍你如初

我不能在我的EC2客户端上运行命令苏,我ssh到客户端通过一个Java程序,并通过程序运行命令。 我可以如ls和使用ifconfig,尽管运行命令。

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.

我得到一个错误说。须藤:对不起,你必须有一个tty运行sudo的

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

我怎样才能运行该命令,我使用Jsch的ssh来我的EC2实例。

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

推荐答案

您可以做的命令无伪终端与JSch,使用 -S 选项须藤

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

请参见 Sudo.java 中的JSch网站上的一个完整的例子。

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

(我JSch的作者。)

(I'm the author of JSch.)