toolkit/shell/ssh-enhancer.sh

23 lines
567 B
Bash

#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: sudo bash $0 <port>"
exit 1
fi
port=$1
# Check if the port is a number
if ! [[ "$port" =~ ^[0-9]+$ ]]; then
echo "Error: Port must be a number."
exit 1
fi
# Create a new sshd_config file with 99- prefix in /etc/ssh/sshd_config.d/ directory
echo -e "Port $port\nPasswordAuthentication no" | sudo tee /etc/ssh/sshd_config.d/99-custom_ssh_port.conf > /dev/null
# Restart SSH service to apply changes
sudo systemctl restart sshd
echo "SSH port changed to $port and password authentication disabled."