Passwordless SSH Title Before proceeding make sure Key-Based Authentication (see: SSH Keys) is configured! #!/bin/bash # Check if the script is run as root if [ "$(id -u)" -ne 0 ]; then echo "This script must be run as root. Use 'sudo' to run it." >&2 exit 1 fi # Display the important message echo "IMPORTANT: First Setup SSH Key-Based Authentication AND TEST IT!" # Ask for user confirmation to proceed read -p "Have you set up and tested SSH key-based authentication? (y/N) " response # Check the user's response case "$response" in [yY][eE][sS]|[yY]) # The user agreed, proceed with the script echo "Proceeding with SSH configuration..." ;; *) # Any other response means abort echo "Operation aborted. Please set up and test SSH key-based authentication before running this script again." exit 1 ;; esac # Define the target file path TARGET_FILE="/etc/ssh/sshd_config.d/10-passwordless_login.conf" # Append the lines to the file echo -e "ChallengeResponseAuthentication no\nPasswordAuthentication no" | tee -a "$TARGET_FILE" > /dev/null # Restart the SSH service to apply changes. This command might vary based on your system. systemctl restart sshd Relevant Note(s):