libssh2_userau...ey_fromfile_ex(3)
π libssh2_userau...ey_fromfile_ex(3) π
okay bestie, gather round, because this one lives in the libssh2 manual and it's literally the glow-up you need when you want to log into a session with a key that's just... sitting in a file. no cap.
β¨ NAME β¨
libssh2_userauth_publickey_fromfile_ex β authenticate a session with a public key, read from a file ποΈ
πΈ SYNOPSIS πΈ
#include <libssh2.h>
int
libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
const char *username,
unsigned int username_len,
const char *publickey,
const char *privatekey,
const char *passphrase);
π¦ DESCRIPTION π¦
so here's the whole vibe, arg by arg, because every single one matters:
sessionβ the session instance you got back fromlibssh2_session_init_ex(3). your main character, basically.usernameβ pointer to the user name you're authenticating as. who are we being today? πusername_lenβ the length ofusername. yes, it needs its own number. the way that C works πpublickeyβ path name of the public key file (like, for example,/etc/ssh/hostkey.pub). π fun fact: if libssh2 is built against OpenSSL, this one can be set toNULL.privatekeyβ path name of the private key file (e.g./etc/ssh/hostkey). keep this one safe, fr fr πpassphraseβ the passphrase used when decodingprivatekey. the secret to the secret β¨
and what does it actually do? it attempts public key authentication using either a public key file or a PEM encoded private key file stored on disk. when you hand it a private key, the public key gets automatically extracted from it β self-sufficient queen π . when you pass both, the public key you passed takes precedence. periodt.
π₯ RETURN VALUE π₯
- returns
0on success, or a negative number on failure. - it returns
LIBSSH2_ERROR_EAGAINwhen it would otherwise block. - and listen: even though
LIBSSH2_ERROR_EAGAINis a negative number, it is not really a failure per se. it's giving "hold on, brb" not "we're done here" π
π ERRORS π
LIBSSH2_ERROR_FILEβ an issue opening, reading or parsing the disk file.LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed.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. π
lowkey the LIBSSH2_ERROR_SOCKET_TIMEOUT one has no description in the original and honestly? same energy. it says what it says. π
π SEE ALSO π
and that's the whole page, bestie π«Ά
<cute>this lil doc came from libssh2 0.15, dated 1 Jun 2007 β vintage, iconic, still slaying β</cute>
π¦ 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