C
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 C Downloads
#include <C_CkSocket.h>
void ChilkatSample(void)
{
BOOL success;
HCkSocket socket;
const char *sshPassword;
success = FALSE;
socket = CkSocket_Create();
success = CkSocket_SshOpenTunnel(socket,"ssh.example.com",22);
if (success == FALSE) {
printf("%s\n",CkSocket_lastErrorText(socket));
CkSocket_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 = "mySshPassword";
success = CkSocket_SshAuthenticatePw(socket,"sshUser",sshPassword);
if (success == FALSE) {
printf("%s\n",CkSocket_lastErrorText(socket));
CkSocket_Dispose(socket);
return;
}
printf("SSH authentication succeeded.\n");
CkSocket_Dispose(socket);
}