Skip to content

Commit

Permalink
Consider additional default ssh keys for LibGit2. (JuliaLang#44767)
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarFarneback authored May 9, 2022
1 parent c62ea26 commit b6b0874
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions stdlib/LibGit2/src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Cvoid}}, p::CredentialPayload,
cred.user = unsafe_string(username_ptr)
end

cred.prvkey = Base.get(ENV, "SSH_KEY_PATH") do
default = joinpath(homedir(), ".ssh", "id_rsa")
if isempty(cred.prvkey) && isfile(default)
default
else
cred.prvkey
if haskey(ENV, "SSH_KEY_PATH")
cred.prvkey = ENV["SSH_KEY_PATH"]
elseif isempty(cred.prvkey)
for keytype in ("rsa", "ecdsa")
private_key_file = joinpath(homedir(), ".ssh", "id_$keytype")
if isfile(private_key_file)
cred.prvkey = private_key_file
break
end
end
end

Expand Down

0 comments on commit b6b0874

Please sign in to comment.