new ssh port changing script.

This commit is contained in:
2024-04-25 17:29:24 +00:00
parent d4b328f9b7
commit c60ab060ef
2 changed files with 33 additions and 3 deletions
-3
View File
@@ -236,9 +236,6 @@ read -p 'split bash history by terminal/screen in realtime? [y/N]: ' add_history
case $add_history in
[Yy]* )
if [[ -f "$HOME/.bash_history" ]]; then
echo 'Backing up ~/.bashrc'
cp "$HOME/.bashrc" "$HOME/.bashrc.backup"
echo 'Comment existing history config'
sed -i '/^\(HISTCONTROL\|HISTFILESIZE\|HISTFILE\|HISTIGNORE\|HISTSIZE\|HISTTIMEFORMAT\|shopt -s histappend\|shopt -s histreedit\|shopt -s histverify\)/s/^/# ABS #/' "$HOME/.bashrc"
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
echo 'Enter the desired new port for ssh to use, leave blank to abort.'
read -p 'change ssh to operate on a different port then normal? [<new-port-number>]: ' change_port
if [[ -z "$change_port" ]]; then
echo 'port change aborted'
else
sudo cp "/etc/ssh/sshd_config" "/etc/ssh/sshd_config.port_backup"
sudo sed -i '/^Port/s/^/# ABS #/' '/etc/ssh/sshd_config'
(
cat << CONFIG
Port $change_port
CONFIG
) | sudo tee -a /etc/ssh/sshd_config > /dev/null
echo "----- Restart ssh now -------------------------------"
read -p 'Restart SSH to use updated config? [y/N]: ' restart_ssh
case $restart_ssh in
[Yy]* )
echo 'calling systemctl'
sudo systemctl restart ssh.service
;;
* )
echo 'Skipping'
;;
esac
echo 'REMEMBER TO TEST SSH:'
echo 'ENSURE YOU UPDATE YOUR CLIENT CONFIG.'
fi