1

I have quite a frustrating situation. I am trying to use Deployer to deploy my laravel projects with GitHub Actions and it just keeps kicking me back and giving me a Permission denied (publickey,keyboard-interactive) error.

On the server I want to deploy to (Ubuntu) ... I created a user and then ran the following to generate an SSH key

ssh-keygen -t ed25519 -C "myusername@myexampledomain.com"

I then ran the following to create the known_hosts

ssh-keyscan -t ed25519 -p 22342 my.public.server.ip >> known_hosts

I went into my github repo, then to Settings -> Secrets and Variables -> Actions and then created 2 PRIVATE_KEY and KNOWN_HOSTS with the values from the above commands.

My github actions file looks like so;

name: Building

on: [push, pull_request]

jobs:
  build:
    name: Deploy to production
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.1
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
          coverage: none

      - name: Deploy
        uses: deployphp/action@master
        with:
          dep: deploy production -f ./path/to/my/deploy.php
          private-key: ${{ secrets.PRIVATE_KEY }}
          known-hosts: ${{ secrets.KNOWN_HOSTS }}
          deployer-version: "7.1.4"

and finally my deploy.php is as follows;

<?php

namespace Deployer;

require 'recipe/laravel.php';

set('application', 'my_api');
set('repository', 'git@github.com:organisation/my-repo.git');
set('git_tty', false);
set('ssh_multiplexing', false);

// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);

set('allow_anonymous_stats', false);

host('production')
    ->set('hostname', 'my.public.server.ip')
    ->set('port', '22342')
    ->set('remote_user', 'myusername')
    ->set('branch', 'main')
    ->set('deploy_path', '/var/www/api');

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');

Pretty standard stuff from what I have read ... But it just doesnt seem to work ... When running the action it always gets stuck with the following error;

myusername@my.public.server.ip: Permission denied (publickey,keyboard-interactive)

Im going nuts as I have used this deploy.php before without github actions and its worked fine.

Please help

CodeSauce
  • 255
  • 3
  • 19
  • 39
  • Verify that the SSH key is not encrypted with a passphrase. If the SSH key is encrypted, then the ssh client will prompt for the passphrase, which will cause the deployment to fail – Wahyu Kristianto Feb 22 '23 at 10:39
  • @WahyuKristianto I did just press enter when the passphrase was asked, but weirdly its still asking for a password – CodeSauce Feb 22 '23 at 10:53

1 Answers1

1

but weirdly its still asking for a password

That means the public key way not added to the remote server ~myusername@myexampledomain.com/.ssh/authorized_keys.

On the server I want to deploy to (Ubuntu) ... I created a user and then ran the following to generate an SSH key

That would create a key pair at ~myusername@myexampledomain.com/.ssh, but would not update the authorized_keys file with the public key generated there.
You need to add said public key there in order for the GitHub Action (which has the private key as a secret) to be able to SSH connect to the server as myusername.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250