It looks like the issue you're encountering is due to the SSH private key being passphrase protected. When using SSH keys that are protected by a passphrase in automated scripts like GitHub Actions, you need to ensure that the passphrase is also provided, or use a key without a passphrase.
Here are the steps to resolve the issue:
-
Remove the passphrase from the existing SSH key (not recommended for production environments due to security concerns):
- You can remove the passphrase from the SSH key using the following command:
ssh-keygen -p -f ~/.ssh/id_ed25519 - When prompted for the passphrase, enter it and then press enter when asked for the new passphrase to remove it.
- You can remove the passphrase from the SSH key using the following command:
-
Create a new SSH key without a passphrase:
- This is a safer approach for production. Generate a new SSH key without a passphrase:
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_ci -N "" - Replace
"[email protected]"with your actual email address. The-N ""option sets an empty passphrase directly.
- This is a safer approach for production. Generate a new SSH key without a passphrase:
-
Update the GitHub Secrets:
- Update the
SSHKEYsecret in your GitHub repository to use the new SSH key (either the passphrase-removed key or the new key without a passphrase).
- Update the
-
Update the server's authorized keys:
- Make sure that the public key corresponding to the modified or new private key is added to the
~/.ssh/authorized_keyson the server where you are deploying.
- Make sure that the public key corresponding to the modified or new private key is added to the
-
Modify the GitHub Actions workflow:
- Ensure that your workflow is using the correct secrets and that the SSH action setup is correct. Here is a revised version of your workflow step for deploying to the server:
- name: Deploy to Server uses: appleboy/ssh-action@master with: host: ${{ secrets.HOST }} username: ${{ secrets.USERNAME }} port: ${{ secrets.PORT }} key: ${{ secrets.SSHKEY }} script: | cd /var/www/example.com && ./.scripts/deploy.sh
- Ensure that your workflow is using the correct secrets and that the SSH action setup is correct. Here is a revised version of your workflow step for deploying to the server:
By following these steps, you should be able to resolve the SSH authentication issue in your GitHub Actions workflow. Remember, handling SSH keys securely is crucial, especially in production environments. Avoid using keys without passphrases unless absolutely necessary and ensure secure handling of all secrets.