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 HOME environment variable is set, libcurl defaults to $HOME/.ssh/id_dsa.pub 🏠
  • if HOME is 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