Home > Back-end >  I have to enter my login twice and ssh-key doesn't work on a dockerized gitlab
I have to enter my login twice and ssh-key doesn't work on a dockerized gitlab

Time:01-30

I launch gitlab with this command:

sudo docker run --detach --hostname example.com --publish 4433:443 --publish 8080:80 --publish 2222:22 --name gitlab --restart always --volume /data/gitlab/config:/etc/gitlab --volume /data/gitlab/logs:/var/log/gitlab --volume /data/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest

example.com being another URL, as you may have guessed.

I have an nginx server with this config:

server {
  server_name example.com;
  client_max_body_size 50m;
  location / {
    proxy_pass http://127.0.0.1:8080/;
    proxy_set_header Host $http_host;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote-addr;
  }
  listen 443 ssl;
  ssl_certificate [MY PATH TO THE .pem FILE];
  ssl_certificate_key [OTHER PATH];
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
  if ($host = example.com) {
    return 301 https://$host$request_uri;
  }
}

When I use HTTPS to clone and push repos, I have to enter my login/password twice, and when I use ssh (for example git clone [email protected]:myuser/myproject.git), it asks me for a password.

I triple checked, my ssh key configuration is correct.

I left the gitlab.rb config by default, except for this line:

external_url 'https://example.com'

What happens here?

CodePudding user response:

For this particular key, I don't use a passphrase

That means SSH fails to connect to example.com as git, and falls back to the Identity authentication: git's password (which you are not supposed to have).

Using a port syntax HOST_PORT:CONTAINER_PORT, you are supposed to launched your GitLab Docker container with a host port (for instance 2222) mapped to GitLab internal SSH daemon (port 22)

sudo docker run [...] -port 2222:22

Then check it is working with:

ssh -T [email protected] -p 2222
Welcome to GitLab, @you!

With a ~/.ssh/config file, it is easier:

Host         gl
hostname     example.com
port         2222
User         git
IdentityFile ~/.ssh/yourGitLabkey

Then:

ssh -T gh
Welcome to GitLab, @you!

See as examples this thread, or this thread, based on the official documentation "Install GitLab using Docker Compose", mentioned by issue 1767.

  • Related