mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-26 21:51:05 +01:00
ssh-agent: use key signatures to check loaded ids (#7504)
Use fingerprint of ssh key instead of file name to control if the key is already loaded. Also check for .ssh folder presence (#5128)
This commit is contained in:
parent
fabee55948
commit
2a60385659
1 changed files with 18 additions and 6 deletions
|
@ -12,16 +12,28 @@ function _start_agent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _add_identities() {
|
function _add_identities() {
|
||||||
local id line
|
local id line sig
|
||||||
local -a identities ids
|
local -a identities loaded signatures
|
||||||
zstyle -a :omz:plugins:ssh-agent identities identities
|
zstyle -a :omz:plugins:ssh-agent identities identities
|
||||||
|
|
||||||
# get list of loaded identities
|
# check for .ssh folder presence
|
||||||
for line in ${(f)"$(ssh-add -l)"}; do ids+=${${(z)line}[3]}; done
|
if [[ ! -d $HOME/.ssh ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get list of loaded identities' signatures
|
||||||
|
for line in ${(f)"$(ssh-add -l)"}; do loaded+=${${(z)line}[2]}; done
|
||||||
|
|
||||||
|
# get signatures of private keys
|
||||||
|
for id in $identities; do
|
||||||
|
signatures+="$(ssh-keygen -lf "$HOME/.ssh/$id" | awk '{print $2}') $id"
|
||||||
|
done
|
||||||
|
|
||||||
# add identities if not already loaded
|
# add identities if not already loaded
|
||||||
for id in ${^identities}; do
|
for sig in $signatures; do
|
||||||
[[ ${ids[(I)$HOME/.ssh/$id]} -le 0 ]] && ssh-add $HOME/.ssh/$id
|
id="$(cut -f2 <<< $sig)"
|
||||||
|
sig="$(cut -f1 <<< $sig)"
|
||||||
|
[[ ${loaded[(I)$sig]} -le 0 ]] && ssh-add $HOME/.ssh/$id
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue