Skip to content

Commit

Permalink
fix: prefer specified identities instead of the ssh agent (#61)
Browse files Browse the repository at this point in the history
* fix: prefer specified identities instead of the ssh agent

if an identity file is provided, prefer it over the ssh agent.

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: handle err properly

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 authored Apr 26, 2022
1 parent 4d19fe3 commit 8a63c15
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions client_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ func remoteBestAuthMethod(s ssh.Session) (gossh.AuthMethod, agent.Agent, closers
// It'll return a nil list if none of the methods is available.
func localBestAuthMethod(agt agent.Agent, e *Endpoint) ([]gossh.AuthMethod, error) {
var methods []gossh.AuthMethod
if len(e.IdentityFiles) > 0 {
ids, err := tryIdendityFiles(e)
if err != nil {
return methods, err
}
methods = append(methods, ids...)
}

if method := agentAuthMethod(agt); method != nil {
methods = append(methods, method)
}

if len(e.IdentityFiles) > 0 {
ids, err := tryIdendityFiles(e)
return append(methods, ids...), err
if len(methods) > 0 {
return methods, nil
}

keys, err := tryUserKeys()
return append(methods, keys...), err
}
Expand Down

0 comments on commit 8a63c15

Please sign in to comment.