Sample code for 30+ languages & platforms
Zig

Authenticate an SSH Tunnel with a Password

See more Socket/SSL/TLS Examples

Demonstrates Socket.SshAuthenticatePw, which authenticates an SSH tunnel session using a login and password. Call SshOpenTunnel first.

Background. Authenticate before opening forwarded channels. The password should come from a secure source and never be logged; public-key authentication is often preferred.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const socket = try chilkat.Socket.init();
    defer socket.deinit();

    socket.sshOpenTunnel("ssh.example.com", 22) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    // Authenticate the SSH tunnel session with a login and password.
    // The SSH password should come from a secure source rather than being hard-coded.
    const ssh_password = "mySshPassword";
    socket.sshAuthenticatePw("sshUser", ssh_password) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("SSH authentication succeeded.\n", .{});
}