Skip to content
TheEliteCodezPublic

About

Standalone C++17 SSHv2 client using OpenSSL and platform sockets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NanoSSH

NanoSSH is a standalone C++17 SSHv2 client by Gregory King.

Dependencies: CMake 3.20+, a C++17 compiler, and OpenSSL Crypto 1.1.1 or later with its legacy APIs enabled. Windows also links Winsock. No libssh dependency.

Build on Windows

cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DOPENSSL_ROOT_DIR="C:/Program Files/OpenSSL"
cmake --build build --config Release

Open build/NanoSSH.sln in Visual Studio, or build from the command line. With a shared OpenSSL build, its runtime DLL and any dependencies must be on PATH or beside the executable. The MSVC runtime must also be installed.

MinGW is also supported; point CMake to the matching compiler and OpenSSL installation:

cmake -S . -B build-mingw -G Ninja -DCMAKE_CXX_COMPILER=C:/Strawberry/c/bin/g++.exe -DOPENSSL_ROOT_DIR=C:/Strawberry/c -DOPENSSL_INCLUDE_DIR=C:/Strawberry/c/include -DOPENSSL_CRYPTO_LIBRARY=C:/Strawberry/c/lib/libcrypto.a -DCMAKE_BUILD_TYPE=Release
cmake --build build-mingw

Build on Linux

Install a C++ compiler, CMake, and OpenSSL development files. GoogleTest is needed when tests are enabled.

cmake -S . -B build -DBUILD_TESTING=OFF
cmake --build build

Use

The example connects using an existing private key and executes one command:

.\build\Release\nanossh_exec.exe 127.0.0.1 2222 username C:/keys/id_rsa "whoami"

Include Core/NanoSSH.h, construct Common::NanoSSH, and call Connect, Handshake, then AuthenticatePassword or AuthenticatePrivateKey. ExecuteCommand requests a PTY and collects output. UploadFile writes through a remote shell command, rather than SFTP. Connections currently accept numeric IPv4 addresses. Instances own socket and cryptographic resources and cannot be copied. Windows socket initialization is handled by the library.

For another CMake project, use add_subdirectory and link NanoSSH::nanossh, or install the package:

cmake --install build --config Release --prefix C:/local/NanoSSH

Then configure the consumer with that prefix in CMAKE_PREFIX_PATH:

find_package(NanoSSH CONFIG REQUIRED)
target_link_libraries(your_app PRIVATE NanoSSH::nanossh)

Runtime test

The GoogleTest integration test starts a temporary loopback OpenSSH daemon, generates RSA keys, authenticates, and checks that tty reports a PTY. It requires Linux, GoogleTest, ssh-keygen, sshd, and a non-root local account that sshd can authenticate. Missing OpenSSH executables cause a skip. Windows does not register this Linux-only test.

cmake -S . -B build-tests -DBUILD_TESTING=ON
cmake --build build-tests
ctest --test-dir build-tests --output-on-failure

Client behavior

NanoSSH supports password and private-key authentication, key exchange, command execution, and file uploads through a remote shell. The SSH client banner is SSH-2.0-NanoSSH_1.0.

Existing protocol limitations remain: host signature verification does not provide known-host identity checking, encrypted private-key passphrases are not exposed by the API, command success reports request acceptance rather than the remote exit status, and the socket code assumes full packet reads/writes in several paths.

Validation

Validated with MSVC 19.44 / OpenSSL 3.6.0 and MinGW GCC 13.2 / OpenSSL 3.3.0: both Release builds passed. Installing the MSVC library and building a separate find_package(NanoSSH) consumer passed. The MinGW example launched and returned the expected usage and refused-connection exit codes (2 and 1).

The local MSVC OpenSSL DLL requires a missing z.dll, so MSVC executable runtime validation remains blocked by that installation. WSL lacks the Linux build and OpenSSH prerequisites, so the real SSH authentication/PTY integration test has not been run for this version.

About

Standalone C++17 SSHv2 client using OpenSSL and platform sockets

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages