简体   繁体   中英

Push a git repo to a remote server via ssh

So I have an AWS EC2 server that I ssh into using a private.pem file. I do this by passing it as an argument with -i flag

ssh -i private.pem "user@host"

And this private.pem file is not in my .ssh directory.

I have a git repository on my ec2 which I want to push to, but I am not able to figure out how I should use the private.pem file for authentication.

To tell what is the exact problem, I had a similar thing with DigitalOcean, where I had a vps, and I could ssh into it without using the -i flag, since when I created the ssh key for digitalocean, it was automatically placed in my .ssh directory, so I could just ssh into it using

ssh user@host

And for ec2, I use,

ssh -i private.pem "host"

When I added the remote for digital ocean, it was

git remote add production ssh://user@host/path/to/repo

And while pushing, it automatically used the correct ssh key from my .ssh directory.

But for ec2, I don't understand how to specify the ssh key which IS NOT in .ssh directory.

I have read other answers and tried using the config file in .ssh and also GIT_SSH_COMMAND, but haven't had success.

I generated a new key and used that for authentication. Worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM