CURLOPT_SSH_KEYDATA(3)

πŸ’… CURLOPT_SSH_KEYDATA(3) β€” your fave libcurl manual page, bestie

okay so this is the CURLOPT_SSH_KEYDATA(3) page from the libcurl manual (Library Functions Manual, no cap) and it's literally about smuggling your own pointer into an SSH key callback. short page, iconic energy, let's go 🫢


✨ NAME ✨

CURLOPT_SSH_KEYDATA β€” the pointer you yeet straight into the SSH key callback πŸŽ€


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_KEYDATA, void *pointer);

πŸ¦‹ DESCRIPTION πŸ¦‹

so you pass a void * as the parameter, right? that pointer gets handed along verbatim β€” like, untouched, no edits, no vibe check β€” to the callback you set with CURLOPT_SSH_KEYFUNCTION(3). that's it. that's the whole job. lowkey the easiest option in the whole library πŸ’œ


πŸŽ€ DEFAULT πŸŽ€

NULL

like, nothing. empty. no pointer, no problems πŸ™ˆ


🌈 PROTOCOLS 🌈

this functionality affects scp and sftp β€” so if you're not doing SSH file stuff, this option is not your main character ✨


πŸ”₯ EXAMPLE πŸ”₯

here's the whole thing, exactly as it is, because it ate and left no crumbs:

struct mine {
  void *custom;
};
static int keycb(CURL *easy,
                 const struct curl_khkey *knownkey,
                 const struct curl_khkey *foundkey,
                 enum curl_khmatch match,
                 void *clientp)
{
  /* 'clientp' points to the callback_data struct */
  /* investigate the situation and return the correct value */
  return CURLKHSTAT_FINE_ADD_TO_FILE;
}

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    struct mine callback_data;
    curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
    curl_easy_setopt(curl, CURLOPT_SSH_KEYFUNCTION, keycb);
    curl_easy_setopt(curl, CURLOPT_SSH_KEYDATA, &callback_data);
    curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "/home/user/known_hosts");

    curl_easy_perform(curl);
  }
}

see how &callback_data slides right through into clientp? that's the whole trick, bestie πŸ’…


⭐ AVAILABILITY ⭐

added in curl 7.19.6 β€” vintage but still slaying πŸ‘‘


πŸ’– RETURN VALUE πŸ’–

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK πŸŽ‰ β€” non-zero means an error occurred, so go check libcurl-errors(3) and figure out what went wrong, fr fr 😭


🧚 SEE ALSO 🧚


and that's the page!! this slay was brought to you by libcurl, dated 2026-10-12, filed under CURLOPT_SSH_KEYDATA(3) β€” mwah, go set some pointers bestie πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from