Last active
July 15, 2024 17:18
-
-
Save rameerez/a9fa4e78bebe7caf91fced41d781d60f to your computer and use it in GitHub Desktop.
Post-setup script to run after setting up a new Rails + Capistrano server via the Ubuntu Server setup script
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 | |
| # This scripts performs the initial setup for an EC2 AMI that has | |
| # been previously prepared to accept Rails apps. | |
| # --- USER DATA SCRIPT STARTS --- | |
| # Configure SSH key for the rails user (same as ubuntu, AWS configured key) | |
| sudo mkdir /home/rails/.ssh | |
| sudo cp /home/ubuntu/.ssh/authorized_keys /home/rails/.ssh | |
| sudo chown -R rails:rails /home/rails/.ssh | |
| sudo chmod 700 /home/rails/.ssh | |
| sudo chmod 600 /home/rails/.ssh/authorized_keys | |
| # Copy Github SSH credentials so Capistrano is able to pull code from private Github repos | |
| cat << EOF > /home/rails/.ssh/id_rsa | |
| -----BEGIN OPENSSH PRIVATE KEY----- | |
| <REDACTED> | |
| -----END OPENSSH PRIVATE KEY----- | |
| EOF | |
| cat << EOF > /home/rails/.ssh/id_rsa.pub | |
| ssh-rsa <REDACTED> | |
| <REDACTED> <redacted-email>@users.noreply.github.com | |
| EOF | |
| # Set up the right permissions to the ssh folder | |
| sudo chown -R rails:rails /home/rails/.ssh | |
| sudo chmod 700 /home/rails/.ssh | |
| sudo chmod 600 /home/rails/.ssh/authorized_keys | |
| sudo chmod 600 /home/rails/.ssh/id_rsa | |
| sudo chmod 600 /home/rails/.ssh/id_rsa.pub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment