Files

31 lines
660 B
Bash
Executable File

#!/usr/bin/env bash
# Generate Ed25519 SSH keys for the given service names.
set -euo pipefail
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
awk '/^#!/ {next} /^[^#]/ {exit} {sub(/^# ?/, ""); print}' "$0"
exit 0
fi
if (( $# == 0 )); then
echo "[+] No services specified; nothing to do."
exit 0
fi
mkdir -p ~/.ssh
chmod 700 ~/.ssh
host_short="$(hostname -s)"
for service in "$@"; do
file="$HOME/.ssh/id_$service"
if [[ -f "$file" ]]; then
echo "[+] skipping: $file already exists"
continue
fi
echo "[+] generating: $file"
ssh-keygen -t ed25519 -f "$file" -N "" -C "$service@$host_short"
done