Unicode C++
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
#include <CkSocketW.h>
void ChilkatSample(void)
{
bool success = false;
CkSocketW socket;
success = socket.SshOpenTunnel(L"ssh.example.com",22);
if (success == false) {
wprintf(L"%s\n",socket.lastErrorText());
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 wchar_t *sshPassword = L"mySshPassword";
success = socket.SshAuthenticatePw(L"sshUser",sshPassword);
if (success == false) {
wprintf(L"%s\n",socket.lastErrorText());
return;
}
wprintf(L"SSH authentication succeeded.\n");
}