Skip to content

Instantly share code, notes, and snippets.

@tayopal
Created December 21, 2023 20:57
Show Gist options
  • Save tayopal/1c6aea5412d7397131634dc48e406bdf to your computer and use it in GitHub Desktop.
Save tayopal/1c6aea5412d7397131634dc48e406bdf to your computer and use it in GitHub Desktop.
Check signed SSH cert for expiration
# .zhsrc
function signed {
expiry=$(ssh-keygen -L -f ~/.ssh/id_rsa-cert.pub | grep Valid | awk '{ print $5 }')
expiry_epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S" "${expiry}" "+%s")
current_epoch=$(date "+%s")
if [ $current_epoch -gt $expiry_epoch ]; then
echo $fg[red] "SSH -"
return -1
else
(( seconds_left = $expiry_epoch - $current_epoch ))
(( hours = seconds_left / 60 / 60 ))
(( minutes = seconds_left / 60 % 60 ))
(( seconds = seconds_left % 60 ))
echo $fg[green] "SSH + $hours:${(l(2)(0))minutes}:${(l(2)(0))seconds} remaining"
return 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment