Skip to content

Commit

Permalink
Install private SSH and GPG key from 1Password
Browse files Browse the repository at this point in the history
  • Loading branch information
pkissling committed Oct 26, 2023
1 parent 844364a commit 6611f0b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ git: bootstrap
@chmod +x git/install.sh
@./git/install.sh

gpg: bootstrap
gpg: bootstrap brew
@chmod +x gpg/install.sh
@./gpg/install.sh

Expand Down
11 changes: 11 additions & 0 deletions gpg/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ ln -sfv "${HOME}"/dotfiles/gpg/gpg-agent_"${USAGE}".conf "${HOME}"/.gnupg/gpg-ag
# import public gpg keys
gpg --import ~/dotfiles/gpg/private.asc
gpg --import ~/dotfiles/gpg/work.asc

# add private gpg key from 1password, if not exist
if [ -z "$(gpg --list-secret-keys)" ]; then
if [ "${USAGE}" = "work" ]; then
ONE_PASSWORD_VAULT="Azena"
else
ONE_PASSWORD_VAULT="Personal"
fi
ONE_PASSWORD_DOCUMENT_ID=$(op item get 'GPG Private Key' --vault "${ONE_PASSWORD_VAULT}" --format json | jq -r .id)
gpg --import <(op document get "${ONE_PASSWORD_DOCUMENT_ID}")
fi
14 changes: 14 additions & 0 deletions ssh/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ ln -sfv "${HOME}"/.ssh/"${USAGE}".priv "${HOME}"/.ssh/id_rsa

# create symlinks for config file
ln -sfv "${HOME}"/dotfiles/ssh/config "${HOME}"/.ssh

# add private ssh key from 1password, if not exist
# shellcheck disable=SC2140
if [ ! -f "${HOME}"/.ssh/"${USAGE}.priv" ]; then
if [ "${USAGE}" = "work" ]; then
ONE_PASSWORD_VAULT="Azena"
else
ONE_PASSWORD_VAULT="Personal"
fi
ONE_PASSWORD_DOCUMENT_ID=$(op item get 'SSH Private Key' --vault "${ONE_PASSWORD_VAULT}" --format json | jq -r .id)
# shellcheck disable=SC2140
op read op://"${ONE_PASSWORD_VAULT}"/"${ONE_PASSWORD_DOCUMENT_ID}"/'private key' > "${HOME}"/.ssh/"${USAGE}.priv"
chmod 600 "${HOME}"/.ssh/"${USAGE}.priv"
fi

0 comments on commit 6611f0b

Please sign in to comment.