Skip to content

Commit

Permalink
Try ~/.ssh/id_rsa first by default
Browse files Browse the repository at this point in the history
Only prompt for a different private key. If authentication with the first key fails.
This can be a little annoying if one wants to use a different private key, but the
default one is encrypted, so it queries for a password, without asking for the key first.
However, in that case, one probably wants to use the environment variables or the ssh
agent anyway, so I'm not too concerned.
  • Loading branch information
Keno committed Jul 27, 2016
1 parent 994405a commit b9d8182
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,23 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
ENV["SSH_KEY_PATH"]
else
keydefpath = creds[:prvkey, credid] # check if credentials were already used
if keydefpath !== nothing && !isusedcreds
keydefpath == nothing && (keydefpath = "")
if !isempty(keydefpath) && !isusedcreds
keydefpath # use cached value
else
if keydefpath === nothing || isempty(keydefpath)
keydefpath = joinpath(homedir(),".ssh","id_rsa")
defaultkeydefpath = joinpath(homedir(),".ssh","id_rsa")
if isempty(keydefpath) && isfile(defaultkeydefpath)
keydefpath = defaultkeydefpath
else
keydefpath =
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
end

# If the private key changed, invalidate the cached public key
(privatekey != creds[:prvkey, credid]) &&
(creds[:pubkey, credid] = "")
creds[:prvkey, credid] = privatekey # save credentials

# For SSH we need a public key location, look for environment vars SSH_* as well
Expand Down

0 comments on commit b9d8182

Please sign in to comment.