From c60ab060ef12e517c14a03fc434c118bc25409c6 Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Thu, 25 Apr 2024 17:29:24 +0000 Subject: [PATCH] new ssh port changing script. --- one-time-stuff/basic-settings.sh | 3 --- one-time-stuff/ssh-port-change.sh | 33 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 one-time-stuff/ssh-port-change.sh diff --git a/one-time-stuff/basic-settings.sh b/one-time-stuff/basic-settings.sh index eb471c6..8e7e5bb 100755 --- a/one-time-stuff/basic-settings.sh +++ b/one-time-stuff/basic-settings.sh @@ -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" diff --git a/one-time-stuff/ssh-port-change.sh b/one-time-stuff/ssh-port-change.sh new file mode 100755 index 0000000..f61fa96 --- /dev/null +++ b/one-time-stuff/ssh-port-change.sh @@ -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? []: ' 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