libSSH2是一个开源的C函数库,用来实现SSH2协议。
SSH(Secure SHell)到目前为止有两个不兼容的版本——SSH1和SSH2。
SSH2避免了RSA的专利问题,并修补了CRC的缺陷,增加了AES和Twofish等对称加密算法。
libSSH2网站:
libSSH2
下载压缩包:libssh2-1.10.0.tar.gz
解压缩libssh2-1.10.0.tar.gz文件。
进入libssh2-1.10.0目录
CMakeLists.txt记录了要加载的文件目录。
windows环境下的libssh2_config.h文件:
从libssh2-1.10.0/win32目录下,拷贝libssh2_config.h,到win目录下:
linuxmac目录下的libssh2_config.h文件进行修改如下:
配置头文件:
#头文件
HEADERS += ./agent.h \
./blf.h \
./channel.h \
./comp.h \
./crypto.h \
./libssh2.h \
./libssh2_priv.h \
./mac.h \
./mbedtls.h \
./misc.h \
./openssl.h \
./packet.h \
./session.h \
./sftp.h \
./transport.h \
./userauth.h \
./wincng.h
win32 {
HEADERS += ./win/libssh2_config.h
}
linux* {
HEADERS += ./linuxmac/libssh2_config.h
}
macx {
HEADERS += ./linuxmac/libssh2_config.h
}
配置源文件:
#源文件
SOURCES += ./agent.c \
./agent_win.c \
./bcrypt_pbkdf.c \
./blowfish.c \
./channel.c \
./comp.c \
./crypt.c \
./global.c \
./hostkey.c \
./keepalive.c \
./kex.c \
./knownhost.c \
./mac.c \
./mbedtls.c \
./misc.c \
./openssl.c \
./packet.c \
./pem.c \
./publickey.c \
./scp.c \
./session.c \
./sftp.c \
./transport.c \
./userauth.c \
./version.c \
./wincng.c
配置预定义项:
DEFINES -= UNICODE
DEFINES += LIBSSH2_OPENSSL
win32 {
DEFINES += LIBSSH2_WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}
依赖库配置:
win32 {
LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/lib
LIBS += -llibcrypto
LIBS += -luser32 -lws2_32
}
linux* {
LIBS += -lcrypto
}
macx {
LIBS += -L/usr/local/opt/openssl@3/lib
LIBS += -lcrypto
}
形成003.libssh2-1.10.0.pro文件:
QT += core network
TEMPLATE = lib
CONFIG += c++17
DESTDIR = ../QGIS
CONFIG(debug, debug|release){
MOC_DIR = ../build-QGIS/ssh2/Debug/moc
RCC_DIR = ../build-QGIS/ssh2/Debug/rcc
UI_DIR = ../build-QGIS/ssh2/Debug/ui
OBJECTS_DIR = ../build-QGIS/ssh2/Debug/obj
}else{
MOC_DIR = ../build-QGIS/ssh2/Release/moc
RCC_DIR = ../build-QGIS/ssh2/Release/rcc
UI_DIR = ../build-QGIS/ssh2/Release/ui
OBJECTS_DIR = ../build-QGIS/ssh2/Release/obj
}
CONFIG(debug, debug|release){
TARGET = ssh2d
}else{
TARGET = ssh2
}
DEFINES -= UNICODE
DEFINES += LIBSSH2_OPENSSL
win32 {
DEFINES += LIBSSH2_WIN32 _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE
}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#当前目录
INCLUDEPATH += ./
#openssl路径
win32 {
INCLUDEPATH += ./win
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include
INCLUDEPATH += D:/Qt/Tools/OpenSSL/Win_x64/include/openssl
}
linux* {
INCLUDEPATH += ./linuxmac
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include
INCLUDEPATH += /opt/Qt/Tools/OpenSSL/src/include/openssl
}
macx {
INCLUDEPATH += ./linuxmac
INCLUDEPATH += /usr/local/opt/openssl@3/include
INCLUDEPATH += /usr/local/opt/openssl@3/include/openssl
}
#ZLIB路径
INCLUDEPATH += ../zlib-1.2.12
#LIBS
LIBS += -L../QGIS
CONFIG(debug, debug|release){
LIBS += -lzlibd
}else{
LIBS += -lzlib
}
win32 {
LIBS += -LD:/Qt/Tools/OpenSSL/Win_x64/lib
LIBS += -llibcrypto
LIBS += -luser32 -lws2_32
}
linux* {
LIBS += -lcrypto
}
macx {
LIBS += -L/usr/local/opt/openssl@3/lib
LIBS += -lcrypto
}
#头文件
HEADERS += ./agent.h \
./blf.h \
./channel.h \
./comp.h \
./crypto.h \
./libssh2.h \
./libssh2_priv.h \
./mac.h \
./mbedtls.h \
./misc.h \
./openssl.h \
./packet.h \
./session.h \
./sftp.h \
./transport.h \
./userauth.h \
./wincng.h
win32 {
HEADERS += ./win/libssh2_config.h
}
linux* {
HEADERS += ./linuxmac/libssh2_config.h
}
macx {
HEADERS += ./linuxmac/libssh2_config.h
}
#源文件
SOURCES += ./agent.c \
./agent_win.c \
./bcrypt_pbkdf.c \
./blowfish.c \
./channel.c \
./comp.c \
./crypt.c \
./global.c \
./hostkey.c \
./keepalive.c \
./kex.c \
./knownhost.c \
./mac.c \
./mbedtls.c \
./misc.c \
./openssl.c \
./packet.c \
./pem.c \
./publickey.c \
./scp.c \
./session.c \
./sftp.c \
./transport.c \
./userauth.c \
./version.c \
./wincng.c
# Default rules for deployment.
#unix {
# target.path = /usr/lib
#}
#!isEmpty(target.path): INSTALLS += target
用QtCreator程序,打开003.libssh2-1.10.0.pro文件。
在windows下编译,形成:
在linux下编译,形成:
在macos下编译,形成: