#!/usr/bin/env bash

function replace_or_append() {
    key="$1"
    value="$2"

    if ! grep -qE "^${key}\s+.*$" "/etc/ssh/sshd_config"; then
        echo "${key} ${value}" >> "/etc/ssh/sshd_config"
    else
        sed -i -rE "s,^${key}\s+.*$,${key} ${value}" "/etc/ssh/sshd_config"
    fi
}

replace_or_append "PermitRootLogin" "no"
replace_or_append "HostKey" "/etc/ssh/ssh_host_rsa_key"
replace_or_append "X11Forwarding" "yes"
replace_or_append "UseDNS" "no"
