change the SSH port
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Warning: Before running this script, make sure you have created a user and an SSH key in the authorized_keys file.
|
||||||
|
|
||||||
# This script is designed to configure the SSH server on a Linux system according to Mozilla's security best practices.
|
# This script is designed to configure the SSH server on a Linux system according to Mozilla's security best practices.
|
||||||
# It enhances the security of SSH connections by enforcing modern encryption standards, disabling insecure protocols, and restricting root access.
|
# It enhances the security of SSH connections by enforcing modern encryption standards, disabling insecure protocols, and restricting root access.
|
||||||
# The script backs up the original SSH configuration file, applies a new set of secure settings, and then restarts the SSH service to apply the changes.
|
# The script backs up the original SSH configuration file, applies a new set of secure settings, and then restarts the SSH service to apply the changes.
|
||||||
@@ -34,6 +36,15 @@ else
|
|||||||
allow_users="# AllowUsers configuration not set"
|
allow_users="# AllowUsers configuration not set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ask user if they want to change the SSH port
|
||||||
|
read -p "Do you want to change the SSH port? (yes/no): " change_port
|
||||||
|
if [[ "$change_port" == "yes" ]]; then
|
||||||
|
read -p "Enter the new SSH port: " new_port
|
||||||
|
port_setting="Port $new_port"
|
||||||
|
else
|
||||||
|
port_setting="# Port configuration not changed"
|
||||||
|
fi
|
||||||
|
|
||||||
# Modify the sshd_config file
|
# Modify the sshd_config file
|
||||||
cat <<EOL > "$SSHD_CONFIG"
|
cat <<EOL > "$SSHD_CONFIG"
|
||||||
# Mozilla SSH Security Recommendations
|
# Mozilla SSH Security Recommendations
|
||||||
@@ -68,6 +79,9 @@ ClientAliveCountMax 2
|
|||||||
|
|
||||||
# IP restriction based on user input
|
# IP restriction based on user input
|
||||||
$allow_users
|
$allow_users
|
||||||
|
|
||||||
|
# SSH port based on user input
|
||||||
|
$port_setting
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
# Restart the SSH service
|
# Restart the SSH service
|
||||||
|
|||||||
Reference in New Issue
Block a user