我正在使用SSH通过C文件连接到其他计算机。在终端中,我使用以下代码
ssh sakurachan@192.168.61.10
我如何在C中做到这一点?我需要用户输入IP和电脑。目前我有这个代码:
char name[100];
char ip[100];
printf("Enter the computer name to connect: ");
scanf("%s", name);
printf("Enter the ip to connect: ");
scanf("%s", ip);
char command[150];
strcpy(command, "ssh ");
strcat(command, name);
system(command);
代码不能运行。有办法解决这个问题吗?
如果使用C语言编程,可以使用libssh,并使用适当的C函数来实现。用C写代码很难看(恕我直言)。
libssh
有很好的文档和很好的教程。试试这个。