libssh2_userau...ckey_frommemory(3)
β¨ libssh2_userauth_publickey_frommemory β bestie edition β¨
okay so this one lives in the libssh2 manual, and it's literally about logging into a session with a public key that you're holding in memory. no files on disk, no drama, just vibes and buffers π
πΈ NAME πΈ
libssh2_userauth_publickey_frommemory β authenticate a session with a public key, read from memory
π SYNOPSIS π
#include <libssh2.h>
int
libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
const char *username,
size_t username_len,
const char *publickeydata,
size_t publickeydata_len,
const char *privatekeydata,
size_t privatekeydata_len,
const char *passphrase);
π DESCRIPTION π
so here's the tea, the whole squad of arguments, one by one:
sessionβ Session instance as returned bylibssh2_session_init_ex(3). this is your main character, the session you're doing all of this for π«Άusernameβ Remote user name to authenticate as. who you're being on the other side β¨username_lenβ Length ofusername. yes bestie, you have to tell it how long the name is, we don't guess here πpublickeydataβ Buffer containing the contents of a public key file. the public key, just chilling in memory πpublickeydata_lenβ Length of public key data.privatekeydataβ Buffer containing the contents of a private key file. the secret one, keep it safe πprivatekeydata_lenβ Length of private key data.passphraseβ Passphrase to use when decoding private key file. iykyk π
and the actual plot: this function attempts public key authentication using either a public key file or a PEM encoded private key file that's stored in memory. no disk, no touching grass.
- when you provide a private key, the public key is automatically extracted from it. the function does the work for you, iconic behavior fr fr π
- when you provide both, the passed public key takes precedence. so the public key you hand over is the one that wins, no cap.
π₯ RETURN VALUE π₯
Return 0 on success or negative on failure. it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. and listen β while LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se. it's just the vibe check saying "try again later" π so don't panic.
π ERRORS π
LIBSSH2_ERROR_ALLOCβ An internal memory allocation call failed. the memory said no πLIBSSH2_ERROR_SOCKET_SENDβ Unable to send data on socket.LIBSSH2_ERROR_SOCKET_TIMEOUTβLIBSSH2_ERROR_PUBLICKEY_UNVERIFIEDβ The username/public key combination was invalid.LIBSSH2_ERROR_AUTHENTICATION_FAILEDβ Authentication using the supplied public key was not accepted.
ok so quick heads up: LIBSSH2_ERROR_SOCKET_TIMEOUT shows up with no description in the original, so i'm not gonna invent one for you. it's giving mystery β¨
π AVAILABILITY π
libssh2_userauth_publickey_frommemory was added in libssh2 1.6.0.
Supported with OpenSSL, WinCNG, mbedTLS, OS/400 crypto backends. so like, a whole friend group of crypto backends, we love to see it π¦
π SEE ALSO π
and that's the whole page bestie, go forth and authenticate π§
this little love letter came to you from the libssh2 manual, dated 1 Sep 201 (yes, that's exactly how it's written, i don't make the rules π). mwah, go slay πβ¨π
π¦ where this page comes from
- alpine 3.22: libssh2-doc 1.11.1-r3 Β· BSD-3-Clause
- alpine 3.23: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- alpine 3.24: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- arch rolling: libssh2 1.11.1-7 Β· BSD-3-Clause
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u1 Β· BSD3
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u2 Β· BSD3
- epel 10: libssh2-docs 1.11.1-9.el10_3 Β· BSD-3-Clause
- epel 9: libssh2-docs 1.11.1-9.el9 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-4.fc43 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-9.fc43 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-5.fc44 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-9.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- ubuntu questing: libssh2-1-dev 1.11.1-1build1
- ubuntu questing: libssh2-1-dev 1.11.1-1ubuntu0.25.10.2
- ubuntu resolute: libssh2-1-dev 1.11.1-1build2 Β· BSD3
- ubuntu resolute: libssh2-1-dev 1.11.1-1ubuntu0.26.04.4 Β· BSD3
- ubuntu stonking: libssh2-1-dev 1.11.1-6 Β· BSD3
- π the page's license: BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms