CURLOPT_SS...IC_KEYFILE(3)
π CURLOPT_SS...IC_KEYFILE(3) π
okay so this is from the libcurl Library Functions Manual bestie, and it's literally all about CURLOPT_SSH_PUBLIC_KEYFILE β the public key file you hand over for SSH auth. no cap, it's a short one but it's important, so let's get into it β¨
β¨ NAME β¨
CURLOPT_SSH_PUBLIC_KEYFILE β public key file for SSH auth π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_PUBLIC_KEYFILE,
char *filename);
π¦ DESCRIPTION π¦
okay so you pass a char pointer pointing to a filename for your public key. that's it, that's the whole vibe π
but here's the part where you gotta pay attention, bestie β if you don't use this option, libcurl has a default and it's lowkey specific:
- if the
HOMEenvironment variable is set, libcurl defaults to$HOME/.ssh/id_dsa.pubπ - if
HOMEis not set, it just uses"id_dsa.pub"in the current directory π
the way that's such a specific little fallback chain, iykyk π
now for the spicy part πΆοΈ β if NULL (or an empty string "") is passed to this option, libcurl passes no public key to the SSH library, which then rather derives it from the private key. but careful: if the SSH library cannot derive the public key from the private one and no public one is provided, the transfer fails. π like, straight up fails. no public key, no derived key, no transfer. periodt.
the good news tho β the application does not have to keep the string around after setting this option π«Ά you can let it go, it's fine.
π DEFAULT π
NULL π
π PROTOCOLS π
this functionality affects scp and sftp β¨ (those two only, bestie β don't try it anywhere else)
π§ EXAMPLE π§
here's the whole thing in action, iconic main character energy:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/file");
curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE,
"/home/clarkkent/.ssh/id_rsa.pub");
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
look at clark kent over here with his id_rsa.pub π
slay.
β HISTORY β
the "" trick was added in 7.26.0 π
π AVAILABILITY π
added in curl 7.16.1 β so it's been around a minute, fr fr π¦
π 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 β go check
libcurl-errors(3)bestie π
πΈ SEE ALSO πΈ
and that's the whole page, bestie! π«Ά this lil gem came to you from the libcurl manual, dated 2026-10-12 β go forth and ssh responsibly π πβ¨
π¦ 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