mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 01:52:31 +01:00
Add ssh_fingerprint (and ssh_fp alias)
Also update README.md
This commit is contained in:
parent
6e7ac0544e
commit
5e966203ae
2 changed files with 39 additions and 0 deletions
|
|
@ -14,3 +14,10 @@ plugins=(... ssh)
|
||||||
- `ssh_rmhkey`: remove host key from known hosts based on a host section name from `.ssh/config`.
|
- `ssh_rmhkey`: remove host key from known hosts based on a host section name from `.ssh/config`.
|
||||||
- `ssh_load_key`: load SSH key into agent.
|
- `ssh_load_key`: load SSH key into agent.
|
||||||
- `ssh_unload_key`: remove SSH key from agent.
|
- `ssh_unload_key`: remove SSH key from agent.
|
||||||
|
- `ssh_fingerprint` : calculate fingerprint of specifed key files. It has some options:
|
||||||
|
- `-md5` : Use MD5 fingerprint instead of SHA256
|
||||||
|
- `-n` : Don't colorize using ANSI
|
||||||
|
- `-q` : Don't print filename(s)
|
||||||
|
- If key files are not specified, defaults to `~/.ssh/authorized_keys`
|
||||||
|
- `ssh_fp` is an alias to this function
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,3 +51,35 @@ function ssh_unload_key {
|
||||||
ssh-add -d "$keyfile"
|
ssh-add -d "$keyfile"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
# Calculate SSH key fingerprint
|
||||||
|
function ssh_fingerprint {
|
||||||
|
local fptype
|
||||||
|
local quiet
|
||||||
|
local ansi
|
||||||
|
|
||||||
|
zmodload zsh/zutil
|
||||||
|
zparseopts -D -- md5=fptype q=quiet n=ansi
|
||||||
|
fptype="${fptype[*]}"
|
||||||
|
if [[ -z $fptype ]]; then
|
||||||
|
fptype="sha256"
|
||||||
|
else
|
||||||
|
fptype="${fptype:1}"
|
||||||
|
fi
|
||||||
|
if [[ -z ${ansi[*]} ]]; then
|
||||||
|
ansi=("\e[1;30m" "\e[0m")
|
||||||
|
else
|
||||||
|
ansi=("" "")
|
||||||
|
fi
|
||||||
|
|
||||||
|
local keyfiles=( "$@" )
|
||||||
|
if [[ ${#keyfiles[@]} == 0 ]]; then keyfiles=( "$HOME/.ssh/authorized_keys" ); fi
|
||||||
|
local f
|
||||||
|
for f in "${keyfiles[@]}"; do
|
||||||
|
if [[ $quiet != "-q" ]]; then printf "${ansi[1]}$f:${ansi[2]}\n"; fi
|
||||||
|
ssh-keygen -l -E "$fptype" -f "$f"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
alias ssh_fp='ssh_fingerprint'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue