Creating a SSH connection in a program?

后端 未结 2 1828
盖世英雄少女心
盖世英雄少女心 2021-01-21 04:34

I am writing a programing (in C) in which I have to access data from another computer through an SSH connection. I was wondering how to create the SSH connection within the prog

2条回答
  •  独厮守ぢ
    2021-01-21 04:57

    One easy solution would be to use the ssh binary and call that from your program. Create 3 pipes using pipe(), then fork(), close() the appropriate endpoints (not sure if that's needed) so you have 2 processes with 3 pipes between them. On the child, dup2() the pipe endpoints to stdin, stdout and stderr (i.e. fd's 0, 1, 2) and exec() the ssh command.

    On the parent process you can now just talk to the other side. Use RSA authentication to get rid of password stuff.

    But there may be libraries to just connect, I don't know ;-)

提交回复
热议问题