Change behavior of adding lines to sshd config

* Replace existing lines in cases where a change has already been made
This commit is contained in:
William Wernert
2021-04-02 10:00:27 -04:00
parent 43c31b4e66
commit fd57996bc6
2 changed files with 12 additions and 10 deletions

View File

@@ -38,12 +38,14 @@ print_diff() {
fi fi
} }
add_if_missing() { replace_or_add() {
local string=$1 local type=$1
if ! grep -q "$1" $temp_config; then local string=$2
printf "%s\n\n" "$1" >> $temp_config if grep -q "$type" $temp_config; then
reload_required=true sed -i "/$type .*/d" $temp_config
fi fi
printf "%s\n\n" "$string" >> $temp_config
reload_required=true
} }
test_config() { test_config() {
@@ -76,7 +78,7 @@ main() {
if [[ $verbose ]]; then print_diff; fi if [[ $verbose ]]; then print_diff; fi
if [[ $before != "$after" ]]; then if [[ $before != "$after" ]]; then
add_if_missing "$cipher_string" && test_config || exit 1 replace_or_add "ciphers" "$cipher_string" && test_config || exit 1
fi fi
# KexAlgorithms # KexAlgorithms
@@ -90,7 +92,7 @@ main() {
if [[ $verbose ]]; then print_diff; fi if [[ $verbose ]]; then print_diff; fi
if [[ $before != "$after" ]]; then if [[ $before != "$after" ]]; then
add_if_missing "$kexalg_string" && test_config || exit 1 replace_or_add "kexalgorithms" "$kexalg_string" && test_config || exit 1
fi fi
# Macs # Macs
@@ -103,7 +105,7 @@ main() {
if [[ $verbose ]]; then print_diff; fi if [[ $verbose ]]; then print_diff; fi
if [[ $before != "$after" ]]; then if [[ $before != "$after" ]]; then
add_if_missing "$macs_string" && test_config || exit 1 replace_or_add "macs" "$macs_string" && test_config || exit 1
fi fi
# HostKeyAlgorithms # HostKeyAlgorithms
@@ -116,7 +118,7 @@ main() {
if [[ $verbose ]]; then print_diff; fi if [[ $verbose ]]; then print_diff; fi
if [[ $before != "$after" ]]; then if [[ $before != "$after" ]]; then
add_if_missing "$hostkeyalg_string" && test_config || exit 1 replace_or_add "hostkeyalgorithms" "$hostkeyalg_string" && test_config || exit 1
fi fi
if [[ $reload_required == true ]]; then if [[ $reload_required == true ]]; then

View File

@@ -906,7 +906,7 @@ set_redirect >> $setup_log 2>&1
set_progress_str 85 'Applying finishing touches' set_progress_str 85 'Applying finishing touches'
filter_unused_nics >> $setup_log 2>&1 filter_unused_nics >> $setup_log 2>&1
network_setup >> $setup_log 2>&1 network_setup >> $setup_log 2>&1
so-ssh-harden -q >> $setup_log 2>&1 so-ssh-harden >> $setup_log 2>&1
if [[ $is_manager || $is_import ]]; then if [[ $is_manager || $is_import ]]; then
set_progress_str 87 'Adding user to SOC' set_progress_str 87 'Adding user to SOC'