Hi,
I am new to SSHD. I have tried to follow the documentation and tips on the SSHD
web site to create a simple sshServer.
At this point it receives the command from the SSH client but no output is
returned from the command (e.g., the directory contents when sending "ls -l" as
the command).
Here is my server code:
import java.io.IOException;
import org.apache.sshd.SshServer;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.shell.ProcessShellFactory;
public class CopyOfServerTest {
public CopyOfServerTest() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPasswordAuthenticator(new NoPasswordAuthenticator());
//sshd.setPublickeyAuthenticator(new
MyPublickeyAuthenticator());
sshd.setPort(12250);
sshd.setKeyPairProvider(new
SimpleGeneratorHostKeyProvider("/pathto/hostkey.ser"));
sshd.setShellFactory(new ProcessShellFactory(new String[] {
"/bin/bash", "-i", "-l" }));
sshd.setCommandFactory(new ScpCommandFactory(new
CommandFactory() {
public Command createCommand(String command) {
System.out.println("******** COMMAND is " + command);
return new ProcessShellFactory(command.split("
")).create();
}
}));
try {
sshd.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Console output is:
Mar 7, 2011 3:32:59 PM org.apache.sshd.common.util.SecurityUtils register
INFO: BouncyCastle not registered, using the default JCE provider
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession <init>
INFO: Session created...
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession
readIdentification
INFO: Client version string: SSH-2.0-OpenSSH_5.2
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession
handleMessage
INFO: Received SSH_MSG_KEXINIT
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.kex.AbstractDHGServer next
INFO: Received SSH_MSG_KEXDH_INIT
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.kex.AbstractDHGServer next
INFO: Send SSH_MSG_KEXDH_REPLY
Mar 7, 2011 3:33:03 PM org.apache.sshd.common.session.AbstractSession
sendNewKeys
INFO: Send SSH_MSG_NEWKEYS
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession
handleMessage
INFO: Received SSH_MSG_NEWKEYS
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession
handleMessage
INFO: Received SSH_MSG_SERVICE_REQUEST 'ssh-userauth'
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Accepting user authentication request
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Authorized authentication methods: password
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession
handleMessage
INFO: Received SSH_MSG_USERAUTH_REQUEST
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Authenticating user 'user' with method 'none'
Mar 7, 2011 3:33:03 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Unsupported authentication method 'none'
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.session.ServerSession
handleMessage
INFO: Received SSH_MSG_USERAUTH_REQUEST
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Authenticating user 'user' with method 'password'
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.session.ServerSession userAuth
INFO: Authentication succeeded
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.session.ServerSession channelOpen
INFO: Received SSH_MSG_CHANNEL_OPEN session
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.channel.ChannelSession
handleRequest
INFO: Received SSH_MSG_CHANNEL_REQUEST on channel 0
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.channel.ChannelSession
handleRequest
INFO: Received channel request: exec
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.channel.ChannelSession handleExec
INFO: Executing command: ls -l
******** COMMAND is ls -l
Mar 7, 2011 3:33:04 PM
org.apache.sshd.server.shell.ProcessShellFactory$ProcessShell start
INFO: Starting shell with command: '[ls, -l]' and env: {SHELL=/bin/bash,
com.apple.java.jvmMode=client,
TMPDIR=/var/folders/HM/HMPDcPnuE40TW8d57qD7w++++TI/-Tmp-/,
APP_ICON_7541=../Resources/Eclipse.icns, __CF_USER_TEXT_ENCODING=0x1F5:0:0,
PATH=/usr/bin:/bin:/usr/sbin:/sbin, COMMAND_MODE=unix2003,
DISPLAY=/tmp/launch-VaHBR3/org.x:0, USER=user,
JAVA_STARTED_ON_FIRST_THREAD_7541=1,
JAVA_MAIN_CLASS_7723=server_test.CopyOfServerTest, HOME=/Users/user,
LOGNAME=user, Apple_PubSub_Socket_Render=/tmp/launch-oPQXIZ/Render,
SSH_AUTH_SOCK=/tmp/launch-uYARkk/Listeners}
Mar 7, 2011 3:33:04 PM org.apache.sshd.common.channel.AbstractChannel sendEof
INFO: Send SSH_MSG_CHANNEL_EOF on channel 0
Mar 7, 2011 3:33:04 PM org.apache.sshd.server.channel.AbstractServerChannel
sendExitStatus
INFO: Send SSH_MSG_CHANNEL_REQUEST exit-status on channel 0
Mar 7, 2011 3:33:04 PM org.apache.sshd.common.channel.AbstractChannel close
INFO: Send SSH_MSG_CHANNEL_CLOSE on channel 0
Mar 7, 2011 3:33:04 PM org.apache.sshd.common.channel.AbstractChannel
handleClose
INFO: Received SSH_MSG_CHANNEL_CLOSE on channel 0
Mar 7, 2011 3:33:04 PM org.apache.sshd.common.session.AbstractSession close
INFO: Closing session
Thanks for any help!