Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Git on EC2 to pull from GitHub repo

I'm kind of new to both EC2 and Git, and I have just set up my first instance of EC2, using a clean Amazon Linux AMI. I also installed MySQL, Apache and PHP and opened some ports to make it work as a normal web server, responding to an elastic IP as well.

Now, my code is on a private repo on GitHub, and I would like to perform simple deployments by doing git pull or something like that. Git is also installed on the server already. I know I could set up my git repo on the server using my personal ssh key, but it seems odd. I guess another solution would be to create a new GitHub user and use it on the server, but it doesn't seem right either.

How do I achieve this in an elegant, safe way?

like image 408
luchomolina Avatar asked Oct 20 '11 07:10

luchomolina


People also ask

How do I pull a repository from GitHub Linux?

To do so, simply open a terminal window in the directory with the local version of the repository and type the command “git pull”. The operation of this command is particularly simple if you're just wanting to download an updated version of the repository; the local version will be updated to match the remote version.

How do I add a GitHub repository to AWS?

To create a connection for AWS CodeDeploy applications to a GitHub account, sign out of GitHub in a separate web browser tab. In GitHub token name, type a name to identify this connection, and then choose Connect to GitHub. The web page prompts you to authorize CodeDeploy to interact with GitHub for your application.


1 Answers

To avoid having to keep an SSH private key on your EC2 instance, people often use a workflow that involves pushing to that remote server in order to deploy. Essentially, you set up a bare git repository there with a pre-receive hook that deploys to another directory. There is a simple example of doing this in this tutorial. Then you only need to have your SSH public key in ~/.ssh/authorized_keys on the server. However, with this workflow, you couldn't deploy directly from your GitHub repository - you would need to pull it locally and then push to the EC2 machine.

An alternative is to use GitHub's deploy keys mechanism. This would involve creating a new SSH key-pair on your EC2 instance, and adding the public key as a deploy key into your private repository on GitHub. Then you can pull directly from your private GitHub repository to your EC2 instance.

like image 103
Mark Longair Avatar answered Sep 21 '22 04:09

Mark Longair