![](/img/trans.png)
[英]How to establish a simple communication with C++ to a Rigol instrument?
[英]How to establish a simple ssh connection with c++
我正在嘗試制作一個將連接到 ssh 服務器(我的筆記本電腦)的 C++ 程序。 服務器沒問題,因為我可以通過膩子連接。 雖然到目前為止我寫的程序不能。 在我的代碼中,我使用庫 libssh.h 並進行開發,我使用了 Visual Studio 2015。我得到的錯誤是: crypt_set_algorithms2: no crypto algorithm function found for 3des-cbc我到目前為止還沒有找到任何東西,所以我希望你幫助。 我使用的代碼:
#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
已損壞,可能已在您的服務器上禁用。
有簡單的會話非常好的教程。
刪除該行使其在 Ubuntu 上對我有用(不知道您在哪里找到它):
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
如果沒有,您使用的是什么版本的libssh
? 是不是有些過時了?
終於拿到了! 我刪除了該行
ssh_options_set(my_ssh_session, SSH_OPTIONS_CIPHERS_C_S,"aes128-ctr");
然后我使用了 libssh v0-7.2 中的ssh.dll而不是我之前使用的 v0-7.1 中的ssh.dll 。 ssh.dll 位於libssh-0.7.2\\bin 中。 如果您遇到類似msvcr120d.dll丟失的錯誤,請嘗試在 Visual Studio 中從調試更改為發布。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.