From 7c8e77e3de9ecc36061fbfe05a81c0e1f952a1ca Mon Sep 17 00:00:00 2001 From: George Kitsos Date: Thu, 26 Sep 2024 15:17:37 +0300 Subject: [PATCH] fix: Check existence of ~/.ssh folder and create it (#5) Co-authored-by: George Kitsos --- .../bootstrap-agent-scripts/onm/onm-bootstrap.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh b/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh index b8babd9..791dbcb 100755 --- a/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh +++ b/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh @@ -206,6 +206,22 @@ if [ "$ACTION" == "CREATE" ]; then # Create OpenSSH Public/Private Key files ssh-keygen -C wireguard-pub -t rsa -b 4096 -f /home/${logged_in_user}/wireguard/wireguard -N "" + # Checking existence of ~/.ssh/authorized_keys + SSH_DIR_NAME="/home/${logged_in_user}/.ssh" + log_print INFO "onm-bootstrap($PID): Checking existence of ~/.ssh/authorized_keys" + if [ -d "$SSH_DIR_NAME" ]; then + log_print INFO "Directory $SSH_DIR_NAME already exists." + else + log_print INFO "Directory $SSH_DIR_NAME does not exist. Creating it now." + mkdir -p /home/${logged_in_user}/.ssh && chmod 700 /home/${logged_in_user}/.ssh + if [ $? -eq 0 ]; then + touch $SSH_DIR_NAME/authorized_keys && chmod 600 $SSH_DIR_NAME/authorized_keys + else + log_print WARN "Failed to create directory $SSH_DIR_NAME." + exit 1 + fi + fi + log_print INFO "onm-bootstrap($PID): Moving wireguard.pub file to authorized_keys file..." cat /home/${logged_in_user}/wireguard/wireguard.pub >> /home/${logged_in_user}/.ssh/authorized_keys