Sample code for 30+ languages & platforms
Zig

Start SSH Keyboard-Interactive Authentication

See more SSH Examples

Demonstrates the Chilkat Ssh.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts and whether each response should be echoed. Answer the prompts with ContinueKeyboardAuth.

Background: Keyboard-interactive is the flexible, prompt-driven SSH method — the server sends one or more questions (a password, a one-time code, a security question) and the client answers each. It is how SSH supports two-factor and other challenge-response schemes. The returned XML tells you exactly what to ask the user and whether to mask their input.

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();

    // Demonstrates the Ssh.StartKeyboardAuth method, which begins keyboard-interactive
    // authentication.  The only argument is the login name.  It returns XML describing the server's
    // prompts and whether each response should be echoed.

    const ssh = try chilkat.Ssh.init();
    defer ssh.deinit();

    // Connect to the SSH server.  Port 22 is the usual SSH port.
    const ssh_port = 22;
    ssh.connect("ssh.example.com", ssh_port) catch {
        std.debug.print("{s}\n", .{try ssh.getLastErrorText(alloc)});
        return;
    };

    // Begin keyboard-interactive authentication.  The returned XML describes the prompts.
    const info_request_xml = ssh.startKeyboardAuth(alloc, "mySshLogin") catch {
        std.debug.print("{s}\n", .{try ssh.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{info_request_xml});

    // Answer the prompt(s) with ContinueKeyboardAuth.

    ssh.disconnect();
}