Fix AWS EC2 Server Disconnect from GitHub - oldfartdeveloper/paypal_ipn_forwarder GitHub Wiki

Unreliable Connection from AWS EC2 Instance to GitHub

This note describes what happens when an AWS EC2 instance is unable to reliably clone, pull, fetch, or any other git operation because it cannot access the SSH passphrase.

Symptoms

You've launched a new AWS EC2 t2 instance and you'd like to use the ssh protocol to pull from GitHub the software you want to run on the instance. You want to use a passphrase on your id_rsa private key to make your EC2 instance more secure, so you specify one.

But, having added the passphrase, you now experience some or all of the following problems:

  1. Everytime you type a git command that accesses GitHub, you are asked to re-enter the passphrase.

  2. So, you use the ssh-agent to automatically retrieve and manage the passphrase as described by GitHub. BUT, it doesn't always work:

Solution

The only one I found was this one which I push into its own bash script.

After adding the script and running it from .bash_profile, I only had to set the passphrase once. After that, now the connection to GitHub is reliable:

  • When I log into the server, I can always do git fetch origin w/o error.
  • There is always one ssh-agent running and its pid is always the same.

Problem solved!