9

I can authenticate successfully with putty on the server with my private key and passphrase. But when I try to do it with jenkins publish over SSH plugin (using Test for configuration), I get the following error message:

jenkins.plugins.publish_over.BapPublisherException: Failed to connect session for config myconfig. Message [Auth fail]

I entered the same information as in putty:

Hostname : myhostname
Username : myusername
Remote Directory :

Use password authentication, or use a different key Passphrase / Password Path to key : checked
Path to key : mypath
Passphrase : mypasssword
Key:
Port:22
Timeout(ms):300000

If you have any idea ... Thanks for your help.

lese
  • 539
  • 1
  • 5
  • 24
Corinne Kubler
  • 2,072
  • 5
  • 22
  • 34
  • Jenkins guide on the plugin points out that checking the options "Use password authentication, or use a different key Passphrase / Password Path to key" enables three further fields to supply details to "Path to key", "key" and "Passphrase" ... I dont see passphrase on the info above, have you supplied your password in that box as well? – AltF4_ Mar 17 '14 at 23:32
  • added more detail on the answer below – AltF4_ Mar 17 '14 at 23:40
  • Sorry I put the passphrase too but I forgot it in my question. In fact I put exactly the same information as in putty. I really do not understand the issue ! – Corinne Kubler Mar 18 '14 at 18:36
  • I'm getting the same issue... – Michael Wiles Apr 24 '14 at 09:50
  • I have not found the resolution yet :-( – Corinne Kubler Apr 24 '14 at 13:07
  • See [this issue](https://github.com/jenkinsci/publish-over-ssh-plugin/issues/247) on GitHub – ZhekaKozlov Jul 18 '22 at 14:32

13 Answers13

17

Looks like you're using keyfile authentication, so you'll get this error from Jenkins if you haven't set the permissions correctly on your .ssh folder and/or ~/.ssh/authorized_keys file.

  • the .ssh folder should have drwx------ permissions (read/write/execute owner only)
  • the authorized_keys file should have -rw------- permissions (read/write owner only)

To fix it:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Community
  • 1
  • 1
inanutshellus
  • 9,683
  • 9
  • 53
  • 71
  • 4
    I'm having this error `jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [deploy-server]. Message [Auth fail]]` Any other thing I need to take care? I have jenkins user in deploy server I can `ssh` to that through putty. – The_ehT Jan 14 '19 at 17:10
  • In my system, the permissions were correct, but the issue was still there. I was using private key for authentication, this solved it : `cat id_rsa.pub >> authorized_keys` – lycanthrope10100 Jun 09 '21 at 07:49
6

I ran into the same issue today and it turned out i was accidentally supplying the path to the public key instead of the private one.

So the "path to key" should be something like

.ssh/id_rsa

instead of

.ssh/id_rsa.pub
Rinda
  • 326
  • 2
  • 5
3

Because your linux login need password, the answer is :

 1. Passphrase: your passphrase
 2. path to key: your private key path
 3. key : blank
 4. Disable exec : un-check

SSH Servers

1. Name: remote_user@remotehost.com
 2. hostname: remotehost.com
 3. Username: remote_user
 4. Remote Directory: empty

Advanced --

5. check the box "use passsword authentication, or use a different key"
    `important`

 6. Passphrase / Password: your linux login password`important`

 7. path to key: blank

 8. key:blank

 9. port: 22

 10. Timeout(ms): 300000

'Test Configuration' success

Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
2

Check that the public key is in the .ssh/authorized_keys file on the target server, even if the target server is the same as the jenkins server. I had what is probably the same problem, and it turned out that I needed this, even though ssh localhost worked fine.

(Addendum: also check that the jenkins server has the target server in its .ssh/known_hosts file, as that can affect this as well.)

Joey Coleman
  • 479
  • 9
  • 16
  • `.ssh/known_hosts` created issue in my case. removing fingerprint from `known_host` solved the problem – anand Jul 14 '17 at 17:04
1

I think as it says this is a authentication issue:

Use password authentication, or use a different key Selecting this option will produce 3 more configuration boxes that mirror the options available for the Jenkins SSH Key.

Passphrase / Password If either Path to key or Key are configured then this is the passphrase to use with the encrypted key. If no key is configured then this is the password that will be used for password authentication.

Path to key See description above.

Key See description above.

Disable exec This option will remove the ability to execute commands using this configuration.

LINK HERE

AltF4_
  • 2,312
  • 5
  • 36
  • 56
1

I am facing same issue , the following steps work for me:- ( i am using jenkins 1.57)

  1. Go to http:///jenkins/manage
    1. Configure System
    2. Browse to Publish over SSH section
      • Passphrase: blank
      • path to key: blank
      • key : blank
      • Disable exec : un-check
      • SSH Servers -- Name: remote_user@remotehost.com -- hostname: remotehost.com -- Username: remote_user -- Remote Directory: empty -- Advanced -- check the box "use passsword authentication, or use a different key" -- port: 22 -- Timeout(ms): 300000 -- 'Test Configuration'

success

Cherry Yap
  • 21
  • 2
0

Try restarting ssh of remote server

        /etc/init.d/sshd restart
Supun Dharmarathne
  • 1,138
  • 1
  • 10
  • 19
0

Don't do any ssh-keygen. Just enter the pem key details under key field, Add SSH server details: Name, Hostname and Username as ec2-user. Click test connection and it works.

0

Sometimes the SSH connection would fail, if the destination server doesnt have enough disk space to perform PUT operation

{ERROR: Exception when publishing, exception message [Failure]}

Make sure to verify the destination server has enough disk space.

In case of Linux, you can use 'df -kh /directoryname' to check the disk space

Karthik
  • 55
  • 2
  • 9
0

Just copy jenkins-user's id_rsa.pub to the end of ~/.ssh/authorized_keys on remote host.

artemiuz
  • 444
  • 5
  • 7
0

I was having the same exact issue today and thought I would share what worked for me

Normally when I would SSH into my ec2 instance AWS likes the username to be

ubuntu@[ip address/url]

Jenkins likes it to be just the username so remove the rest

ubuntu

Cesar Bielich
  • 4,754
  • 9
  • 39
  • 81
0

If you use RSA key, and see string like this in your private key:

    -----BEGIN RSA PRIVATE KEY-----
***************************************

-----END RSA PRIVATE KEY-----

You need edit config file sshd on remote machine:

sudo vim /etc/ssh/sshd_config

add in this file stoke:

HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
KoKon
  • 1
  • 1
0

I have the same problem,I am on windows, the solution:

  • open the openssh debug model, no can see the error detail, detail click
    • Stop the sshd service
    • Type 'sshd -d' in PowerShell
  • no if you connect again ,you can see the error detail, my error is
    userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
    
  • we can add PubkeyAcceptedKeyTypes=+ssh-rsa in server sshd_config file, detail click
  • now test success, if still has error like Failed to connect SFTP channel and debug is
    debug1: subsystem: cannot stat sftp-server.exe: No such file or directory
    
    this because the openssh no in windows system path. detail click
vishun
  • 79
  • 6