CURLOPT_SSH_PRIVATE_KEYFILE(3)

πŸ’– CURLOPT_SSH_PRIVATE_KEYFILE πŸ’–

okay so bestie, this is a libcurl page from the Library Functions Manual, and it's about telling curl where your SSH private key lives. literally the whole vibe. ✨


🌸 NAME 🌸

CURLOPT_SSH_PRIVATE_KEYFILE β€” the private key file you use for SSH auth, no cap πŸ—οΈ


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_PRIVATE_KEYFILE,
                          char *filename);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass a char pointer that points to a filename β€” that's your private key, bestie. πŸ”‘

If you don't use this option, libcurl goes ahead and defaults to $HOME/.ssh/id_rsa or $HOME/.ssh/id_dsa if the HOME environment variable is set, and it looks in the current directory if HOME is not set. the way it just picks for you πŸ’…

If the file is password-protected, set that password with CURLOPT_KEYPASSWD(3). don't leave her hanging. 🫢

The SSH library derives the public key from this private key when it can. But listen β€” if the SSH library cannot derive the public key from the private one and no public one is provided with CURLOPT_SSH_PUBLIC_KEYFILE(3), the transfer fails. like, dead. πŸ’€ so give her what she needs.

Good news though: the application does not have to keep the string around after setting this option. set it and forget it, icon behavior ⭐


🧚 DEFAULT 🧚

As explained above ✨ (aka the $HOME/.ssh/id_rsa / $HOME/.ssh/id_dsa / current-directory situation)


🌈 PROTOCOLS 🌈

This functionality affects scp and sftp πŸš€


πŸ’œ EXAMPLE πŸ’œ

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_PRIVATE_KEYFILE,
                     "/home/clarkkent/.ssh/id_rsa");
    curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "password");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

⭐ AVAILABILITY ⭐

Added in curl 7.16.1 πŸ‘‘


πŸ”₯ 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 😭 β€” see libcurl-errors(3) for the full tea.


πŸ“ SEE ALSO πŸ“


okay that's the whole page, bestie, you ate πŸ’…βœ¨ this was libcurl, dated 2026-10-12, and the page is CURLOPT_SSH_PRIVATE_KEYFILE(3) β€” mwah, go forth and SSH πŸ¦‹πŸ’–

πŸ“¦ where this page comes from