You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by "N, Ravikiran" <ra...@hpe.com> on 2017/03/31 06:30:32 UTC

Unable to open channel on client

Hello,

I am trying to setup a basic SSH client using apache SSHD - 1.1.0 libraries. I'm using org.apache.sshd.server.SshServer available in the library, server running at 8000 port. My client code goes as follows :

SshClient client = SshClient.setUpDefaultClient();
client.start();
ClientSession session = client.connect("root", "192.168.56.101",8000).verify().getSession();
session.addPasswordIdentity("root");
ClientChannel channel;
channel = session.createChannel(Channel.CHANNEL_EXEC, "pwd");
channel.setOut(new NoCloseOutputStream(System.out));
channel.setErr(new NoCloseOutputStream(System.err));
channel.open().await();
channel.waitFor(EnumSet.of(ClientChannel.ClientChannelEvent.CLOSED), 0);
channel.close();
session.close(false);
client.stop();

Whenever I execute channel.open().await(); , I get the following error on server side:
Mar 31, 2017 8:22:40 AM org.apache.sshd.common.session.AbstractSession exceptionCaught
WARNING: exceptionCaught(ServerSessionImpl[null@/192.168.56.1:54877])[state=Opened] IllegalStateException: No current authentication mechanism for cmd=SSH_MSG_CHANNEL_OPEN

What is the error I'm doing. Please bear me since I'm starter here.. :)

Thanks
Ravikiran

RE: Unable to open channel on client

Posted by subramaniajeeva <su...@gmail.com>.
I'm getting the same error when I use linux based sftp client to connect to
mina sshd server.

I'm using async authentication. And, only the first attempt to login
fails(even though I get authentication success in my logs)

Here are the logs I can see in my application:

[Thread-4] INFO org.apache.sshd.server.session.ServerUserAuthService -
Session admin@/0:0:0:0:0:0:0:1:57453 authenticated

[sshd-SshServer[181e731e]-nio2-thread-6] WARN
org.apache.sshd.server.session.ServerSessionImpl -
exceptionCaught(ServerSessionImpl[admin@/0:0:0:0:0:0:0:1:57453])[state=Opened]
IllegalStateException: No current authentication mechanism for
cmd=SSH_MSG_CHANNEL_OPEN


  val userAuthFactories = new util.ArrayList[NamedFactory[UserAuth]]()
  userAuthFactories.add(new UserAuthPasswordFactory())

  val sshd: SshServer = SshServer.setUpDefaultServer()
  sshd.setPort(1988)

  sshd.setKeyPairProvider(new
SimpleGeneratorHostKeyProvider(Paths.get("/Users/sujeeva/a.ser")))
  sshd.setUserAuthFactories(userAuthFactories)

  sshd.setShellFactory(new InteractiveProcessShellFactory())

  val factory = new SftpSubsystemFactory.Builder().build()
  sshd.setSubsystemFactories(util.Arrays.asList(factory))

  sshd.setCommandFactory((command: String) => {
    println("SSH server received command " + command)
    new InvertedShellWrapper(new ProcessShell(command))
  })

  sshd.setPasswordAuthenticator((username: String, password: String,
session: ServerSession) => {
    async(1000, true)
  })

   def async(delay: Int, result: Boolean): Boolean = {
    val auth = new AsyncAuthException
    new Thread(() => doAsync(delay, result, auth)).start()
    throw auth
  }

  private def doAsync(delay: Int, result: Boolean, auth:
AsyncAuthException): Unit = {
    try
      Thread.sleep(delay)
    catch {
      case ignore: InterruptedException =>
    } finally auth.setAuthed(result)
  }





--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-User-Forum-f31345.html

RE: Unable to open channel on client

Posted by "N, Ravikiran" <ra...@hpe.com>.
Hello All,

I missed out on calling auth() method. After adding the method call, it is working fine. 
session.auth().verify(FactoryManager.DEFAULT_AUTH_TIMEOUT);
Please ignore my query.

Thanks
Ravikiran

-----Original Message-----
From: N, Ravikiran 
Sent: Friday, March 31, 2017 12:01 PM
To: users@mina.apache.org
Subject: Unable to open channel on client

Hello,

I am trying to setup a basic SSH client using apache SSHD - 1.1.0 libraries. I'm using org.apache.sshd.server.SshServer available in the library, server running at 8000 port. My client code goes as follows :

SshClient client = SshClient.setUpDefaultClient(); client.start(); ClientSession session = client.connect("root", "192.168.56.101",8000).verify().getSession();
session.addPasswordIdentity("root");
ClientChannel channel;
channel = session.createChannel(Channel.CHANNEL_EXEC, "pwd"); channel.setOut(new NoCloseOutputStream(System.out)); channel.setErr(new NoCloseOutputStream(System.err)); channel.open().await(); channel.waitFor(EnumSet.of(ClientChannel.ClientChannelEvent.CLOSED), 0); channel.close(); session.close(false); client.stop();

Whenever I execute channel.open().await(); , I get the following error on server side:
Mar 31, 2017 8:22:40 AM org.apache.sshd.common.session.AbstractSession exceptionCaught
WARNING: exceptionCaught(ServerSessionImpl[null@/192.168.56.1:54877])[state=Opened] IllegalStateException: No current authentication mechanism for cmd=SSH_MSG_CHANNEL_OPEN

What is the error I'm doing. Please bear me since I'm starter here.. :)

Thanks
Ravikiran