Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libssh - SSH MESSAGE Unimplemented

Tags:

c

networking

ssh

I'm trying to connect using ssh_connect and libssh, but i get the following error. I have no idea what it means. Any thoughts?

[2014/09/30 00:53:00.015877, 2] channel_open:  Creating a channel 43 with 64000 window and 32768 max packet
[2014/09/30 00:53:00.050776, 1] ssh_packet_unimplemented:  Received SSH_MSG_UNIMPLEMENTED (sequence number 3)
[2014/09/30 00:54:59.949316, 1] ssh_socket_exception_callback:  Socket exception callback: 1 (0)
[2014/09/30 00:54:59.949483, 1] ssh_socket_exception_callback:  Socket error: disconnected
Error allocating SFTP session: Socket error: disconnected

here's the code

** Initialises SSH Session **/ 
ssh_session initialise_ssh(char* host, int port) {

  ssh_session my_ssh_session;
  int verbosity = SSH_LOG_PROTOCOL;

  my_ssh_session = ssh_new();

  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, host);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);

  rc = ssh_connect(current_session);
  if (rc != SSH_OK)
  {
    fprintf(stderr, "Error connecting host: %s\n",
            ssh_get_error(current_session));

  return my_ssh_session; 
}
like image 448
user1018513 Avatar asked Nov 11 '22 01:11

user1018513


1 Answers

The ssh_session object you create in your initialise_ssh() function is not completely initialized yet and thus cannot directly be used to create an sftp session like you try to do. It is laking some authentication and thus the socket is closed after a timeout of 120 seconds, yealding your exception.

After your successful ssh_connect() call you should authenticate the host (ssh_is_server_known() function among others) and you must provide a way to authenticate the user: a ssh_userauth_publickey_auto(my_ssh_session, NULL, NULL) would do it if you have public key login set up for the user running your app.

Check "Authenticating the server" and "Authenticating the user" in http://api.libssh.org/master/libssh_tutor_guided_tour.html

After that you are set up to use your session to do some work, do some sftp in your example.

like image 170
Martin Avatar answered Nov 15 '22 05:11

Martin