I'm trying to set up a GitHub Actions workflow to deploy my .NET application to a remote server using SSH. However, I'm encountering an authentication error during the SSH handshake. Here's the error message I'm getting:
2024/06/19 02:51:53 ssh: handshake failed: ssh: unable to authenticate, attempted methods [publickey none], no supported methods remain
GitHub Actions Workflow:
name: Deploy to Hetzner
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet publish -c Release -o out
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
mkdir -p /var/www/meal_prep
rm -rf /var/www/meal_prep/*
cp -r out/* /var/www/meal_prep
sudo -S systemctl restart meal_prep.service
Generated SSH keys on my local machine using:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Copied the private key content (~/.ssh/id_rsa) to a GitHub repository secret named SSH_PRIVATE_KEY.
Copied the public key content (~/.ssh/id_rsa.pub) from local machine and added it to the ~/.ssh/authorized_keys file on the remote server.
nano ~/.ssh/authorized_keys and replaced the public key.
I can SSH into the remote server from my local machine without a password.
Ensured that the SSH daemon on the remote server allows the ssh-rsa algorithm by adding:
CASignatureAlgorithms +ssh-rsa
to the /etc/ssh/sshd_config file.
Despite these steps, the GitHub Actions workflow still fails with the authentication error. I've double-checked the secrets and configuration files, but nothing seems to work. Searched and tried different answer from the blogs/so answer, nothing seems to be working.
What could be causing the SSH authentication failure in my GitHub Actions workflow, and how can I resolve it? Are there any additional configurations or steps that I might be missing?
It took me atleast 24 hour to debug this and turned out that the proble was with the version of: appleboy/ssh-action@master
.
I updated to the latest version the problem seems solved.