mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-27 15:30:15 +08:00
ssh-agent: check for loaded id filenames first (#7521)
This change makes the plugin check if an identity is loaded by looking first at the key filename reported by `ssh-add -l`. This fixes the use case where ssh-keygen is not able to output the fingerprint of a key, such as the one reported on #7516. Now, for an identity to be passed onto ssh-add, it has to fail the match for a loaded identity, both filename and signature.
This commit is contained in:
parent
b9670d0409
commit
c494869632
@ -13,7 +13,7 @@ function _start_agent() {
|
|||||||
|
|
||||||
function _add_identities() {
|
function _add_identities() {
|
||||||
local id line sig
|
local id line sig
|
||||||
local -a identities loaded not_loaded signatures
|
local -a identities loaded_sigs loaded_ids not_loaded
|
||||||
zstyle -a :omz:plugins:ssh-agent identities identities
|
zstyle -a :omz:plugins:ssh-agent identities identities
|
||||||
|
|
||||||
# check for .ssh folder presence
|
# check for .ssh folder presence
|
||||||
@ -31,19 +31,19 @@ function _add_identities() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get list of loaded identities' signatures
|
# get list of loaded identities' signatures and filenames
|
||||||
for line in ${(f)"$(ssh-add -l)"}; do loaded+=${${(z)line}[2]}; done
|
for line in ${(f)"$(ssh-add -l)"}; do
|
||||||
|
loaded_sigs+=${${(z)line}[2]}
|
||||||
# get signatures of private keys
|
loaded_ids+=${${(z)line}[3]}
|
||||||
for id in $identities; do
|
|
||||||
signatures+="$(ssh-keygen -lf "$HOME/.ssh/$id" | awk '{print $2}') $id"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# add identities if not already loaded
|
# add identities if not already loaded
|
||||||
for sig in $signatures; do
|
for id in $identities; do
|
||||||
id="$(cut -f2 <<< $sig)"
|
# check for filename match, otherwise try for signature match
|
||||||
sig="$(cut -f1 <<< $sig)"
|
if [[ ${loaded_ids[(I)$HOME/.ssh/$id]} -le 0 ]]; then
|
||||||
[[ ${loaded[(I)$sig]} -le 0 ]] && not_loaded+="$HOME/.ssh/$id"
|
sig="$(ssh-keygen -lf "$HOME/.ssh/$id" | awk '{print $2}')"
|
||||||
|
[[ ${loaded_sigs[(I)$sig]} -le 0 ]] && not_loaded+="$HOME/.ssh/$id"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ -n "$not_loaded" ]] && ssh-add ${^not_loaded}
|
[[ -n "$not_loaded" ]] && ssh-add ${^not_loaded}
|
||||||
|
Loading…
Reference in New Issue
Block a user