Skip to content

Repository files navigation

cppssh

A C++23 SSH server library built on top of libssh.

Quickstart

#include <cppssh/server.hpp>

int main() {
    cppssh::Server server("./example_host_key");
    server.allow_keyless = true;
    server.handler = [](cppssh::Session& s) -> cppssh::Task {
        s.println("you ran: {}", s.command());
        s.exit(0);
        co_return;
    };
    server.listen_and_serve("0.0.0.0:2223");
}
$ ssh -p 2223 localhost hello there
you ran: hello there

Sessions

The handler lambda runs once per authenticated session, as a coroutine, with a Session that interfaces to the SSH channel. stdin is read through co_await s.read().

Auth

Public-key authentication is required by default. public_key_handler is called per offered key and returns whether it is accepted:

server.public_key_handler = [](const cppssh::PublicKey& key) {
    return key.fingerprint() == "...";
};

Setting allow_keyless = true disables key authentication

Examples

  • echo_server.cpp returns the command string.
  • kv_server.cpp implements a read/write/delete store over SSH.
  • pipe_server.cpp relays one session's stdin to another session's stdout by topic.

Development

See the nix flake for dependencies.

nix develop
just         # build
just test    # run tests

About

C++23 ssh server library with coroutine support

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages