broke out install_cert_config

This commit is contained in:
John Lancaster
2026-01-04 09:23:24 -06:00
parent b094a3464c
commit 341648ad80

View File

@@ -1,5 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
GREEN_CHECK="\e[32m✔\e[0m"
RED_X="\e[31m✗\e[0m"
#
# Function Definition
#
ssh_config_val() { ssh_config_val() {
local field="$1" local field="$1"
local val local val
@@ -12,6 +19,10 @@ ssh_config_val() {
echo $(sshd -T | grep -i "^$field " | head -1 | awk '{print $2}') echo $(sshd -T | grep -i "^$field " | head -1 | awk '{print $2}')
} }
green_checkmark() {
printf "\e[32m✔\e[0m"
}
check_ssh_files() { check_ssh_files() {
printf "%-6s %-20s %-6s %s\n" "STATUS" "KEY" "PERMS" "PATH" printf "%-6s %-20s %-6s %s\n" "STATUS" "KEY" "PERMS" "PATH"
for key in hostkey hostcertificate trustedusercakeys; do for key in hostkey hostcertificate trustedusercakeys; do
@@ -23,9 +34,9 @@ check_ssh_files() {
if [[ -e "$path" ]]; then if [[ -e "$path" ]]; then
perms=$(stat -c '%a' "$path") perms=$(stat -c '%a' "$path")
printf "%-7s %-20s %-6s %s\n" "" "$key" "$perms" "$path" printf "%-17b %-20s %-6s %s\n" " $GREEN_CHECK" "$key" "$perms" "$path"
else else
printf "%-7s %-20s %-6s %s\n" "" "$key" "-" "$path (missing)" printf "%-17b %-20s %-6s %s\n" " $RED_X" "$key" "-" "$path (missing)"
fi fi
done done
} }
@@ -54,17 +65,30 @@ ssh_fingerprint() {
ssh-keygen -lf "$cfg_path" | awk '{ print $2 }' ssh-keygen -lf "$cfg_path" | awk '{ print $2 }'
} }
install_cert_config() {
local base_dir="/etc/ssh/sshd_config.d"
local cfg_path="${1:-$base_dir/certs.conf}"
mkdir -p $(dirname $cfg_path)
cat <<EOF > $cfg_path
TrustedUserCAKeys /etc/ssh/ssh_user_ca.pub
HostKey /etc/ssh/ssh_host_ed25519_key
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
EOF
}
#
# Run Process
#
if [[ ! -e "/etc/ssh/sshd_config.d/certs.conf" ]]; then if [[ ! -e "/etc/ssh/sshd_config.d/certs.conf" ]]; then
echo "⚠️ sshd not configured to use SSH certs" echo "⚠️ sshd not configured to use SSH certs"
read -p "Do you want to configure sshd? (y/n) " -n 1 -r read -p "Do you want to configure sshd? (y/n) " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
mkdir -p /etc/ssh/sshd_config.d install_cert_config
cat <<EOF > /etc/ssh/sshd_config.d/certs.conf
TrustedUserCAKeys /etc/ssh/ssh_user_ca.pub
HostKey /etc/ssh/ssh_host_ed25519_key
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
EOF
echo -n "Restarting sshd... " echo -n "Restarting sshd... "
systemctl restart sshd systemctl restart sshd
echo "done" echo "done"