libssh2_knownhost_addc(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_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_PLAIN
  • LIBSSH2_KNOWNHOST_TYPE_SHA1
  • LIBSSH2_KNOWNHOST_TYPE_CUSTOM

The key is encoded using one of the following encodings:

  • LIBSSH2_KNOWNHOST_KEYENC_RAW
  • LIBSSH2_KNOWNHOST_KEYENC_BASE64

The key is using one of these algorithms:

  • LIBSSH2_KNOWNHOST_KEY_RSA1
  • LIBSSH2_KNOWNHOST_KEY_SSHRSA
  • LIBSSH2_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 🫢✨🌸