Sample code for 30+ languages & platforms
PowerShell

Get the SSH Server's Authentication Methods

See more SSH Examples

Demonstrates the Chilkat Ssh.GetAuthMethods method, which queries a connected but unauthenticated SSH server for the authentication methods it advertises. It takes no arguments and returns a lowercase, comma-separated list such as publickey,password,keyboard-interactive. Call it after Connect and before authenticating.

Background: Knowing what the server accepts lets a client choose the right authentication path — for example, falling back to keyboard-interactive when password auth is not offered. Note the documented connection side effect: querying methods advances the SSH authentication state, so call it at the correct point in the sequence.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Demonstrates the Ssh.GetAuthMethods method, which queries a connected but unauthenticated SSH
#  server for the authentication methods it advertises.  It takes no arguments and returns a
#  lowercase, comma-separated list such as "publickey,password,keyboard-interactive".

$ssh = New-Object Chilkat.Ssh

#  Connect to the SSH server.  Port 22 is the usual SSH port.
$sshPort = 22
$success = $ssh.Connect("ssh.example.com",$sshPort)
if ($success -eq $false) {
    $($ssh.LastErrorText)
    exit
}

#  Query the advertised authentication methods.  Call after Connect, before authenticating.
$methods = $ssh.GetAuthMethods()
if ($ssh.LastMethodSuccess -eq $false) {
    $($ssh.LastErrorText)
    exit
}

$("Server auth methods: " + $methods)

$ssh.Disconnect()