我的SSH服务器使用双重身份验证。我不知道它是如何实现的。但是最初它要求输入密码,然后再次要求输入另一个密码以登录到与通常的控制不同的单独控制台。
我的代码类似于文档中显示的示例代码,
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <libssh/libssh.h>
int main(int argc, char * argv[])
{
ssh_session my_ssh_session = ssh_new();
int rc;
char * password;
char * username = "admin";
// Check if ssh session exists.
if(my_ssh_session == NULL)
{
exit(-1);
}
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "x.x.x.x");
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error Connecting to Server: %s.\n", ssh_get_error(my_ssh_session));
exit(-1);
}
password = getpass("Password: ");
rc = ssh_userauth_password(my_ssh_session, username, password);
if (rc != SSH_AUTH_SUCCESS)
{
fprintf(stderr, "ERROR Authenticating: %s.\n", ssh_get_error(my_ssh_session));
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
else
{
printf("Authentication Successful.\n");
}
ssh_free(my_ssh_session);
}
如何在此实现双重认证?你能帮我吗?
最佳答案
什么版本的
你有libssh吗?
“版本0.5.1及更高版本在处理SSH_MSG_NEWKEYS和SSH_MSG_KEXDH_REPLY程序包时存在逻辑错误。检测到的错误未将会话正确设置为错误状态,并进一步处理了数据包,导致空指针取消引用。这是初始密钥交换后的数据包,并且不需要身份验证。”
参考libssh
关于c - 如何使用libssh模块进行双重身份验证?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31697261/