---
name: "libssh2_session_method_pref"
section: "3"
platform: "linux"
package: "libssh2"
version: "1.11.1-7"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libssh2_session_method_pref"
---

# libssh2\_session\_method\_pref(3)

set preferred key exchange method

## NAME

libssh2\_session\_method\_pref - set preferred key exchange method

## SYNOPSIS

```
#include <libssh2.h>
int
libssh2_session_method_pref(LIBSSH2_SESSION *session,
                            int method_type, const char *prefs);
```

## DESCRIPTION

*session* - Session instance as returned by **[libssh2\_session\_init\_ex(3)](/libssh2_session_init_ex/3.md)**

*method\_type* - One of the Method Type constants.

*prefs* - Coma delimited list of preferred methods to use with the most preferred listed first and the least preferred listed last. If a method is listed which is not supported by libssh2 it will be ignored and not sent to the remote host during protocol negotiation.

Set preferred methods to be negotiated. These preferences must be set prior to calling **[libssh2\_session\_handshake(3)](/libssh2_session_handshake/3.md)** as they are used during the protocol initiation phase.

## RETURN VALUE

Return 0 on success or negative on failure. It returns LIBSSH2\_ERROR\_EAGAIN when it would otherwise block. While LIBSSH2\_ERROR\_EAGAIN is a negative number, it is not really a failure per se.

## ERRORS

*LIBSSH2\_ERROR\_INVAL* - The requested method type was invalid.

*LIBSSH2\_ERROR\_ALLOC* - An internal memory allocation call failed.

*LIBSSH2\_ERROR\_METHOD\_NOT\_SUPPORTED* - The requested method is not supported.

## SEE ALSO

**[libssh2\_session\_init\_ex(3)](/libssh2_session_init_ex/3.md)** **[libssh2\_session\_handshake(3)](/libssh2_session_handshake/3.md)**
