【问题标题】:no authentication methods available using libssh没有使用 libssh 可用的身份验证方法
【发布时间】:2015-04-17 01:38:03
【问题描述】:

尽管我可以在我的服务器上使用各种方法进行身份验证,但使用 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

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

【问题讨论】:

    标签: c libssh


    【解决方案1】:

    根据docs

    这需要在方法可用之前调用函数ssh_userauth_none()

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

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

    【讨论】:

    • 天哪...我看到它,我只是不明白为什么它在那里,决定不使用它,并且花了最后 1 小时 30 左右来解决这个问题...谢谢!
    • 嗯...我试图在我的程序中正确实现它...问题是,文档似乎说ssh_userauth_none应该返回SSH_AUTH_SUCCESS...事实是,尽管事实上它确实工作,该函数不会为我返回SSH_AUTH_SUCCESS...这很棘手。
    • 我根本不会那样阅读文档。除非您的服务器允许完全匿名访问,否则我希望 SSH_AUTH_DENIED 或 SSH_AUTH_PARTIAL
    • 哦。好吧,我没这么看。另外...ssh_userauth_list 一直告诉我我无法使用登录/密码方法登录(尽管它确实接受公钥和其他方法)...但是我尝试使用的所有服务器在我使用时都接受该方法ssh 客户端...知道为什么会这样吗?
    • 对不起,不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2019-08-16
    • 2022-01-11
    相关资源
    最近更新 更多