Executando o comando “sudo” na minha caixa do Amazon EC2 usando a biblioteca sshj java
Eu estou tentando executar um comando sudo na minha máquina Amazon EC2 usando a biblioteca SSHJ (https://github.com/shikhar/sshj). Infelizmente, não estou recebendo nenhuma resposta do servidor. Eu sei com certeza que os outros comandos não-sudo são executados sem falhas. Aqui está um código de exemplo.
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect(host, 22);
if (privateKeyFile != null) {
// authenticate using private key file.
PKCS8KeyFile keyFile = new PKCS8KeyFile();
keyFile.init(privateKeyFile);
sshClient.authPublickey(user, keyFile);
} else {
// Authenticate using password.
sshClient.authPassword(user, password);
}
// Start a new session
session = sshClient.startSession();
session.allocatePTY("vt220", 80,24,0,0,Collections.<PTYMode, Integer>emptyMap());
Command cmd = null;
String response = null;
try (Session session = sshClient.startSession()) {
cmd = session.exec("sudo service riak start");
response = IOUtils.readFully(cmd.getInputStream()).toString();
cmd.join(timeout, timeUnit);
} finally {
if (cmd != null) {
cmd.close();
}
}