Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

authenticate on SSH via BSD socket

Tags:

c

ssh

sockets

I'd like to authenticate on ssh-server via BSD socket. I know how to initiate a connection but don't know how to actually authenticate. Thanks for your time when pointing me to 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;
}
like image 610
ClosedID Avatar asked Apr 24 '26 07:04

ClosedID


1 Answers

Use libssh for adding SSH functionality to your program.

like image 143
ismail Avatar answered Apr 26 '26 21:04

ismail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!