Question

Cannot rsync to my droplet from githubaction

I have a project that is successfully built but i cannot get github action to rsync to the droplet web folder. I have entered the private key (with the begin and end comment that surround the hash of the private key), i have enabled with ufw the SSH at port 22, somehow i get this error message: Run rsync -avz ./ @:/var/www/html

  rsync -avz ./  ***@***:/var/www/html

  shell: /usr/bin/bash -e {0}

Host key verification failed.

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]

Error: Process completed with exit code 255.

Here is the github action: name: Build and Deploy

on: push: branches: [ main ] workflow_dispatch:

jobs: build: runs-on: ubuntu-latest

env:
  NODE_ENV: production
  COMPOSER_NO_DEV: 1

steps:
  - name: Checkout
    uses: actions/checkout@v4

  - name: Install Node packages
    run: npm install

  - name: Build assets
    run: npm run build

  - name: Setup PHP
    uses: "shivammathur/setup-php@v2"
    with:
      php-version: 8.3

  - name: Install Composer packages
    uses: ramsey/composer-install@v3

  - name: Upload artifact
    uses: actions/upload-artifact@v4
    with:
      name: AuthenticatorProWebsite
      path: |
        application
        vendor
        public

deploy: runs-on: ubuntu-latest needs: build

steps:
  - name: Download artifact
    uses: actions/download-artifact@v4
    with:
      name: AuthenticatorProWebsite

  - name: Prepare environment file
    run: |
      printf %s "${{ secrets.ENV_FILE }}" > .env

  - name: Deploy with rsync
    run: rsync -avz ./  ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/var/www/html

thank you in advance for your help


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 30, 2024

Hi there,

As far as I can tell, your workflow setup looks good. You’ve done well with the build process!

The error message shows there’s a problem with SSH key authentication so in general there are a few common things that you should start by checking:

  1. Before running rsync, add these steps to your workflow:

    - name: Install SSH Key
      uses: shimataro/ssh-key-action@v2
      with:
        key: ${{ secrets.SERVER_SSH_KEY }}
        known_hosts: ${{ secrets.KNOWN_HOSTS }}
    
    - name: Adding Known Hosts
      run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
    

    Make sure to add your private key as SERVER_SSH_KEY in your repository secrets.

  2. Change your rsync command like this:

    - name: Deploy with rsync
      run: |
        eval $(ssh-agent -s)
        ssh-add ~/.ssh/id_rsa
        rsync -avz -e "ssh -o StrictHostKeyChecking=no" ./ ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/var/www/html
    

    The -o StrictHostKeyChecking=no option helps avoid the host key verification.

  3. Check that DEPLOY_USER, DEPLOY_HOST, and SERVER_SSH_KEY are set correctly in your GitHub repository secrets.

  4. If you still have problems, add more details to your SSH connection for debugging:

    - name: Deploy with rsync (verbose)
      run: rsync -avz -e "ssh -vvv" ./ ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/var/www/html
    

    This will give you more information about the SSH connection process.

Try these suggestions and let me know the results. If you still have problems, feel free to share more details! Good luck with your deployment!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.