No description
Find a file
2025-03-19 18:22:39 +07:00
.github Create FUNDING.yml 2021-10-01 07:41:17 +07:00
examples fix libssh2_scp_recv requires a ptr to Stat. refs: ba0f3/ssh2.nim#16 2024-02-23 10:07:48 +07:00
.gitignore WIP 2015-07-25 04:58:24 +07:00
libssh2.nim update libssh2 binding to version 1.11.1 2025-03-19 18:19:38 +07:00
libssh2.nimble update libssh2 binding to version 1.11.1 2025-03-19 18:19:38 +07:00
LICENSE Initial commit 2015-07-25 03:50:04 +07:00
README.md Update README 2025-03-19 18:22:39 +07:00

libssh2.nim

Nim wrapper for libssh2

A Nim binding for the libssh2 library, providing SSH client functionality.

For documentation please refer to libssh2 website.

Version Compatibility

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

Installation

Using Nimble

The easiest way to install libssh2.nim is using the Nimble package manager:

nimble install libssh2

Dependencies

In order to use this wrapper, libssh2 must be installed on your system:

Mac OSX:

$ port install libssh2

or

$ brew install libssh2

Ubuntu/Debian:

$ apt-get install libssh2-1-dev

Windows:

There are several ways to install libssh2 on Windows:

  1. Using vcpkg:
vcpkg install libssh2
  1. Using MSYS2:
pacman -S mingw-w64-x86_64-libssh2
  1. Download pre-built binaries from the libssh2 website or build from source.

Basic Usage

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.

License

This Nim wrapper is distributed under the MIT License.

libssh2 itself is licensed under the BSD license. See the libssh2 license for details.