Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
let socket = CkoSocket()!
success = socket.sshOpenTunnel(sshHostname: "ssh.example.com", sshPort: 22)
if success == false {
print("\(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: String? = "mySshPassword"
success = socket.sshAuthenticatePw(sshLogin: "sshUser", sshPassword: sshPassword)
if success == false {
print("\(socket.lastErrorText!)")
return
}
print("SSH authentication succeeded.")
}