trust-ca-ssh/install.sh

38 lines
705 B
Bash
Raw Permalink Normal View History

#!/bin/bash
2020-11-20 22:47:50 +00:00
set -o errexit
set -o nounset
set -o pipefail
#
# Helper functions
#
declare -i term_width=120
2020-12-30 14:19:10 +00:00
host=${1}
key=${2}
2020-11-20 22:47:50 +00:00
h2() {
printf '\e[1;33m==>\e[37;1m %s\e[0m\n' "$*"
}
SSHD_CONFIG=/etc/ssh/sshd_config
CA_FILE=/etc/ssh/trusted-ca.pem
VAULT_CERT="https://${host}/v1/${key}/public_key"
echo $VAULT_CERT
if !(grep -q "TrustedUserCAKeys" $SSHD_CONFIG); then
2020-11-20 22:47:50 +00:00
h2 "Add new TrustedUserCAKeys"
curl -s -o $CA_FILE $VAULT_CERT
echo "TrustedUserCAKeys ${CA_FILE}" | tee -a $SSHD_CONFIG
else
CA_FILE=$(grep "TrustedUserCAKeys" $SSHD_CONFIG|cut -d' ' -f2)
2020-11-20 22:47:50 +00:00
h2 "Attach trusted CA to ${CA_FILE}"
curl -s $VAULT_CERT >> $CA_FILE
fi
2020-11-20 22:47:50 +00:00
h2 "Restart sshd service"
systemctl restart sshd
h2 "Done."