Skip to content

Instantly share code, notes, and snippets.

@hieunba
Last active July 5, 2018 08:28
Show Gist options
  • Save hieunba/efa1f1fc9b549b4dd6f44fa21d55504e to your computer and use it in GitHub Desktop.
Save hieunba/efa1f1fc9b549b4dd6f44fa21d55504e to your computer and use it in GitHub Desktop.
Oxi Hardening
#!/bin/bash
# check root
if [[ `id -u` -ne 0 ]] ; then
echo "Please run this under root."
echo 1
fi
# Hardening SSH
harden-ssh() {
# backup
SSH_PORT="55059"
SSHD_CONF="/etc/ssh/sshd_config"
# port changing
cp -f ${SSHD_CONF} "${SSHD_CONF}.bak"
cat > /etc/ufw/applications.d/oxi-openssh-server <<END
[OpenSSH-Oxi]
title=Secure shell server, an rshd replacement
description=OpenSSH is a free implementation of the Secure Shell protocol.
ports=${SSH_PORT}/tcp
END
# change port
echo "Changing port to ${SSH_PORT}"
sed -i "/Port/ s/22/${SSH_PORT}/" ${SSHD_CONF}
# apply changes
ufw allow OpenSSH-Oxi
systemctl restart ssh.service
}
## start
harden-ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment