2

I am learning to use Jenkins to deploy a .Net 5.0 application on an AWS EC2 server. This is the first time I am using Linux server and Jenkins for .Net (I'm am a life long Windows guy), and I am facing an error while trying to publish my artifacts over SSH to Web Server.

My setup:

Jenkins server is an AWS EC2 Linux AMI server. Web Server is also an AWS EC2 LInux AMI server.

My Jenkins is correctly installed and working. I am able to build and run unit test cases without any issues. For Deploy, I am using 'Publish Over SSH' plugin, and I have followed all steps to configure this plugin as mentioned here https://plugins.jenkins.io/publish-over-ssh/.

However, when try to 'Test Configuration', I get the below error,

Failed to connect or change directory

jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [WebServer]. Message [Auth fail]]

I did a ping test from Jenkins server to Web Server, and it is a success. I'm using the .pem key in the 'Key' section of 'Publish over SSH'. This key is the same key I use to SSH into the web server.

The below link suggests many different solutions, but none is working in my case.

Jenkins Publish over ssh authentification failed with private key

I was looking at the below link which describes the same problem,

Jenkins publish over SSH failed to change to remote directory

However in my case I have kept 'Remote Directory' as empty. I don't know if I have to specify any directory here. Anyways, I tried creating a new directory under the home directory of user ec2-user as '/home/ec2-user/publish' and then used this path as Remote Directory, but it still didn't work.

Screenshot of my settings in Jenkins:

enter image description here I would appreciate if anyone can point me to the right direction or highlight any mistake I'm doing with my configuration.

stack underflow
  • 197
  • 2
  • 5
  • 18

2 Answers2

3

In my case following steps solved the problem.
Solution is based on Ubuntu 22.04
add two line in /etc/ssh/sshd_config

PubkeyAuthentication yes
PubkeyAcceptedKeyTypes +ssh-rsa

restart sshd service

sudo service sshd restart
Karoid
  • 750
  • 4
  • 17
0

you might consider the following:

a. From the screenshot you’ve provided, it seems that you have checked the Use password authentication, or use different key option which will require you to add your key and password (inputs from these fields will be used in connecting to your server via SSH connection). If you use the same SSH key and passphrase/password on all of your servers, you can uncheck/untick that box and just use the config you have specified above.

b. You might also check if port 22 of your web server allows inbound traffic from the security group where your Jenkins server/EC2 instance is running. See reference here.

c. Also, make sure that the remote directory you have specified is existing otherwise the connection may fail.

Here's the sample config enter image description here

Romar C.
  • 51
  • 2