Skip to content

Instantly share code, notes, and snippets.

@gtrabanco
Last active April 27, 2024 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtrabanco/1d81a9129cee29c5fdb3639b67bd7603 to your computer and use it in GitHub Desktop.
Save gtrabanco/1d81a9129cee29c5fdb3639b67bd7603 to your computer and use it in GitHub Desktop.
Initial setup for ubuntu/debian server
#!/usr/bin/env bash
if ! command -p sudo -n -v > /dev/null 2>&1; then
echo "Execute this script as admin by using sudo writing:"
echo " sudo !!"
echo
fi
# Update
apt update -y
apt upgrade -y
apt dist-upgrade -y
#Vim
apt install -y vim
# Unnatended upgrades
apt install -y unattended-upgrades
# Firewall
apt install -y iptables-persistent ufw
ufw allow ssh
ufw enable
# Minimal firewall rules if no ufw installed
#iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#iptables -P INPUT DROP
#ip6tables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#ip6tables -P INPUT DROP
# Save firewall rules
iptables-save | tee /etc/iptables/rules.v4
ip6tables-save | tee /etc/iptables/rules.v6
# Remove unnecessary stuff
apt autoremove --purge # This will cleanup also old kernels, maybe you should do this as well after reboot. Maybe there was an installtion of new kernel when updating...
apt autoclean
apt clean
# Check apt cache is empty (12K is empty)
du -sh /var/cache/apt
@gtrabanco
Copy link
Author

commit="011a673c242ec2705f0939d4c4d337d535d5bda5"
curl -fsS https://gist.github.com/gtrabanco/1d81a9129cee29c5fdb3639b67bd7603/raw/${commit}/debian-based-server-initial.sh | sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment