Created
February 3, 2022 19:08
-
-
Save Rigil-Kent/debfdef5daa439187bb4368a90716f1f to your computer and use it in GitHub Desktop.
Change SSH Port to a random number in a specified range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# range is inclusive | |
# replaces the entire line of the match (uncommenting in the case of newly provisioned servers) | |
NEW_PORT=$(shuf -i 3101-7999 -n 1) | |
sudo sed -i "/Port 22/c Port $NEW_PORT" /etc/ssh/sshd_config && sudo systemctl restart sshd && echo "SSH Port has been changed to $NEW_PORT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment