Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSsh
LOCAL nSshPort
LOCAL cMethods

nSuccess := 0

//  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".

oSsh := CreateObject("Chilkat.Ssh")

//  Connect to the SSH server.  Port 22 is the usual SSH port.
nSshPort := 22
nSuccess := oSsh:Connect("ssh.example.com", nSshPort)
IF (nSuccess == 0)
    ? oSsh:LastErrorText
    oSsh:destroy()
    RETURN
ENDIF

//  Query the advertised authentication methods.  Call after Connect, before authenticating.
cMethods := oSsh:GetAuthMethods()
IF (oSsh:LastMethodSuccess == 0)
    ? oSsh:LastErrorText
    oSsh:destroy()
    RETURN
ENDIF

? "Server auth methods: " + cMethods

oSsh:Disconnect()

oSsh:destroy()