session FEATURE nc_ssh_init and destroy

API updated too.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 373653c..7cf56cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,7 +73,7 @@
 if(ENABLE_SSH)
 	find_package(LibSSH 0.6.4 REQUIRED)
 	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSH ${LIBSSH_DEFINITIONS}")
-	target_link_libraries(netconf2 ${LIBSSH_LIBRARIES})
+	target_link_libraries(netconf2 ${LIBSSH_LIBRARIES} -lssh_threads)
 	include_directories(${LIBSSH_INCLUDE_DIRS})
 endif()
 
diff --git a/src/session.h b/src/session.h
index 21f6169..6ef7d36 100644
--- a/src/session.h
+++ b/src/session.h
@@ -88,10 +88,31 @@
 #ifdef ENABLE_SSH
 
 /**
+ * @brief Initialize libssh so that libnetconf2 can safely use it in a multi-threaded environment.
+ *
+ * Must be called before using any other client SSH functions (nc_connect_ssh(), nc_connect_libssh,
+ * or nc_connect_ssh_channel())! If your application uses libssh and inititalizes it for multi-threaded use,
+ * do not call this function.
+ *
+ * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
+ */
+void nc_client_init_ssh(void);
+
+/**
+ * @brief Destroy any dynamically allocated SSH-specific context.
+ *
+ * If nc_client_init_ssh() was not called before, this function still must be called to clear
+ * any key pairs set using nc_set_keypair_path().
+ *
+ * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
+ */
+void nc_client_destroy_ssh(void);
+
+/**
  * @brief Connect to the NETCONF server using SSH transport (via libssh).
  *
- * SSH session is created with default options. If a caller need to change SSH session properties,
- * it is supposed to use nc_connect_libssh().
+ * SSH session is created with default options. If the caller needs to use specific SSH session properties,
+ * they are supposed to use nc_connect_libssh().
  *
  * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
  *
@@ -146,6 +167,32 @@
  */
 struct nc_session *nc_connect_ssh_channel(struct nc_session *session, struct ly_ctx *ctx);
 
+/**
+ * @brief Set (add) an SSH public and private key pair to be used for client authentization.
+ *
+ * Private key can be encrypted, the passphrase will be asked for before using it.
+ *
+ * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
+ *
+ * @param[in] pub_key Path to the public key.
+ * @param[in] priv_key Path to the private key.
+ *
+ * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise.
+ */
+int nc_set_keypair_path(const char *pub_key, const char *priv_key);
+
+/**
+ * @brief Remove an SSH public and private key pair that was used for client authentization.
+ *
+ * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
+ *
+ * @param[in] pub_key Path to the public key.
+ * @param[in] priv_key Path to the private key.
+ *
+ * @return EXIT_SUCCESS on success, EXIT_FAILURE otherwise.
+ */
+int nc_del_keypair_path(const char *pub_key, const char *priv_key);
+
 #endif /* ENABLE_SSH */
 
 #ifdef ENABLE_TLS
diff --git a/src/session_ssh.c b/src/session_ssh.c
index b2dd679..a9b874c 100644
--- a/src/session_ssh.c
+++ b/src/session_ssh.c
@@ -56,6 +56,28 @@
 int connect_getsocket(const char *host, unsigned short port);
 int handshake(struct nc_session *session);
 
+API void
+nc_client_init_ssh(void)
+{
+    ssh_threads_set_callbacks(ssh_threads_get_pthread());
+    ssh_init();
+}
+
+API void
+nc_client_destroy_ssh(void)
+{
+    int i;
+
+    for (i = 0; i < ssh_opts.key_count; ++i) {
+        free(ssh_opts.keys[i].pubkey_path);
+        free(ssh_opts.keys[i].privkey_path);
+    }
+
+    free(ssh_opts.keys);
+    ssh_opts.keys = NULL;
+    ssh_opts.key_count = 0;
+}
+
 static char *
 sshauth_password(const char *username, const char *hostname)
 {