在Overthere / sshj中使用Sudo su

时间:2018-03-06 12:39:15

标签: java ssh remote-access overthere

我一直在尝试使用Overthere来访问远程盒子。我想要运行的命令

sudo su - username

然而,应用程序挂起等待密码。此外,我不知道如何启用日志记录以查看正在发生的事情。

这是我的代码:

public class Main {

public static void main(String[] args) throws Exception {

    ConnectionOptions options = new ConnectionOptions();
    options.set(ADDRESS,"11.214.133.104");
    options.set(USERNAME,"user");
    options.set(PASSWORD,"password");
    options.set(OPERATING_SYSTEM,UNIX);
    options.set(CONNECTION_TYPE,SU);
    options.set(SU_USERNAME,"superuser");
    options.set(SU_PASSWORD,"password2");
    options.set(SUDO_PASSWORD_PROMPT_REGEX,"(\\[sudo\\]\\spassword\\sfor\\susername:)");
    options.set(ALLOCATE_PTY,"vt220:80:24:0:0");

    OverthereConnection connection = Overthere.getConnection("ssh", options);
    try {
        connection.execute(CmdLine.build("sudo - su superuser"));

    } finally {
        connection.close();
    }
    }
}

我的logback配置:

<configuration debug="true">
<appender name="OVERTHERE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/overthere.log</file>
<rollingPolicy 
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <FileNamePattern>log/overthere.%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>
<encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%logger{36}] %msg%n</pattern>
    </encoder>
</appender>

<!-- set the level to 'debug' or 'trace' for more details -->
<logger 
name="com.xebialabs.overthere.ssh.SshElevatedPasswordHandlingStream" 
level="TRACE">
    <appender-ref ref="OVERTHERE" />
</logger>
</configuration>

这是我得到的输出:

[sudo] password for username: 

0 个答案:

没有答案