Last active
March 4, 2018 21:10
-
-
Save weibeld/2a649179aecd596cf762a75ac174c3e6 to your computer and use it in GitHub Desktop.
AWS EC2 Ubuntu instance configuration script
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 | |
# | |
# Script executed automatically upon launch of an AWS EC2 Ubuntu instance. | |
# | |
# Pass this script as the "user data" to the instance launching process: | |
# | |
# - Web Console: Step 3 | |
# - CLI: aws ec2 run-instances ... --user-data "commands..." | |
# | |
# Note that all commands in this script are executed as root in /root. | |
# | |
# Output of this script is in /var/log/cloud-init-output.log | |
# | |
# Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html | |
#------------------------------------------------------------------------------# | |
# Install dotfiles | |
runuser -l ubuntu -c 'curl -Lks http://bit.ly/get-my-dotfiles | bash' | |
# Install Docker and add user 'ubuntu' to group 'docker' | |
apt-get update | |
apt-get install -y docker.io | |
sudo usermod -aG docker ubuntu | |
# Listen on an additional port (default is 22) for SSH connections | |
echo "Port 4500" >>/etc/ssh/sshd_config | |
service sshd restart | |
# Add function for printing public DNS hostname of this instance | |
runuser -l ubuntu -c "echo 'public-hostname() { curl -s http://169.254.169.254/latest/meta-data/public-hostname && echo; }' >>~/.bashrc_trash" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment