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)
{
int *ssh_socket = ssh("127.0.0.1", 22, "root", "password");
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);
connect(*sock, (struct sockaddr *)&addr, sizeof(addr));
return sock;
}
source
share