A Forgejo Action for executing commands and scripts on a remote host via SSH in CI/CD pipelines
| action.yml | Add action | |
| entrypoint.sh | Add output handling | |
| LICENSE | Initial commit | |
| README.md | Update readme | |
SSH Forgejo Action
A Forgejo Action to execute commands or scripts on a remote server via SSH.
Features
- Securely connects to a remote server using SSH.
- Executes inline commands or an external script.
- Supports custom SSH ports.
- Uses environment variables for sensitive credentials.
Usage
Inputs
| Name | Required | Description |
|---|---|---|
host |
✅ | The hostname or IP address of the remote server. |
username |
✅ | The SSH username. |
key |
✅ | The private SSH key for authentication. |
port |
❌ | The SSH port (default is 22). |
script |
✅ | Inline commands or the path to a script to execute. |
Example Workflow
name:Execute Commands or Script on Remote Hoston:push:branches:- mainjobs:execute-commands:runs-on:ubuntu-lateststeps:- name:Checkout repositoryuses:actions/checkout@v2- name:Execute Inline Commands on Remote Hostuses:https://codeberg.org/latzo/ssh-action@v1with:host:${{ secrets.HOST }}username:${{ secrets.USERNAME }}key:${{ secrets.KEY }}port:${{ secrets.PORT }}script:| whoami
ls -al- name:Execute Script on Remote Hostuses:https://codeberg.org/latzo/ssh-action@v1with:host:${{ secrets.HOST }}username:${{ secrets.USERNAME }}key:${{ secrets.KEY }}port:${{ secrets.PORT }}script:/path/to/script.shHow It Works
- The action connects to the remote server using SSH.
- If the
scriptinput contains inline commands, they are executed directly. - If
scriptis a file path, the script is copied to the remote server and executed. - The SSH key is securely passed as an environment variable and deleted after execution.
Security Considerations
- Use GitHub Secrets: Always store sensitive information (such as
key,host,username) as GitHub Secrets. - Restrict SSH Access: Ensure that the SSH key used for authentication has the necessary but minimal permissions.
License
This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE