如何使用C ++建立简单的SSH连接 [英] How to establish a simple ssh connection with c++
问题描述
我正在尝试制作一个C ++程序,该程序将连接到ssh服务器(我的笔记本电脑).服务器还可以,因为我可以通过腻子连接.虽然到目前为止我写的程序还不能.在我的代码中,我使用的是libssh.h库,而在开发中,我使用的是Visual Studio2015.我得到的错误是: crypt_set_algorithms2:没有为3des-cbc找到加密算法功能 到目前为止我还没有找到任何东西,希望对您有所帮助. 我使用的代码:
I am trying to make a c++ program which will connect to an ssh server (my laptop). The server is ok because I can get connected via putty. Although the program I wrote so far can not. In my code I am using the library libssh.h and for development I used visual studio 2015. The error I get is: crypt_set_algorithms2: no crypto algorithm function found for 3des-cbc I haven't found anything so far so I hope to your help. The code I use:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int rc;
int port = 22;
int verbosity = SSH_LOG_PROTOCOL;
char *password;
// Open session and set options
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "192.168.1.6");
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "john");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
//ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error: %s\n", ssh_get_error(my_ssh_session)); //HERE IS WHERE I GET THE ERROR
ssh_free(my_ssh_session);
exit(-1);
}
// Verify the server's identity
// For the source code of verify_knowhost(), check previous example
/* if (verify_knownhost(my_ssh_session) < 0)
{
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
*/
// Authenticate ourselves
password = "pass";
rc = ssh_userauth_password(my_ssh_session, NULL, password);
if (rc != SSH_AUTH_SUCCESS)
{
fprintf(stderr, "Error authenticating with password: %s\n",
ssh_get_error(my_ssh_session));
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
推荐答案
尝试使用其他密码. 3des-cbc
已损坏,可能已在您的服务器上禁用.
Try to use different cipher. 3des-cbc
is broken and probably disabled on your server already.
真的有不错的教程,带有简单的会话.
There is really nice tutorial with simple session.
删除该行可以使其在Ubuntu上为我工作(不知道在哪里找到):
Removing the line makes it working for me on Ubuntu (don't know where you found it):
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
如果没有,您使用的是什么版本的libssh
?是不是有些过时了?
If not, what version of libssh
are you using? Isn't it some obsolete one?
这篇关于如何使用C ++建立简单的SSH连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!