Lua
Lua
Start SSH Tunnel Keyboard-Interactive Authentication
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.
Background: Keyboard-interactive is the prompt-driven authentication method: the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how a tunnel supports two-factor and other challenge-response schemes. The returned XML says exactly what to ask and whether to mask the input.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Demonstrates the SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive
-- authentication. The only argument is the login name. It returns XML describing the server's
-- prompts, which are answered with ContinueKeyboardAuth.
local tunnel = chilkat.SshTunnel.new()
-- The tunnel forwards accepted local connections to this destination through the SSH server.
tunnel.dest_hostname = "db.internal.example.com"
tunnel.dest_port = 5432
-- Connect to the SSH server. This performs the TCP/proxy connection and SSH handshake, but
-- does not authenticate yet.
local sshPort = 22
local success = tunnel:connect("ssh.example.com", sshPort)
if not success then
print(tunnel.last_error_text)
return
end
-- Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
local infoRequestXml = tunnel:start_keyboard_auth("mySshLogin")
if not tunnel.last_method_success then
print(tunnel.last_error_text)
return
end
print(infoRequestXml)
-- Answer the prompt(s) with ContinueKeyboardAuth, then call BeginAccepting.
local waitForThreadExit = true
success = tunnel:close_tunnel(waitForThreadExit)
if not success then
print(tunnel.last_error_text)
return
end