Preparation failed: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

I have an AWS Ubuntu instance which has GitLab CE configured. Now I
want to configure GitLab CI to deploy my NodeJS app after each commit.I
don’t have any proper step by step solution for this.

My NodeJS app running in /var/www/mean/my-app on http://myapp.mydomain.com and the hosting is handled by Apache Proxy,

<VirtualHost *:80>
   ServerName myapp.mydomain.com
   ProxyPreserveHost On
   ProxyPass / http://localhost:8089/
   ProxyPassReverse / http://localhost:8089/
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And the app is bootstrapped using forever module

forever start app.js

The gitlab config check sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production gives,

Checking GitLab Shell ...

GitLab Shell version >= 4.0.0 ? ... OK (4.0.0)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ... 
dev / my-app ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /home/git/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured with autocrlf=input? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... 
dev / my-app ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.1)
Your git bin path is "/usr/bin/git"
Git version >= 2.7.3 ? ... yes (2.7.4)
Active users: 1

Checking GitLab ... Finished

I used to login to the instance using SSH from my system,

ssh -i API-Key.pem ubuntu@ec2-XX-XX-XXX-XXX.ap-south-1.compute.amazonaws.com

Created key using command

ssh-keygen -t rsa

Runner config on /etc/gitlab-runner/config.toml

concurrent = 1
check_interval = 0

[[runners]]
  name = "Production Runner"
  url = "http://gitlab.mydomain.com/ci"
  token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
  executor = "ssh"
  [runners.ssh]
    user = "ubuntu"
    host = "ip-XXX-XX-XX-XXX"
    identity_file = "/home/ubuntu/.ssh/id_rsa"
  [runners.cache]

Code on .gitlab-ci.yml

test_async:   
 script:    
  - npm install

Because of my bad configuration, the runner gives error,

Running with gitlab-ci-multi-runner 1.7.1 (f896af7)
Using SSH executor...
ERROR: Preparation failed: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
Will be retried in 3s ...

My confusions are:

What should be the content of .gitlab-ci.yml file to deploy the committed code to the application location?

And how to configure a runner for this? If I have to use an ssh runner, what should be the configurations over there?

1 Like

I too have the same error and questions, but I am using the virtualbox executor rather than aws.

1 Like

I wish someone from gitlab would respond to this issue, there are other similar ssh runner issues that no one is answering. Support asked me to turn on debug. That did not help.

Here is debug process for this situation.

Verify you can logging to remote ssh server manually using same local user and same key file than gitlab-runner

sudo su - USER

eval `ssh-agent -s`
ssh-add YOUR_SSH_KEY_FILE
ssh REMOTEU_SER@REMOTE_SERVER

You should solve any issue here before continue.

Run gitlab-runner with log in debug mode

sudo vi /etc/gitlab-runner/config.toml

Add log_level = "debug"

# Sample
concurrent = 1
check_interval = 0
log_level = "debug"
...

Then restart gitlab-runner

sudo gitlab-runner restart

Retry to run buggy job.

If it does not help go to next step.

Launch remote sshd in debug mode

Run SSH daemon on another port as a part of the command (then you don’t need to lost your existing session, if already connect thought ssh)

sudo /usr/sbin/sshd -d -p 2200
# sudo /usr/sbin/sshd -dd -p 2200 - if you need more logs
# sudo /usr/sbin/sshd -ddd -p 2200 - if you need all logs

Warn: You should run this for each ssh connection.

Then modify gitlab-runner configuration (on gitlab runner host)

sudo vi /etc/gitlab-runner/config.toml

Add port = "2200"

...
[[runners]]
  name = "XXXXX"
  url = "https://XXXXX/"
  token = "XXXXX"
  executor = "ssh"
  [runners.ssh]
    user = "XXXXX"
    host = "XXXXX"
    port = "2200"
    identity_file = "XXXXX"
...

Retry to run buggy job.

On console sshd console you are able to see all gitlab-runner actions and you should be able to understand what is the issue.

1 Like