Sample code for 30+ languages & platforms
Unicode C

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

Unicode C
#include <C_CkSocketW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSocketW socket;
    const wchar_t *sshPassword;

    success = FALSE;

    socket = CkSocketW_Create();

    success = CkSocketW_SshOpenTunnel(socket,L"ssh.example.com",22);
    if (success == FALSE) {
        wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
        CkSocketW_Dispose(socket);
        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.
    sshPassword = L"mySshPassword";
    success = CkSocketW_SshAuthenticatePw(socket,L"sshUser",sshPassword);
    if (success == FALSE) {
        wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
        CkSocketW_Dispose(socket);
        return;
    }

    wprintf(L"SSH authentication succeeded.\n");


    CkSocketW_Dispose(socket);

    }