Nim wrapper for libssh2
A Nim binding for the libssh2 library, providing SSH client functionality.
For documentation please refer to libssh2 website.
This wrapper is compatible with libssh2 version 1.11.1 and includes support for:
- Security key authentication
- Various crypto engines
- Session timeouts
- Modern host key types
- All standard libssh2 functionality
The easiest way to install libssh2.nim is using the Nimble package manager:
nimble install libssh2
In order to use this wrapper, libssh2 must be installed on your system:
$ port install libssh2
or
$ brew install libssh2
$ apt-get install libssh2-1-dev
There are several ways to install libssh2 on Windows:
- Using vcpkg:
vcpkg install libssh2
- Using MSYS2:
pacman -S mingw-w64-x86_64-libssh2
- Download pre-built binaries from the libssh2 website or build from source.
Here's a simple example of how to connect to an SSH server:
import libssh2
proc main() =
# Initialize libssh2
discard libssh2_init(0)
# Create a new session instance
let session = libssh2_session_init()
defer: libssh2_session_free(session)
# Connect to the server using your preferred socket library
# ... socket connection code ...
let socket = connectToServer("example.com", 22)
# Start the SSH session on the connected socket
if libssh2_session_handshake(session, socket) != 0:
echo "Failed to establish SSH session"
return
# Authenticate
if libssh2_userauth_password(session, "username", "password") != 0:
echo "Authentication failed"
return
echo "Successfully connected and authenticated"
# Clean up
libssh2_exit()
when isMainModule:
main()
See the examples directory for more comprehensive usage examples.
This Nim wrapper is distributed under the MIT License.
libssh2 itself is licensed under the BSD license. See the libssh2 license for details.