Directly use ssh-agent instead of keychain

This commit is contained in:
Jeremy Gardais 2021-09-19 17:58:44 +02:00
parent 5086ba686d
commit 71038b0a65
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
3 changed files with 27 additions and 24 deletions

17
zlogin
View File

@ -77,23 +77,16 @@ if [ ${USER} != "root" ] && [ $(command -v startx) ]; then
fi fi
fi fi
# Keychain {{{ # ssh-agent with fix socket path {{{
## TODO: user must be able to see ssh-agent process ## See load-ssh-agent function in ~/.zsh/zshrc
## Be careful with hidepid! load-ssh-agent
if [ -f $HOME/.ssh/id_rsa ]; then
eval $(keychain --eval --quiet --agents ssh id_rsa)
fi
if [ -f $HOME/.ssh/id_ed25519 ]; then
eval $(keychain --eval --quiet --agents ssh id_ed25519)
fi
# }}} # }}}
# GPG Agent # GPG Agent {{{
if [ -f $HOME/.gnupg/secring.gpg ]; then if [ -f $HOME/.gnupg/secring.gpg ]; then
# Keychain # Keychain
## Don't ask for gpg password, it will be asked at the first usage ## Don't ask for gpg password, it will be asked at the first usage
keychain --noask --agents gpg keychain --noask --agents gpg
. $HOME/.keychain/$HOST-sh-gpg . $HOME/.keychain/$HOST-sh-gpg
fi fi
# }}}

5
zshenv
View File

@ -100,3 +100,8 @@ if [ $(command -v tmux) ]; then
export TMUX_TMPDIR=~/.tmux/socks/ export TMUX_TMPDIR=~/.tmux/socks/
[ ! -d "${TMUX_TMPDIR}" ] && mkdir -p -- "${TMUX_TMPDIR}" || chmod 0700 -- "${TMUX_TMPDIR}" [ ! -d "${TMUX_TMPDIR}" ] && mkdir -p -- "${TMUX_TMPDIR}" || chmod 0700 -- "${TMUX_TMPDIR}"
fi fi
# SSH
## Specify ssh-agent socket path
SSH_AGENT_SOCK="${HOME}/.ssh/socks/ssh_auth"
SSH_AGENT_ENV="${HOME}/.ssh/socks/ssh_agent_env"

29
zshrc
View File

@ -314,20 +314,25 @@ alias ping6="ping6 -c 3"
## JOSM ## JOSM
alias josm="java -jar -Xmx2048M /opt/josm-tested.jar" alias josm="java -jar -Xmx2048M /opt/josm-tested.jar"
# Keychain # Function to load ssh-agent with a fix socket path {{{
## For SSH {{{ ## This function can be used :
function ssh() { ## 1. in zlogin (for a new shell)
## If keychain exists, run ssh from default $PATH as usual function load-ssh-agent() {
if [ -f ~/.keychain/"${HOST}"-sh ]; then ## If a ssh-key is available
command -p ssh "${*}" ## AND ssh-agent not launched
else ## Otherwise, reload keychain and run ssh if find "${HOME}/.ssh" -maxdepth 1 -type f -iname "id_*" > /dev/null 2>&1 &&
keychain --agents ssh ! ps -x | grep -v grep | grep -Fq -- "ssh-agent -a ${SSH_AGENT_SOCK}"; then
source ~/.keychain/"${HOST}"-sh ### Remove any previous socket and environment files
command -p ssh "${*}" rm --force -- "${SSH_AGENT_SOCK}" "${SSH_AGENT_ENV}"
### Start ssh-agent with a specified socket path
### AND store informations in a file
ssh-agent -a "${SSH_AGENT_SOCK}" > "${SSH_AGENT_ENV}"
fi fi
## Load content of ssh-agent environment file
source "${SSH_AGENT_ENV}"
} }
## }}} # }}}
## For GPG {{{ ## Keychain for GPG {{{
function gpg() { function gpg() {
## If keychain exists, run gpg from default $PATH as usual ## If keychain exists, run gpg from default $PATH as usual
if [ -f ~/.keychain/"${HOST}"-sh-gpg ]; then if [ -f ~/.keychain/"${HOST}"-sh-gpg ]; then