我正在尝试一个非常简单的实现,libssh但valgrind显示内存泄漏.
代码是:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main()
{
ssh_session my_ssh_session = ssh_new();
int port = 22;
int rc, state;
const char *ip = "192.168.125.241";
char *password;
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, ip);
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error connecting to localhost: %s\n",
ssh_get_error(my_ssh_session));
exit(-1);
}
state = ssh_is_server_known(my_ssh_session);
if(state == SSH_SERVER_KNOWN_OK)
printf("already added\n");
else
printf("require addition\n");
rc = ssh_userauth_password(my_ssh_session, "rohit", "password");
if …Run Code Online (Sandbox Code Playgroud) 问题
我尝试使用libssh和libssh-C++-wrapper进行本地端口转发。我的目的是通过 SSH 将localhost:3306服务器localhost:3307上的端口转发到我的机器上,以通过 MySQL 连接到localhost:3307.
void ssh_session::forward(){
ssh::Channel channel(this->session);
//remotehost, remoteport, localhost, localport
channel.openForward("localhost",3306,"localhost",3307);
std::cout<< "Channel is " << (channel.isOpen()?"open!":"closed!") << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
withsession在ssh::Channel类型为 的构造函数中ssh::Session。
上面的代码打印Channel is open!. 如果我尝试localhost:3307使用MySQL Connector/C++ 连接,我会得到
错误 2003 (HY000):无法连接到“127.0.0.1”上的 MySQL 服务器 (61)
观察
$ ssh -L 3307:localhost:3306 me@myserver.com一切正常,我可以连接。ssh::Session session在构造函数中使用used 或ssh::Channel channel执行远程 shell 命令,一切正常,因此会话很好! …我目前正在研究与SSH服务器通信的客户端.一切都运行良好,但是,因为服务器回答很慢,我不得不等待它发送数据.我有两个选择,我想就什么是等待服务器的最有效方法提出建议.
选择#1:
while (!(ssh_channel_poll(*sshChannel,0)))
;
Run Code Online (Sandbox Code Playgroud)
选择#2:
while (!(ssh_channel_poll(*sshChannel,0)))
sleep(1);
Run Code Online (Sandbox Code Playgroud) 尝试 ./configure libcurl 7.22.0 时出现以下错误
链接时可用的一个或多个库在运行时不可用。链接时使用的库:-lssh2 -lssl -lcrypto -lrt -lz
当我使用--without-libssh2 ./configure 时,它工作得很好。
我已采取的步骤:
apt-get install libssl-dev
apt-get install libssh-dev
cd /var
wget http://www.libssh2.org/download/libssh2-1.3.0.tar.gz
tar -zxvf libssh2-1.3.0.tar.gz
cd libssh2-1.3.0
./configure
make
make install
Run Code Online (Sandbox Code Playgroud)
顺便说一句,SSL 支持运行良好。我一定是 libssh 做错了什么
我也尝试过:
./configure --with-libssh2
./configure --with-libssh2-path=/usr/local/lib
./configure --with-libssh2=/usr
./configure --with-libssh2=/usr/local/lib
Run Code Online (Sandbox Code Playgroud)
但这并没有什么区别。我不知道还能尝试什么。
当尝试在 Linux 中运行 libssh 服务器时,我遇到了错误侦听套接字:无法导入私有 RSA 主机密钥。我使用了两个例子作为参考。https://github.com/substack/libssh/blob/master/examples/samplesshd.c和https://github.com/PeteMo/sshpot/blob/master/main.c。但后一个参考文献在自述文件中提到使用公钥,而不是私钥,这让我感到困惑。
我仍然是一个新手 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 …Run Code Online (Sandbox Code Playgroud) 我想知道在与Sourcery工具链进行ARM交叉编译时是否有可能将我的应用程序链接到libssh。我的主机系统是Ubuntu x86_64
:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm `pkg-config --cflags --libs libssh`
cc1: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
/home/user/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libssh.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我的应用使用gcc使用以下命令可以正常编译:
gcc ssh.c -o ssh -lssh
Run Code Online (Sandbox Code Playgroud)
交叉编译时添加相同的-lssh标志会导致以下错误:
:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm -lssh
ssh.c:2:49: fatal error: libssh/libssh.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud) 每次我尝试在 Ubuntu 上使用 gcc 编译代码时都会收到错误。
我通过输入以下命令安装了 libssh-dev:
sudo apt-get install libssh-dev
Run Code Online (Sandbox Code Playgroud)
它安装得很好(没有错误消息)
我试图编译的代码是:
#include <stdlib.h>
#include <stdio.h>
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
int main(void){
int rc;
int port = 21;
char *pass = "password";
ssh_session my_ssh_session = ssh_new();
if(my_ssh_session == NULL){
exit(-1);
}
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "username");
rc = ssh_connect(my_ssh_session);
if(rc != SSH_OK){
fprintf(stderr, "Error connecting to localhost: %s\n", ssh_get_error(my_ssh_session) );
exit(-1);
}
ssh_userauth_password(my_ssh_session, NULL, pass);
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译代码时,错误消息显示:
user@neodym:~/Desktop/projects/ssh$ gcc -lssh ssh_client.c
/tmp/ccGihId0.o: …Run Code Online (Sandbox Code Playgroud) 我正在为我正在研究的linux程序编写一些代码,需要libssh.我正在查看他们的教程页面,我看到它通过ssh_options_set()引用传递所有参数.这是为什么?
#include <libssh/libssh.h>
#include <stdlib.h>
int main()
{
ssh_session my_ssh_session;
int verbosity = SSH_LOG_PROTOCOL;
int port = 22;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); //here
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port); //here
...
ssh_free(my_ssh_session);
}
Run Code Online (Sandbox Code Playgroud) 有人可以帮我登录ssh并发送简单的ls命令吗?这是我的代码:
你能帮帮我吗?这是我的代码:
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int verbosity = SSH_LOG_PROTOCOL;
int rc;
int port = 22;
char user = "root";
char pass = "password";
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "192.168.1.100");
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, user);
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
rc = ssh_userauth_password(my_ssh_session,NULL,pass);
if (rc == SSH_AUTH_ERROR)
{
fprintf(stderr, "Error connecting to localhost: %s\n",
ssh_get_error(my_ssh_session));
exit(-1);
}
rc = ssh_channel_request_exec(my_ssh_session, "ls -l");
if (rc != SSH_OK)
{ …Run Code Online (Sandbox Code Playgroud)