Back to Guides
AWSEC2GitHubStreamlit

Clone a Private GitHub Repository on AWS EC2 & Run a Streamlit App

A step-by-step guide to securely authenticating your EC2 instance with GitHub using Deploy Keys and deploying a Python Streamlit application.

1

Create a Deploy Key on EC2

First, SSH into your EC2 instance. We need to generate a secure SSH key pair that will identify this specific server to GitHub.

Terminal (EC2)
ssh-keygen -t ed25519 -a 100 -C "your-email@example.com"

When prompted for a file path, press Enter to accept the default. When prompted for a passphrase, you can leave it empty (press Enter twice) for automated scripts, or add one for extra security.

Next, display the public key so you can copy it:

Terminal (EC2)
cat ~/.ssh/id_ed25519.pub

Output Example:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... your-email@example.com

2

Add the Deploy Key to GitHub

  1. Navigate to your repository on GitHub.
  2. Go to Settings > Deploy keys (in the sidebar).
  3. Click Add deploy key.
  4. Provide a Title (e.g., "AWS EC2 Instance").
  5. Paste the public key you copied in Step 1 into the Key field.
  6. (Optional) Check "Allow write access" only if your app needs to push code back to the repo.
  7. Click Add key.
3

Test Connection & Install Git

Back on your EC2 terminal, verify that GitHub accepts your new key:

Terminal (EC2)
ssh -T git@github.com

Type yes if prompted to verify the host fingerprint. You should see a success message like:
Hi username! You've successfully authenticated...

Now, ensure your package manager is updated and Git is installed:

Terminal (EC2)
sudo yum update -y sudo yum install git -y
4

Clone the Repository & Run

Use the SSH URL (not HTTPS) to clone your repo. This allows Git to use the SSH key we just set up.

Terminal (EC2)
# Replace with your actual repo SSH URL git clone git@github.com:OrgName/your-repo.git cd your-repo

Install your Python dependencies:

Terminal (EC2)
pip install -r requirements.txt

Finally, launch your Streamlit application:

Terminal (EC2)
streamlit run streamlit_app.py

To Keep it Running

Running streamlit run directly will stop the app if you close your SSH terminal. To keep it running in the background, use tmux or nohup:

nohup streamlit run streamlit_app.py &

Need help?

If you encounter any issues with permission denied errors, ensure your key is added to the ssh-agent using ssh-add ~/.ssh/id_ed25519.

Feel free to reach out: its.royniloy@gmail.com