diff --git a/setup.sh b/setup.sh index cfa0c2e..b43573c 100644 --- a/setup.sh +++ b/setup.sh @@ -84,7 +84,7 @@ fi gauge_run "Applying system updates…" apt-get -y dist-upgrade ############################################################################### -# Hostname # +# Hostname # ############################################################################### MACS=$(ip -brief link | awk '$1!~"lo"{print $1": "$3}') NEW_HOST=$(whiptail --title "Hostname" --inputbox "\ @@ -96,24 +96,49 @@ hostnamectl set-hostname "$NEW_HOST" msg "Hostname set to $NEW_HOST" ############################################################################### -# SSH keys # +# SSH keys for root # ############################################################################### install -d -m 700 /root/.ssh chmod 700 /root/.ssh # Add default key if provided -if [[ -n "$DEFAULT_SSH_KEY" ]]; then +test -n "$DEFAULT_SSH_KEY" && { grep -qxF "$DEFAULT_SSH_KEY" /root/.ssh/authorized_keys 2>/dev/null || \ echo "$DEFAULT_SSH_KEY" >> /root/.ssh/authorized_keys chmod 600 /root/.ssh/authorized_keys - msg "Default SSH key added to authorized_keys" -fi -# Optionally add more keys -if confirm "Add additional SSH public key?"; then - KEY=$(whiptail --title "SSH Key" --inputbox "Paste your public key:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled" + msg "Default SSH key added for root" +} +# Optionally add more keys for root +if confirm "Add additional SSH public key for root?"; then + KEY=$(whiptail --title "SSH Key (root)" --inputbox "Paste your public key for root:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled" grep -qxF "$KEY" /root/.ssh/authorized_keys 2>/dev/null || \ echo "$KEY" >> /root/.ssh/authorized_keys chmod 600 /root/.ssh/authorized_keys - msg "Additional SSH key added" + msg "Additional SSH key added for root" +fi + +############################################################################### +# SSH keys for user jordanwages # +############################################################################### +USER_NAME="jordanwages" +USER_HOME="/home/$USER_NAME" +install -d -m 700 "$USER_HOME/.ssh" +chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh" +# Add default key if provided +test -n "$DEFAULT_SSH_KEY" && { + grep -qxF "$DEFAULT_SSH_KEY" "$USER_HOME/.ssh/authorized_keys" 2>/dev/null || \ + echo "$DEFAULT_SSH_KEY" >> "$USER_HOME/.ssh/authorized_keys" + chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh/authorized_keys" + chmod 600 "$USER_HOME/.ssh/authorized_keys" + msg "Default SSH key added for $USER_NAME" +} +# Optionally add more keys for user +if confirm "Add additional SSH public key for $USER_NAME?"; then + KEY=$(whiptail --title "SSH Key ($USER_NAME)" --inputbox "Paste public key for $USER_NAME:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled" + grep -qxF "$KEY" "$USER_HOME/.ssh/authorized_keys" 2>/dev/null || \ + echo "$KEY" >> "$USER_HOME/.ssh/authorized_keys" + chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh/authorized_keys" + chmod 600 "$USER_HOME/.ssh/authorized_keys" + msg "Additional SSH key added for $USER_NAME" fi ############################################################################### @@ -156,7 +181,7 @@ for host in "${CIFS_HOSTS[@]}"; do grep -q "${host}.wageshouse" /etc/fstab || printf "# $TEMPLATE\n" "username" "password" >> /etc/fstab fi done -if ! mount -a 2>>"$LOGFILE"; then msg "⚠️ Some CIFS mounts failed. Re-run the script to correct credentials."; fi +if ! mount -a 2>>"$LOGFILE"; then msg "⚠️ Some CIFS mounts failed. Re‑run the script to correct credentials."; fi ############################################################################### # Summary #