libssh2_userau...ckey_frommemory(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 by libssh2_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 of username. 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 πŸ’–βœ¨πŸŽ€