Skip to content

libssh: default id_rsa probe (since 8.22.0) stops publickey auth at the first key; the agent and other methods are never tried #23518

Closed

Description

@saiharsha1994

Since commit c7f67be ("vssh: keyfile use cleanups", 8.22.0, issue #22243) the shared helper
Curl_ssh_setup_pkey() in lib/vssh/vssh.c sets the private key to $HOME/.ssh/id_rsa (then id_dsa) when the file exists and the user named no key. Both SSH backends now run this probe. They differ in what they do when that key does not authenticate.

  • libssh2 (lib/vssh/libssh2.c): after the key fails it continues to the agent, then keyboard-interactive, then
    login denied.
  • libssh (lib/vssh/libssh.c): after the key fails myssh_in_AUTH_PKEY() goes to GSSAPI, then
    keyboard-interactive, then password, then login denied. There is no agent step. The agent and the default keys are only reached through ssh_userauth_publickey_auto() in the else branch of myssh_in_AUTH_PKEY_INIT(), and the probe skips that branch whenever id_rsa exists. If the probed key cannot be loaded at all, myssh_in_AUTH_PKEY_INIT() returns login denied with no fallback.

So on the libssh backend the probed key is not a default, it is the only key tried. Two setups that ssh logs
into, and that curl 8.21.0 logged into, now fail.

Setup A, an unauthorized id_rsa next to the authorized key:

ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa            # not in authorized_keys
ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519    # authorized
curl sftp://user@host/etc/hostname
# 8.21.0: file content, exit 0
# 8.22.0 and later: curl: (67) Login denied

Setup B, a passphrase-protected id_rsa held in ssh-agent, nothing else in ~/.ssh:

ssh-keygen -t rsa -N 'secret' -f ~/.ssh/id_rsa
eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa
curl sftp://user@host/etc/hostname
# 8.21.0: file content, exit 0
# 8.22.0 and later: curl: (67) Could not load private key file /home/user/.ssh/id_rsa

--key ~/.ssh/id_ed25519 works around A. Nothing on the command line works around B short of passing the
passphrase, which defeats the agent.

I am not asking to remove the id_rsa default. Issue #22243 kept it so libssh2 users keep working, and that still
holds. The gap is that the probe assumes a fallback the libssh backend does not have. Two ways to close it:

  1. Finish the parity: on the libssh backend, after the probed key fails, continue to the agent and the remaining
    methods (fall into the ssh_userauth_publickey_auto() path), the way libssh2 continues to the agent. The
    default then behaves the same on both backends in the failure case.
  2. On the libssh backend, use the probed key only when the user set CURLOPT_SSH_PRIVATE_KEYFILE, and let ssh_userauth_publickey_auto() do the default search as before 8.22.0.

Option 1 matches the goal of #22243. I can send either as a PR.

I expected the following

With no key named, a wrong or unloadable ~/.ssh/id_rsa costs one failed attempt, then curl tries the agent and the other methods the server offers, the way the libssh2 backend does. Both setups above authenticate.

curl/libcurl version

curl 8.23.0 (x86_64-pc-linux-gnu) libcurl/8.23.0

operating system

Linux x86_64, also reproduced on aarch64.

Activity

  1. icing commented on Oct 22, 2026

    @icing
    Contributor

    Care to work on a fix for this?

  2. saiharsha1994 commented on Oct 23, 2026

    @saiharsha1994
    Author

    Done. #23582

  3. added a commit that references this issue on Oct 26, 2026
    296e403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions