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:
-
Everytime you type a git command that accesses GitHub, you are asked to re-enter the passphrase.
-
So, you use the
ssh-agent
to automatically retrieve and manage the passphrase as described by GitHub. BUT, it doesn't always work:- You have to re-enter the passphrase each time you log into the EC2 instance.
- You get an error:
Could not open a connection to your authentication agent
- And when you try fixing the problems above, you end up finding
multiple instances of the
ssh-agent
daemon, or none, and in any case the passphrase processed is not the right one.
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 itspid
is always the same.
Problem solved!