Sample code for 30+ languages & platforms
Tcl

Start SSH Keyboard-Interactive Authentication

See more SSH Examples

Demonstrates the Chilkat Ssh.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts and whether each response should be echoed. Answer the prompts with ContinueKeyboardAuth.

Background: Keyboard-interactive is the flexible, prompt-driven SSH method — the server sends one or more questions (a password, a one-time code, a security question) and the client answers each. It is how SSH supports two-factor and other challenge-response schemes. The returned XML tells you exactly what to ask the user and whether to mask their input.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Ssh.StartKeyboardAuth method, which begins keyboard-interactive
#  authentication.  The only argument is the login name.  It returns XML describing the server's
#  prompts and whether each response should be echoed.

set ssh [new_CkSsh]

#  Connect to the SSH server.  Port 22 is the usual SSH port.
set sshPort 22
set success [CkSsh_Connect $ssh "ssh.example.com" $sshPort]
if {$success == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

#  Begin keyboard-interactive authentication.  The returned XML describes the prompts.
set infoRequestXml [CkSsh_startKeyboardAuth $ssh "mySshLogin"]
if {[CkSsh_get_LastMethodSuccess $ssh] == 0} then {
    puts [CkSsh_lastErrorText $ssh]
    delete_CkSsh $ssh
    exit
}

puts "$infoRequestXml"

#  Answer the prompt(s) with ContinueKeyboardAuth.

CkSsh_Disconnect $ssh

delete_CkSsh $ssh