A C++23 SSH server library built on top of libssh.
#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 thereThe 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().
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
echo_server.cppreturns the command string.kv_server.cppimplements aread/write/deletestore over SSH.pipe_server.cpprelays one session's stdin to another session's stdout by topic.
See the nix flake for dependencies.
nix develop
just # build
just test # run tests