mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
Autoload ssh keys using keychain on macOS
This commit is contained in:
parent
dcbd4d2dbf
commit
762463af07
1 changed files with 22 additions and 0 deletions
22
shell/ssh
22
shell/ssh
|
|
@ -1,11 +1,33 @@
|
|||
# start ssh agent, if no agent set
|
||||
if [[ -n "${XDG_RUNTIME_DIR}" && -z "${SSH_AUTH_SOCK}" ]]; then
|
||||
# XDG should make this linux only
|
||||
# macOS starts its own agent, so, doubly so
|
||||
|
||||
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
|
||||
ssh-agent -t 24h > "${XDG_RUNTIME_DIR}/ssh-agent.env"
|
||||
fi
|
||||
|
||||
if [[ ! -S "${SSH_AUTH_SOCK}" ]] && [[ -f "${XDG_RUNTIME_DIR}/ssh-agent.env" ]]; then
|
||||
source "${XDG_RUNTIME_DIR}/ssh-agent.env" > /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# autoload keys if there's an agent
|
||||
if [[ -n "${SSH_AUTH_SOCK}" ]]; then
|
||||
if ! ssh-add -l > /dev/null; then
|
||||
case "${OSTYPE}"; in
|
||||
linux*)
|
||||
# TODO: unsure yet
|
||||
:
|
||||
;;
|
||||
darwin*)
|
||||
ssh-add -q --apple-load-keychain
|
||||
;;
|
||||
*)
|
||||
:
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
# vim: ft=bash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue