diff options
author | Lukas Bestle <mail@lukasbestle.com> | 2021-07-10 21:36:26 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2021-11-17 12:00:39 +0000 |
commit | 48b9626aab58741e31e55721c5b4f9fb5fd87500 (patch) | |
tree | 8275619aa160b59d6b6170f03300aef918777d1c /setup-sshd.in | |
parent | c43b38051149f0685fcb22e253de8bba432872e0 (diff) | |
download | alpine-conf-48b9626aab58741e31e55721c5b4f9fb5fd87500.zip |
setup-sshd: Ask for authorized key for root
Fixes #10459.
Diffstat (limited to 'setup-sshd.in')
-rw-r--r-- | setup-sshd.in | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/setup-sshd.in b/setup-sshd.in index 67cb8a0..caf8f1c 100644 --- a/setup-sshd.in +++ b/setup-sshd.in @@ -6,21 +6,23 @@ PREFIX= usage() { cat <<-__EOF__ - usage: setup-sshd [-h] [-c choice of SSH daemon] + usage: setup-sshd [-h] [-c choice of SSH daemon] [-k authorized key] Setup sshd daemon options: -h Show this help -c Choice of SSH daemon: openssh dropbear none + -k Authorized key for root (HTTP(S)/FTP URL, the public key itself or 'none') __EOF__ exit 1 } -while getopts "hc:" opt; do +while getopts "hc:k:" opt; do case $opt in h) usage;; c) sshdchoice="$OPTARG";; + k) authorized_key="$OPTARG";; esac done @@ -50,3 +52,22 @@ if [ -n "$svc" ]; then rc-update add $svc default rc-service $svc start fi + +if [ -z "$authorized_key" ]; then + ask "Authorized SSH public key for root? (HTTP(S)/FTP URL or the public key itself)" none + authorized_key="$resp" +fi + +if [ -n "$authorized_key" -a "$authorized_key" != "none" ]; then + # if the argument is an HTTP(S)/FTP URL, try to fetch the file contents + if [ -z "$(echo "$authorized_key" | sed -E 's~^(https?|ftp)://.+$~~')" ]; then + key_url="$authorized_key" + authorized_key="$(wget -qO- "$key_url")" || die "Could not fetch key from '$key_url'" + + echo "Received authorized SSH key from '$key_url':" + echo "$authorized_key" + fi + + mkdir -p ${ROOT}/root/.ssh + echo "$authorized_key" >> ${ROOT}/root/.ssh/authorized_keys +fi |