Automatically Config SSHd


14 Mar 2015

Automatically Config SSHd

Preston Garrison 0 Comments

When setting up servers I want to easily modify the ssh config.  This simple script can be pasted when you first login.  It will remove the lines from the config that match these, and then add the new lines into the config.  You can use this method to easily modify any other config files.


Just paste this into terminal, should work on most Linux and FreeBSD variants.

cat /etc/ssh/sshd_config | grep -v Port | grep -v ClientAliveInterval | grep -v ClientAliveCountMax > /tmp/sshd_config
echo ClientAliveInterval 200 >> /tmp/sshd_config
echo ClientAliveCountMax 200 >> /tmp/sshd_config
echo Port 10022 >> /tmp/sshd_config
cat /tmp/sshd_config > /etc/ssh/sshd_config
rm /tmp/sshd_config
service ssh reload
service sshd reload



Preston Garrison