Authenticate to SSH via BSD

I want to authenticate to an ssh server through a BSD socket. I know how to initiate a connection, but I do not know how to actually authenticate. Thanks for your time pointing me in the right direction.

Here is the source code:

//
#include <stdio.h>      // printf()
#include <sys/types.h>  // socket data types
#include <sys/socket.h> // socket(), connect(), send(), recv()
#include <arpa/inet.h>  // sockaddr_in, inet_addr()
#include <stdlib.h>     // free()
#include <unistd.h>     // close()

int *ssh(char *host, int port, char *user, char *pass);

int main(void)
{
// create socket
int *ssh_socket = ssh("127.0.0.1", 22, "root", "password");

// close and free
close(*ssh_socket);
free(ssh_socket);

return 0;
}

int *ssh(char *host, int port, char *user, char *pass)
{
int *sock = calloc(sizeof(int), 1);
struct sockaddr_in addr = {.sin_family=AF_INET, \
                           .sin_port=htons(port), \
                           .sin_addr.s_addr=inet_addr(host)};

*sock=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // create socket
connect(*sock, (struct sockaddr *)&addr, sizeof(addr)); // init connection


// here is the problem
// how do I authenticate on this socket?


return sock;
}
+3
source share
2 answers

Use libssh to add SSH functions to your program.

+1
source

SSH is a fairly complex protocol with several layers.

Before proceeding with user authentication, you need to initiate a protocol, verify the credentials of the remote host, and start an encrypted connection.

, ( , passwd, - ..).

Wikipedia SSH RFC.

, libssh libssh2 OpenSSH!

+1

Source: https://habr.com/ru/post/1784539/


All Articles