gpt4 book ai didi

c - 使用 libssh 没有可用的身份验证方法

转载 作者:太空宇宙 更新时间:2023-11-04 08:27:44 24 4
gpt4 key购买 nike

即使我可以在我的服务器上使用各种方法进行身份验证,使用 libssh 库,也没有检测到任何身份验证方法。这是一个代码示例:

 #include <libssh/libssh.h>
#include <stdio.h>

int main(int,char**)
{
ssh_session session = ssh_new();
unsigned short port = 22;
int verbosity = SSH_LOG_PROTOCOL;

ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(session, SSH_OPTIONS_PORT, &port);
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_connect(session);

int supported_authentication_methods = ssh_userauth_list(session, NULL);

printf("Supported methods: %d\n", supported_authentication_methods);
return (0);
}

这是它产生的输出:

[2015/04/16 19:30:34.367528, 1] ssh_connect:  libssh 0.6.4 (c) 2003-2014 Aris Adamantiadis, Andreas Schneider, and libssh contributors. Distributed under the LGPL, please refer to COPYING file for information about your rights, using threading threads_noop
[2015/04/16 19:30:34.368626, 2] ssh_socket_connect: Nonblocking connection socket: 5
[2015/04/16 19:30:34.368643, 2] ssh_connect: Socket connecting, now waiting for the callbacks to work
[2015/04/16 19:30:34.368675, 1] socket_callback_connected: Socket connection callback: 1 (0)
[2015/04/16 19:30:34.400420, 1] ssh_client_connection_callback: SSH server banner: SSH-2.0-OpenSSH_6.2
[2015/04/16 19:30:34.400445, 1] ssh_analyze_banner: Analyzing banner: SSH-2.0-OpenSSH_6.2
[2015/04/16 19:30:34.400456, 1] ssh_analyze_banner: We are talking to an OpenSSH client version: 6.2 (60200)
[2015/04/16 19:30:34.426885, 2] ssh_packet_dh_reply: Received SSH_KEXDH_REPLY
[2015/04/16 19:30:34.427292, 2] ssh_client_dh_reply: SSH_MSG_NEWKEYS sent
[2015/04/16 19:30:34.427311, 2] ssh_packet_newkeys: Received SSH_MSG_NEWKEYS
[2015/04/16 19:30:34.427908, 2] ssh_packet_newkeys: Signature verified and valid
Supported methods: 0

如输出所示,未检测到任何身份验证方法...这很奇怪,因为我绝对可以使用密码和 key 登录到本地主机...这是怎么回事?

最佳答案

根据 docs :

This requires the function ssh_userauth_none() to be called before the methods are available.

所以先调用ssh_userauth_none()。服务器以可用选项列表作为响应,这就是 ssh_userauth_list() 知道要返回什么的方式。

(void)ssh_userauth_none(session, NULL);
int supported_authentication_methods = ssh_userauth_list(session, NULL);

关于c - 使用 libssh 没有可用的身份验证方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29682023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com