title: jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection Message [Auth fail]
body: <p>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.</p>
  <p>My setup:</p>
  <p>Jenkins server is an AWS EC2 Linux AMI server.
  Web Server is also an AWS EC2 LInux AMI server.</p>
  <p>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 <a href="https://plugins.jenkins.io/publish-over-ssh/" rel="nofollow noreferrer">https://plugins.jenkins.io/publish-over-ssh/</a>.</p>
  <p>However, when try to 'Test Configuration', I get the below error,</p>
  <p>Failed to connect or change directory</p>
  <p><em>jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [WebServer]. Message [Auth fail]]</em></p>
  <p>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.</p>
  <p>The below link suggests many different solutions, but none is working in my case.</p>
  <p><a href="https://stackoverflow.com/questions/22345483/jenkins-publish-over-ssh-authentification-failed-with-private-key">Jenkins Publish over ssh authentification failed with private key</a></p>
  <p>I was looking at the below link which describes the same problem,</p>
  <p><a href="https://stackoverflow.com/questions/39926058/jenkins-publish-over-ssh-failed-to-change-to-remote-directory">Jenkins publish over SSH failed to change to remote directory</a></p>
  <p>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.</p>
  <p>Screenshot of my settings in Jenkins:</p>
  <p><a href="https://i.stack.imgur.com/PI3Y3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PI3Y3.png" alt="enter image description here" /></a>
  I would appreciate if anyone can point me to the right direction or highlight any mistake I'm doing with my configuration.</p>