summaryrefslogtreecommitdiff
path: root/setup-sshd.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2021-11-17 12:45:44 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2021-11-17 13:01:06 +0100
commit5886878d254a1120039683859e25fa62e97ed197 (patch)
tree1717fad4be3d389a9c3bc0f694d4207478c6d15e /setup-sshd.in
parent48b9626aab58741e31e55721c5b4f9fb5fd87500 (diff)
downloadalpine-conf-5886878d254a1120039683859e25fa62e97ed197.zip
setup-sshd: use SSH_KEY instead of prompt user
Do not ask user for ssh key, but support the use of SSH_KEY env var.
Diffstat (limited to 'setup-sshd.in')
-rw-r--r--setup-sshd.in20
1 files changed, 7 insertions, 13 deletions
diff --git a/setup-sshd.in b/setup-sshd.in
index caf8f1c..271ad79 100644
--- a/setup-sshd.in
+++ b/setup-sshd.in
@@ -18,6 +18,7 @@ usage() {
exit 1
}
+authorized_key="$SSH_KEY"
while getopts "hc:k:" opt; do
case $opt in
h) usage;;
@@ -53,21 +54,14 @@ if [ -n "$svc" ]; then
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
-
+ case "$authorized_key" in
+ http*://*|ftp://)
+ key_url="$authorized_key"
+ authorized_key="$(wget -qO- "$key_url")" || die "Could not fetch key from '$key_url'"
+ ;;
+ esac
mkdir -p ${ROOT}/root/.ssh
echo "$authorized_key" >> ${ROOT}/root/.ssh/authorized_keys
fi