Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkSshW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSshW ssh;
    int sshPort;
    const wchar_t *infoRequestXml;

    success = FALSE;

    //  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.

    ssh = CkSshW_Create();

    //  Connect to the SSH server.  Port 22 is the usual SSH port.
    sshPort = 22;
    success = CkSshW_Connect(ssh,L"ssh.example.com",sshPort);
    if (success == FALSE) {
        wprintf(L"%s\n",CkSshW_lastErrorText(ssh));
        CkSshW_Dispose(ssh);
        return;
    }

    //  Begin keyboard-interactive authentication.  The returned XML describes the prompts.
    infoRequestXml = CkSshW_startKeyboardAuth(ssh,L"mySshLogin");
    if (CkSshW_getLastMethodSuccess(ssh) == FALSE) {
        wprintf(L"%s\n",CkSshW_lastErrorText(ssh));
        CkSshW_Dispose(ssh);
        return;
    }

    wprintf(L"%s\n",infoRequestXml);

    //  Answer the prompt(s) with ContinueKeyboardAuth.

    CkSshW_Disconnect(ssh);


    CkSshW_Dispose(ssh);

    }