Non-Root SSH
#!/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
# Define the target file path
TARGET_FILE="/etc/ssh/sshd_config.d/20-disable_root_login.conf"
# Append the lines to the file
echo -e "PermitRootLogin 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):