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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms