Created
May 24, 2017 08:05
-
-
Save loleg/d33693b5a75534679ef9556c0d88ce30 to your computer and use it in GitHub Desktop.
A handy script to start a new box, based on other people's Stackscripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# Base server that sets a root SSH key and disables password auth. Used by me for Ansible-based deploys. | |
# <UDF name="HOSTNAME" Label="Hostname" /> | |
# <UDF name="USERNAME" Label="Username" /> | |
# <UDF name="PASSWORD" Label="Password" /> | |
# <UDF name="SSH_KEY" Label="SSH Key" /> | |
# <UDF name="FQDN" Label="Domain Name"> | |
source <ssinclude StackScriptID=46109> | |
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://') | |
apt-get update -o Acquire::ForceIPv4=true | |
goodstuff | |
# Basic Stuff | |
ssh_disable_root | |
user_add_sudo "$USERNAME" "$PASSWORD" | |
user_add_pubkey "$USERNAME" "$SSH_KEY" | |
system_set_hostname "$HOSTNAME" | |
system_add_host_entry "$IPADDR" "$HOSTNAME" | |
system_add_host_entry "$IPADDR" "$FQDN" | |
service sshd restart | |
# Kernel Stuff | |
## Prevents debconf prompt | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" linux-image-virtual grub2 -y | |
update-grub | |
echo '%sudo ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers | |
groupadd docker | |
usermod -aG docker $USERNAME | |
## Configure firewall | |
ufw default deny incoming | |
ufw default allow outgoing | |
ufw allow ssh | |
ufw allow http | |
ufw allow https | |
ufw enable | |
# Base packages | |
apt-get install -q -y zip git make nginx python-virtualenv python-dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment