JavaScript
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
var socket = new CkSocket();
success = socket.SshOpenTunnel("ssh.example.com",22);
if (success == false) {
console.log(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.
var sshPassword = "mySshPassword";
success = socket.SshAuthenticatePw("sshUser",sshPassword);
if (success == false) {
console.log(socket.LastErrorText);
return;
}
console.log("SSH authentication succeeded.");