---
name: "libssh2_session_handshake"
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_handshake"
---

# libssh2\_session\_handshake(3)

perform the SSH handshake

## NAME

libssh2\_session\_handshake - perform the SSH handshake

## SYNOPSIS

```
#include <libssh2.h>
int
libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t socket);
```

## DESCRIPTION

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

*socket* - Connected socket descriptor. Typically a TCP connection though the protocol allows for any reliable transport and the library will attempt to use any berkeley socket.

Begin transport layer protocol negotiation with the connected host.

## RETURN VALUE

Returns 0 on success, negative on failure.

## ERRORS

*LIBSSH2\_ERROR\_SOCKET\_NONE* - The socket is invalid.

*LIBSSH2\_ERROR\_BANNER\_SEND* - Unable to send banner to remote host.

*LIBSSH2\_ERROR\_KEX\_FAILURE* - Encryption key exchange with the remote host failed.

*LIBSSH2\_ERROR\_SOCKET\_SEND* - Unable to send data on socket.

*LIBSSH2\_ERROR\_SOCKET\_DISCONNECT* - The socket was disconnected.

*LIBSSH2\_ERROR\_PROTO* - An invalid SSH protocol response was received on the socket.

*LIBSSH2\_ERROR\_EAGAIN* - Marked for non-blocking I/O but the call would block.

## AVAILABILITY

Added in 1.2.8

## SEE ALSO

**[libssh2\_session\_free(3)](/libssh2_session_free/3.md)** **[libssh2\_session\_init\_ex(3)](/libssh2_session_init_ex/3.md)**
