在程序中创建 SSH 连接? [英] Creating a SSH connection in a program?

查看:21
本文介绍了在程序中创建 SSH 连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序(用 C 语言),我必须通过 SSH 连接从另一台计算机访问数据.我想知道如何在程序中创建 SSH 连接.

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 program.

谢谢

推荐答案

一个简单的解决方案是使用 ssh 二进制文件并从您的程序中调用它.使用 pipe() 创建 3 个管道,然后使用 fork(), close() 适当的端点(不确定是否需要),所以你有2 个进程,它们之间有 3 个管道.在子进程上,dup2() 管道端点到 stdin、stdout 和 stderr(即 fd 的 0、1、2)和 exec() ssh 命令.

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.

在父进程上,您现在可以只与另一方交谈.使用 RSA 身份验证摆脱密码.

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 ;-)

这篇关于在程序中创建 SSH 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆