ubuntugithubamazon-ec2ssh

Cloning Multiple repos on Ec2 | .ssh config error


Problem statement : Clone 2 repos from Github

Actions Taken :

  1. Created 2 ssh keys and added to corresponding repos's deploy keys.
  2. Create a config file in Home/Ubuntu/.ssh folder
      Host aimer-ui github.com
        HostName github.com
        IdentityFile /home/ubuntu/.ssh/id_rsa_new.pub
            
     
    
       Host aimer-service github.com
         HostName github.com
         IdentityFile /home/ubuntu/.ssh/id_rsa.pub

Error Coming on Cloning :

Cloning into 'aimer-ui'...
Load key "/home/ubuntu/.ssh/id_rsa_new.pub": error in libcrypto
Load key "/home/ubuntu/.ssh/id_rsa.pub": Permission denied
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
ubuntu@ip-172-31-44-226:~$ git clone git@github.com:BeA-Brand/aimer-service.git
Cloning into 'aimer-service'...
Load key "/home/ubuntu/.ssh/id_rsa_new.pub": error in libcrypto
Load key "/home/ubuntu/.ssh/id_rsa.pub": Permission denied
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

My Observation : Same ssh being used in cloning the repos. But in that case, atleast one repo would have worked.


Solution

  • I see a few things wrong here.

    First: You went to the trouble of setting up ~/.ssh/config with key-specific hostnames, and then you didn't use those key-specific hostnames. Your commands need to be git clone git@aimer-service:BeA-Brand/aimer-service.git and git clone git@aimer-ui:BeA-Brand/aimer-ui.git (or whatever the correct path is for that one).

    As @erik258 pointed out in the comments, your ~/.ssh/config needs the private keys. Take off the .pub endings.

    You can potentially troubleshoot the libcrypto issue with ssh -Tv git@aimer-ui - GitHub will not give you shell, but the verbose output should be helpful in determining what's wrong with the key.

    You can check the permissions and ownership on /home/ubuntu/.ssh/id_rsa with ls -la /home/ubuntu/.ssh. id_rsa needs to have mode 0600; id_rsa.pub can have mode 0644; the folder needs mode 1700; and all of them need to be owned by the ubuntu user.