Skip to content

key file is not used if other keys exist in ssh agent #237

@xinfengliu

Description

@xinfengliu

While debugging a k0sctl issue, I found my specified keyPath for ssh is not used and ssh connection failed.

spec:
  hosts:
  - ssh:
      address: rocky9-0
      keyPath: /home/docker/.ssh/id_ed25519
      port: 22
      user: root
...

To work around the issue, I had to manually add the key to ssh agent or unset SSH_AUTH_SOCK or clearing keys in ssh agent.

I reviewed k0sproject/rig codes and found the reason is that I have already had other ssh keys in SSH agent, and the specified ssh key file is configured as another ssh.AuthMethod in https://github.com/k0sproject/rig/blob/v0.19.0/ssh.go#L434 , so ssh.ClientConfig.Auth has two AuthMethod, both method() is publickey , golang.org/x/crypto/ssh client_auth.go only tries the first one for the same auth method (https://cs.opensource.google/go/x/crypto/+/refs/tags/v0.29.0:ssh/client_auth.go;l=101), so the specified ssh key file is never used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions