Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set socket [new_CkSocket]

set success [CkSocket_SshOpenTunnel $socket "ssh.example.com" 22]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    exit
}

#  Authenticate the SSH tunnel session with a login and password.
#  The SSH password should come from a secure source rather than being hard-coded.
set sshPassword "mySshPassword"
set success [CkSocket_SshAuthenticatePw $socket "sshUser" $sshPassword]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    exit
}

puts "SSH authentication succeeded."

delete_CkSocket $socket