Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect EC2 to Git by ssh

Having a EC2 instance with a Git repository, I need to update it by ssh-key.

I tried:

  1. Add authorized_keys into GitHub. --> Not working and not the right way.

  2. Create a new ssh-key, add it into EC2 console pair-key and add into GitHub. As ssh-add not working at EC2 instance, @Biswajit Mohanty suggested me to run ssh -T [email protected], and got the proper answer but still getting 'permission denied (publickey). fatal: could not read from remote repository' when pulling.

I already configured the .git/config as it should:

    sshCommand = "ssh -i ~/.ssh/id_rsa.pub"

[remote "origin"] url = ssh://[email protected]/ArantecEnginheria/smartyplanet.git

Any suggestion about to success doing a 'pull' and update the code into that server?

like image 237
NorthmaN Avatar asked Jul 01 '26 20:07

NorthmaN


2 Answers

ssh-keygen -t rsa 
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/.ssh/id_rsa): ./yourgitkey
Enter passphrase (empty for no passphrase):  
Enter same passphrase again: 
Your identification has been saved in ./yourgitkey
Your public key has been saved in ./yourgitkey.pub

copy the content of the ./yourgitkey.pub to GitHub https://github.com/settings/keys

Add New SSH key and enter the ./yourgitkey.pub

To avoid Permission error : make your private key permission to

chmod 400 ./yourgitkey 

Enter the following:

$ ssh -T [email protected]

You may see a warning like this:

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
Verify that the fingerprint in the message you see matches GitHub's RSA public key fingerprint.

If it does, then type yes:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

You Are Ready Now !!!

like image 173
Biswajit Mohanty Avatar answered Jul 03 '26 13:07

Biswajit Mohanty


You generally do not add an authorized_keys to GitHub. You register a public SSH key to your GitHub user profile, in order to establish the proper authentication.

If you need to push to a GitHub repository from an EC2 instance, (meaning from an EC2 instance session), then said session should include a ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub: private/public key pair, with the public one registered to GitHub as mentioned above.

like image 28
VonC Avatar answered Jul 03 '26 12:07

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!