Search code examples
gitsshamazon-ec2gitlabgitlab-omnibus

permission denied when cloning from GitLab repo hosted on an Amazon EC2 instance


I can't push to/clone from a GitLab running on an Amazon EC2 instance. Here is what I did so far

  • Created a keypair on my local machine
  • Created a project in Gitlab (my GitLab user has owner-permissions)
  • Add my public key in the webconfig of my user in Gitlab

When I try to clone that repository via git clone [email protected]:project-group/project.git I get the infamous message:

Permission denied (publickey).

How can I configure my EC2-instance to accept clone/push/pull requests from users who added their SSH-keys via Gitlabs web-interface?


Solution

  • User ubuntu? Usually, the user configure for a GitLab instance is git.

    Try and modify your .ssh/config file with User git, and use that url:

    git clone myhost:project-group/MyRepo.git
    

    Make sure that test.pub (the public key extracted from the pem file) is registered properly on the repo (or in your GitLab account, if you are the owner of that repo). If test.pem is the key used to access the EC2 instance, then you would need to generate a separate public/private set of keys and use those instead in accessing GitLab.

    After discussion below, it appears that:

    • GitLab is installed on an EC2 instance with Omnibus-gilab
    • Omnibus-gitlab means using gitlab-rake some_task (not 'rake' directly)
    • a gitlab-rake gitlab:check points out that the authorized_keys file resides in /var/opt/gitlab/.ssh/authorized_keys
    • the git account was locked (unlocking it made the Gitlab work: git:!: to git:*: in the file /etc/shadow).
      This is similar to the "Trouble Shooting Guide - SSH" section.