gauravmehla/ama

Alternative to connect with EC2 instance instead of .pem file

abhishek11210646 opened this issue · 1 comments

Hi, I am following this article..
https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

It shows to connect to remote git directory like this...
git remote add live ssh://user@mydomain.com/var/repo/site.git

But how can I do this in ec2 as ec2 connect through pem file. so how?

It's simple. Just add your local system's ssh key to your EC2 account. That's it

https://gist.github.com/roalcantara/75e14daf3d10060420590c3fa38684a2

This will help you.

In more detail

By default, AWS do not bind any new instance with any local system. They gave a .pem file using which anybody who has access to that file can login into that instance but what you can do is create an ssh pair on your remote system and add your remote id_rsa.pub to local system. Then you do not need .pem file to login to your EC2 instance. You can directly ssh to your EC2 using -

ssh <user>@<ip or domain>

Then, in your local git repo. Add this URL as remote by mentioning the correct path i.e ssh://<user>@<ip or domain>/<path to remote git repo>

Now you can directly push to your remote repo from local system and then the post-hook on your remote repo will update the root project on your EC2 instance.

Imgur