Hello,
Is it possible to run interactive shell scripts using Apache SSHD? My
attempt was not very successful.
Java code:
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(45121);
String hostKey = new
File(App.class.getResource("hostkey.pem").toURI()).getAbsolutePath();
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
sshd.setShellFactory(new ProcessShellFactory(new String[] { "sh",
"myscript.sh" }, EnumSet.of(TtyOptions.ONlCr, TtyOptions.ICrNl,
TtyOptions.Echo)));
List<NamedFactory<UserAuth>> userAuthFactories = new
ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String username, String password,
ServerSession session) {
return true;
}
});
sshd.start();
myscript.sh:
#!/bin/sh
echo Welcome
read -p "Please input your age: " age
echo You are $age years old
The output of an SSH connection is only "Welcome" (the prompt does not
appear). Then, I can input a value and the characters are echoed, but
backspace doesn't work.
Thanks in advance,
Alexandre