Last active
December 18, 2020 17:39
-
-
Save ryansch/b7b6475e5d3d8f3a2c1fe45917f62900 to your computer and use it in GitHub Desktop.
linode stackscript for bootstrapping ubuntu with docker
This file contains hidden or 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 | |
set -euo pipefail | |
#<UDF name="name" label="Node name"> | |
source <ssinclude StackScriptID="1"> | |
#source ./bash.sh | |
echo "Setting up ubuntu user's ssh key" | |
mkdir -p ~ubuntu/.ssh | |
chown ubuntu:ubuntu ~ubuntu/.ssh | |
chmod 700 ~ubuntu/.ssh | |
cp /root/.ssh/authorized_keys ~ubuntu/.ssh/authorized_keys | |
chown ubuntu:ubuntu ~ubuntu/.ssh/authorized_keys | |
echo "Updating packages" | |
apt-get update | |
apt-get upgrade -y | |
echo "Setting hostname" | |
system_set_hostname ${NAME}-linode | |
echo "Hardening ssh" | |
cat > /etc/ssh/sshd_config <<EOM | |
AuthorizedKeysFile .ssh/authorized_keys | |
ClientAliveInterval 180 | |
Subsystem sftp /usr/lib/openssh/sftp-server | |
UseDNS no | |
PermitRootLogin no | |
UsePAM yes | |
KexAlgorithms [email protected] | |
Protocol 2 | |
HostKey /etc/ssh/ssh_host_ed25519_key | |
PasswordAuthentication no | |
ChallengeResponseAuthentication no | |
PubkeyAuthentication yes | |
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr | |
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected] | |
EOM | |
cat > /etc/ssh/ssh_config <<EOM | |
Host * | |
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256 | |
PasswordAuthentication no | |
ChallengeResponseAuthentication no | |
PubkeyAuthentication yes | |
HostKeyAlgorithms [email protected],[email protected],ssh-ed25519,ssh-rsa | |
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr | |
MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected] | |
UseRoaming no | |
EOM | |
systemctl restart sshd | |
echo "Setting up firewall" | |
ufw_install | |
#configure_ufw_firewall 80 443 | |
echo "Installing docker" | |
apt-get install -y \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg-agent \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - | |
add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" | |
apt-get update | |
apt-get install -y docker-ce docker-ce-cli containerd.io | |
groupadd docker || true | |
usermod -aG docker ubuntu | |
systemctl enable docker | |
echo "Installing docker-compose" | |
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
chmod +x /usr/local/bin/docker-compose | |
echo "Installing ansible" | |
apt-get install -y python3-pip | |
pip3 install ansible | |
echo "Installing extra packages" | |
apt-get install -y unzip amazon-ecr-credential-helper | |
echo "Stackscript complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment