--- example/ssh2_exec.c.orig	2010-04-18 16:13:20.000000000 -0700
+++ example/ssh2_exec.c	2010-04-18 16:34:40.000000000 -0700
@@ -42,6 +42,31 @@
 #include <stdio.h>
 #include <ctype.h>
 
+#define AUTH_PUBLICKEY            (1 << 0)
+#define AUTH_PASSWORD             (1 << 1)
+#define AUTH_KEYBOARD_INTERACTIVE (1 << 2)
+
+const char *password    = "password";
+
+static void kbd_callback(const char *name, int name_len,
+                         const char *instruction, int instruction_len,
+                         int num_prompts,
+                         const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
+                         LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
+                         void **abstract)
+{
+    (void)name;
+    (void)name_len;
+    (void)instruction;
+    (void)instruction_len;
+    if (num_prompts == 1) {
+       responses[0].text = strdup(password);
+       responses[0].length = strlen(password);
+    }
+    (void)prompts;
+    (void)abstract;
+} /* kbd_callback */
+
 static int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
 {
     struct timeval timeout;
@@ -77,7 +102,6 @@
     const char *hostname = "127.0.0.1";
     const char *commandline = "uptime";
     const char *username    = "user";
-    const char *password    = "password";
     unsigned long hostaddr;
     int sock;
     struct sockaddr_in sin;
@@ -90,6 +114,7 @@
     size_t len;
     LIBSSH2_KNOWNHOSTS *nh;
     int type;
+    int auth_methods = 0;
 
 #ifdef WIN32
     WSADATA wsadata;
@@ -188,13 +213,41 @@
     }
     libssh2_knownhost_free(nh);
 
+    char *userauthlist = NULL;
+    while (!userauthlist) {
+        userauthlist = libssh2_userauth_list(session, username, strlen(username));
+        if (libssh2_userauth_authenticated(session)) {
+            goto authenticated;
+        }
+    }
+    printf("Authentication methods: %s\n", userauthlist);
+    if (strstr(userauthlist, "password") != NULL) {
+        auth_methods |= AUTH_PASSWORD;
+    }
+    if (strstr(userauthlist, "keyboard-interactive") != NULL) {
+        auth_methods |= AUTH_KEYBOARD_INTERACTIVE;
+    }
+    if (strstr(userauthlist, "publickey") != NULL) {
+        auth_methods |= AUTH_PUBLICKEY;
+    }
+   
     if ( strlen(password) != 0 ) {
-        /* We could authenticate via password */
-        while ((rc = libssh2_userauth_password(session, username, password)) ==
-               LIBSSH2_ERROR_EAGAIN);
-        if (rc) {
-            fprintf(stderr, "Authentication by password failed.\n");
-            goto shutdown;
+        if ( auth_methods & AUTH_PASSWORD ) {
+            /* We could authenticate via password */
+            while ((rc = libssh2_userauth_password(session, username, password)) ==
+                   LIBSSH2_ERROR_EAGAIN);
+            if (rc) {
+                fprintf(stderr, "Authentication by password failed.\n");
+                goto shutdown;
+            }
+        }
+        else if ( auth_methods & AUTH_KEYBOARD_INTERACTIVE ) {
+           while ((rc = libssh2_userauth_keyboard_interactive(session, username, &kbd_callback)) ==
+                  LIBSSH2_ERROR_EAGAIN);
+           if (rc) {
+              fprintf(stderr, "Authentication by keyboard-interactive failed.\n");
+              goto shutdown;
+           }
         }
     }
     else {
@@ -212,6 +265,7 @@
         }
     }
 
+authenticated:
 #if 0
     libssh2_trace(session, ~0 );
 #endif
