0

I am using the libssh library and trying to create a new SFTP session. I keep getting an error message of

ssh_packet_unimplemented: Received SSH_MSG_UNIMPLEMENTED (sequence number 3)

I checked the syslog of the remote server and found the error

dispatch_protocol_error: type 90 seq 3 [preauth]

For some reason I get this error when trying to use the following (taken from the libssh doc)

int sftp_helloworld(ssh_session session) {
  sftp_session sftp;
  int rc;
  sftp = sftp_new(session); // Freezes at this part
  if (sftp == NULL) {
    fprintf(stderr, "Error allocating SFTP session: %s\n", ssh_get_error(session));
    return SSH_ERROR;
  }
  rc = sftp_init(sftp);
  if (rc != SSH_OK) {
    fprintf(stderr, "Error initializing SFTP session: %s.\n", sftp_get_error(sftp));
    sftp_free(sftp);
    return rc;
  }
  sftp_free(sftp);
  return SSH_OK;
}

The only thing that is working is the actual ssh connection. The same error occurs whether I'm using SCP, SFTP or when opening a remote shell.

I've researched a lot regarding my issue, but couldn't find any remedies. Any help would be great.

EDIT:

On the Amazon EC2 server I looked through /var/log/auth.log and found this:

sshd[24860]: Accepted publickey for ubuntu

sshd[24860]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)

sshd[24930]: dispatch_protocol_error: type 90 seq 3 [preauth]

In the libssh code I set the SSH_OPTIONS_LOG_VERBOSITY to SSH_LOG_PACKET, everything runs smoothly, but when it gets to the sftp_new() I recieve this error and it freezes at the SSH_MSG_UNIMPLEMENTED message,

channel_open: Creating a channel 43 with 64000 window and 32768 max packet

packet_send2: packet: wrote [len=44,padding=19,comp=24,payload=24]

channel_open: Sent a SSH_MSG_CHANNEL_OPEN type session for channel 43

ssh_socket_unbuffered_write: Enabling POLLOUT for socket

ssh_packet_socket_callback: packet: read type 3 [len=12,padding=6,comp=5,payload=5]

ssh_packet_process: Dispatching handler for packet type 3

ssh_packet_unimplemented: Received SSH_MSG_UNIMPLEMENTED (sequence number 3)

EDIT2:

I used the following code to connect to the server,

ssh_key pKey;
int rc = ssh_pki_import_privkey_file(PC_PRIVATE_KEY_FILE, NULL, NULL, NULL, &pKey);

ssh_session my_ssh_session = ssh_new();

ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, PC_HOST);
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, PC_USER);
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &PC_PORT);
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &PC_VERBOSITY);

rc = ssh_connect(my_ssh_session);

I was confused by the tutorial. I might have not wrote the code to connect to the server properly.

Amous
  • 534
  • 5
  • 18
  • Can you connect to the server using a regular SFTP client, at all? – Martin Prikryl Nov 11 '16 at 19:41
  • @MartinPrikryl Yup, I can connect to the server using `ssh`, `sftp` and `scp`. – Amous Nov 11 '16 at 20:00
  • Collect all logs you can and edit them into your question. Server-side log (what SSH server is that anyway?), `sftp -vv` output, libssh log. – Martin Prikryl Nov 11 '16 at 20:57
  • @MartinPrikryl I updated the question with more error messages. Hope it helps. – Amous Nov 11 '16 at 21:39
  • Have you completed client authentication? "[preauth]" from the server's log probably means that user authentication is not yet finished, thus SSH_MSG_CHANNEL_OPEN cannot be processed by the server this far. – Oleg Andriyanov Nov 11 '16 at 22:01
  • @OlegAndriyanov I updated the question with the code I used to connect to the server. The tutorial on the libssh website confused me, so I might have not done it correctly. Thanks for the help. – Amous Nov 11 '16 at 22:40
  • You are definitely not authenticating. Unless you didn't post the relevant code. – Martin Prikryl Nov 12 '16 at 07:13

1 Answers1

2

According to this tutorial, after connecting to server you should authenticate yourself to it. I.e., if you want to authenticate with public key, add the following after successful call to ssh_connect:

int rc;
// ...
rc = ssh_userauth_publickey(my_ssh_session, NULL, pKey);
if(rc != SSH_AUTH_SUCCESS) {
    // error
} else {
    // all good, start SFTP/shell/etc
}
Oleg Andriyanov
  • 5,069
  • 1
  • 22
  • 36