From de66c6049ecd54aca8a438d0d4443e4c3a33edd1 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 8 May 2023 21:53:19 +0200 Subject: [PATCH] Handle error when setting ssh key Avoid create a /.ssh dir if user does not exist. --- lib/tiny-cloud/init | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 8fd06ed..079d2d4 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -218,6 +218,10 @@ init__set_hostname() { init__set_ssh_keys() { local user="$CLOUD_USER" local pwent="$(getent passwd "$user")" + if [ -z "$pwent" ]; then + log err "Failed to find user $user" + return 1 + fi local group=$(echo "$pwent" | cut -d: -f4) local ssh_dir="${ROOT}$(echo "$pwent" | cut -d: -f6)/.ssh" local keys_file="$ssh_dir/authorized_keys"