libssh2_knownhost_addc(3)
π libssh2_knownhost_addc β bestie edition π
okay so you found the libssh2_knownhost_addc(3) page in the libssh2 manual and you're like "what is this" β don't worry bb, I got you. This is the function that adds a host to your known-hosts collection. Let's get into it π
β¨ NAME β¨
libssh2_knownhost_addc β add a known host π
πΈ SYNOPSIS πΈ
#include <libssh2.h>
int
libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
char *host, char *salt,
char *key, size_t keylen,
const char *comment, size_t commentlen,
int typemask,
struct libssh2_knownhost **store);
π¦ DESCRIPTION π¦
So basically this adds a known host to the collection of known hosts that's identified by the hosts handle. It's giving "let me introduce you to my friend" energy, but for SSH hosts π«Ά
host is a pointer to the host name β either in plain text or hashed. If it's hashed, it has to be handed over base64 encoded. And the host name can be the IP numerical address of the host or the full name. Either one, your call bestie β¨
Now, if you wanna add a key for a specific port number for a given host, you have to provide the host name like '[host]:port' β and yes, with the actual [ and ] characters enclosing the host name and a colon separating the host part from the port number. Example time:
[host.example.com]:222
salt is a pointer to the salt used for the host hashing β but only if the host is provided hashed. If the host is given in plain text, salt has no meaning at all, it's just vibing there. And heads up: the salt has to be provided base64 encoded with a trailing zero byte π
key is a pointer to the key for the given host.
keylen is the total size in bytes of the key pointed to by the key argument.
comment is a pointer to a comment for the key.
commentlen is the total size in bytes of the comment pointed to by the comment argument.
typemask is a bitmask that specifies format and info about the data passed to this function. Specifically, it details what format the host name is, what format the key is, and what key type it is. It's the main character of the arguments ngl π₯
The host name is given as one of the following types:
LIBSSH2_KNOWNHOST_TYPE_PLAINLIBSSH2_KNOWNHOST_TYPE_SHA1LIBSSH2_KNOWNHOST_TYPE_CUSTOM
The key is encoded using one of the following encodings:
LIBSSH2_KNOWNHOST_KEYENC_RAWLIBSSH2_KNOWNHOST_KEYENC_BASE64
The key is using one of these algorithms:
LIBSSH2_KNOWNHOST_KEY_RSA1LIBSSH2_KNOWNHOST_KEY_SSHRSALIBSSH2_KNOWNHOST_KEY_SSHDSSβ deprecated β οΈ like, it still exists but it's so last season, pls don't
π <red>deprecated</red> means it's still in the list but you should not be reaching for it, bestie. Not me warning you twice.
Finally, store should point to a pointer that gets filled in to point to the known host data after the addition. And if you literally do not care about that pointer? You can pass NULL. No pressure, no drama π
π RETURN VALUE π
Returns a regular libssh2 error code β where negative values are error codes and 0 indicates success. So like, 0 is the slay, negative is the "we need to talk" π
π AVAILABILITY π
Added in libssh2 1.2.5 β
π SEE ALSO π
and that's the whole page, periodt π
this was libssh2 1.2, dated 28 May 2009, and you just read the libssh2_knownhost_addc(3) manual β go add some known hosts bestie, you got this π«Άβ¨πΈ
π¦ 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