libssh 服务器无法导入私人 RSA 主机密钥
libssh server failed to import private RSA host key
在 linux 中尝试获取 libssh 服务器 运行 时,我遇到了错误侦听套接字:无法导入私有 RSA 主机密钥。我正在使用两个示例作为参考。 https://github.com/substack/libssh/blob/master/examples/samplesshd.c and https://github.com/PeteMo/sshpot/blob/master/main.c。但是后一个参考文献提到使用 public 密钥,在自述文件中不是私有的,这让我感到困惑。
我仍然是一个嫩足C从业者,所以我很确定我做错了什么。也许甚至 asm 他自己(我相信是创造者)也会给我一两个快速提示。这是我的代码:
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#include <libssh/legacy.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define SSHD_USER "user"
#define SSHD_PASSWORD "password"
#define KEYS_FILE "./ssh_host_rsa_key"
/*#ifndef KEYS_FILE
#define KEYS_FILE
#else
#endif*/
static int auth_password(char *user, char *password)
{
if(strcmp(user, SSHD_USER)) {
return 0;
} else {
return 1;
}
if(strcmp(password, SSHD_PASSWORD)) {
return 0;
} else {
return 1;
}
return 0;
}
int main()
{
ssh_bind sshbind = ssh_bind_new();
ssh_session my_session = ssh_new();
int port = 900;
char *address = "127.0.0.1";
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, address);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, &port);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "ssh-rsa");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FILE);
if (ssh_bind_listen(sshbind) < 0) {
printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
return 1;
}
/* Loop, waiting for and handling connection attempts. */
while(1) {
if (ssh_bind_accept(sshbind, my_session) == SSH_ERROR) {
fprintf(stderr, "Error accepting a connection: `%s'.\n",ssh_get_error(sshbind));
return -1;
} else {
printf("Accepted a connection.\n");
}
switch (fork()) {
case -1:
fprintf(stderr,"Fork returned error: `%d'.\n",-1);
exit(-1);
case 0:
exit(auth_password(SSHD_USER, SSHD_PASSWORD));
default:
break;
}
}
return 0;
}
侦听套接字时出错:导入私有 RSA 主机密钥失败
我也尝试过以多种方式直接将ssh_host_rsa_key的内容用作变量。官方参考文档有这一行
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key")
我也将它与 #define KEYS_FILE if else 块一起使用,我在尝试其他方法时将其注释掉了。现在我的私钥和我的服务器在同一个目录中(出于无奈)。
非常感谢任何提示或提示!
万一有人遇到这个问题,我的解决方案是生成新的 ssh 密钥和 link 我的代码。无论出于何种原因,我第一次生成的密钥都不起作用,但删除它们并使用新的一对有效。
没有人会读到这些话。
在 linux 中尝试获取 libssh 服务器 运行 时,我遇到了错误侦听套接字:无法导入私有 RSA 主机密钥。我正在使用两个示例作为参考。 https://github.com/substack/libssh/blob/master/examples/samplesshd.c and https://github.com/PeteMo/sshpot/blob/master/main.c。但是后一个参考文献提到使用 public 密钥,在自述文件中不是私有的,这让我感到困惑。
我仍然是一个嫩足C从业者,所以我很确定我做错了什么。也许甚至 asm 他自己(我相信是创造者)也会给我一两个快速提示。这是我的代码:
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#include <libssh/legacy.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define SSHD_USER "user"
#define SSHD_PASSWORD "password"
#define KEYS_FILE "./ssh_host_rsa_key"
/*#ifndef KEYS_FILE
#define KEYS_FILE
#else
#endif*/
static int auth_password(char *user, char *password)
{
if(strcmp(user, SSHD_USER)) {
return 0;
} else {
return 1;
}
if(strcmp(password, SSHD_PASSWORD)) {
return 0;
} else {
return 1;
}
return 0;
}
int main()
{
ssh_bind sshbind = ssh_bind_new();
ssh_session my_session = ssh_new();
int port = 900;
char *address = "127.0.0.1";
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, address);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, &port);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "ssh-rsa");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FILE);
if (ssh_bind_listen(sshbind) < 0) {
printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
return 1;
}
/* Loop, waiting for and handling connection attempts. */
while(1) {
if (ssh_bind_accept(sshbind, my_session) == SSH_ERROR) {
fprintf(stderr, "Error accepting a connection: `%s'.\n",ssh_get_error(sshbind));
return -1;
} else {
printf("Accepted a connection.\n");
}
switch (fork()) {
case -1:
fprintf(stderr,"Fork returned error: `%d'.\n",-1);
exit(-1);
case 0:
exit(auth_password(SSHD_USER, SSHD_PASSWORD));
default:
break;
}
}
return 0;
}
侦听套接字时出错:导入私有 RSA 主机密钥失败
我也尝试过以多种方式直接将ssh_host_rsa_key的内容用作变量。官方参考文档有这一行
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key")
我也将它与 #define KEYS_FILE if else 块一起使用,我在尝试其他方法时将其注释掉了。现在我的私钥和我的服务器在同一个目录中(出于无奈)。
非常感谢任何提示或提示!
万一有人遇到这个问题,我的解决方案是生成新的 ssh 密钥和 link 我的代码。无论出于何种原因,我第一次生成的密钥都不起作用,但删除它们并使用新的一对有效。 没有人会读到这些话。