mirror of
https://github.com/appleboy/ssh-action.git
synced 2025-04-22 09:04:27 +00:00
Compare commits
No commits in common. "master" and "v1.1.0" have entirely different histories.
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,9 +1,10 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ""
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: appleboy
|
||||
|
||||
---
|
||||
|
||||
## Describe the bug
|
||||
@ -18,18 +19,19 @@ Please post your Yaml configuration file along with the output results.
|
||||
name: remote ssh command
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.2.2
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
```
|
||||
|
||||
## Related environment
|
||||
|
251
.github/workflows/main.yml
vendored
251
.github/workflows/main.yml
vendored
@ -37,19 +37,7 @@ jobs:
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
||||
|
||||
- name: ssh commands from a file
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
script_path: testdata/test.sh
|
||||
script: whoami
|
||||
|
||||
check-ssh-key:
|
||||
runs-on: ubuntu-latest
|
||||
@ -123,6 +111,22 @@ jobs:
|
||||
port: 2222
|
||||
script: whoami
|
||||
|
||||
- name: stop script if command error
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
key: password
|
||||
port: 2222
|
||||
script_stop: true
|
||||
sync: true
|
||||
debug: true
|
||||
script: |
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
|
||||
support-key-passphrase:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -199,6 +203,7 @@ jobs:
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
port: 2222
|
||||
passphrase: 1234
|
||||
script_stop: true
|
||||
script: |
|
||||
ls \
|
||||
-lah
|
||||
@ -275,6 +280,7 @@ jobs:
|
||||
username: linuxserver.io
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
passphrase: 1234
|
||||
script_stop: true
|
||||
script: |
|
||||
whoami
|
||||
|
||||
@ -470,6 +476,7 @@ jobs:
|
||||
username: linuxserver.io
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
port: 2222
|
||||
script_stop: true
|
||||
request_pty: true
|
||||
command_timeout: 30s
|
||||
script: |
|
||||
@ -504,221 +511,3 @@ jobs:
|
||||
command_timeout: 30s
|
||||
script: |
|
||||
whoami
|
||||
|
||||
testing07:
|
||||
name: some special character
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set Environment Variables
|
||||
run: |
|
||||
PASS='3HUS$?8kLu)}'
|
||||
printf "PASS=${PASS}" >> $GITHUB_ENV
|
||||
|
||||
- name: create new ssh server
|
||||
run: |
|
||||
docker run -d \
|
||||
--name=openssh-server \
|
||||
--hostname=openssh-server \
|
||||
-p 2222:2222 \
|
||||
-e SUDO_ACCESS=false \
|
||||
-e PASSWORD_ACCESS=true \
|
||||
-e USER_PASSWORD='${{ env.PASS }}' \
|
||||
-e USER_NAME=linuxserver.io \
|
||||
--restart unless-stopped \
|
||||
lscr.io/linuxserver/openssh-server:latest
|
||||
docker exec openssh-server sh -c "hostname -i" > ip.txt
|
||||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
|
||||
cat ip.txt >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
echo "======= container ip address ========="
|
||||
cat ip.txt
|
||||
echo "======================================"
|
||||
sleep 2
|
||||
|
||||
- name: ssh by username and password
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: ${{ env.PASS }}
|
||||
port: 2222
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
||||
|
||||
testing-capturing-output:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: create new ssh server
|
||||
run: |
|
||||
docker run -d \
|
||||
--name=openssh-server \
|
||||
--hostname=openssh-server \
|
||||
-p 2222:2222 \
|
||||
-e SUDO_ACCESS=false \
|
||||
-e PASSWORD_ACCESS=true \
|
||||
-e USER_PASSWORD=password \
|
||||
-e USER_NAME=linuxserver.io \
|
||||
--restart unless-stopped \
|
||||
lscr.io/linuxserver/openssh-server:latest
|
||||
docker exec openssh-server sh -c "hostname -i" > ip.txt
|
||||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
|
||||
cat ip.txt >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
echo "======= container ip address ========="
|
||||
cat ip.txt
|
||||
echo "======================================"
|
||||
sleep 2
|
||||
|
||||
- id: stdout
|
||||
name: ssh command with stdout
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
capture_stdout: true
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
||||
|
||||
- name: check stdout
|
||||
run: |
|
||||
echo "stdout: ${{ steps.stdout.outputs.stdout }}"
|
||||
|
||||
testing-script-stop:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: create new ssh server
|
||||
run: |
|
||||
docker run -d \
|
||||
--name=openssh-server \
|
||||
--hostname=openssh-server \
|
||||
-p 2222:2222 \
|
||||
-e SUDO_ACCESS=false \
|
||||
-e PASSWORD_ACCESS=true \
|
||||
-e USER_PASSWORD=password \
|
||||
-e USER_NAME=linuxserver.io \
|
||||
--restart unless-stopped \
|
||||
lscr.io/linuxserver/openssh-server:latest
|
||||
docker exec openssh-server sh -c "hostname -i" > ip.txt
|
||||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
|
||||
cat ip.txt >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
echo "======= container ip address ========="
|
||||
cat ip.txt
|
||||
echo "======================================"
|
||||
sleep 2
|
||||
|
||||
- id: stdout01
|
||||
name: ssh command with stdout 01
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
capture_stdout: true
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
echo "TMP TESTING IF"
|
||||
if [[ "2" == "1" ]]; then
|
||||
echo "True"
|
||||
else
|
||||
echo "False"
|
||||
fi
|
||||
|
||||
- name: check stdout 01
|
||||
run: |
|
||||
echo "stdout: ${{ steps.stdout01.outputs.stdout }}"
|
||||
if echo "${{ steps.stdout01.outputs.stdout }}" | grep -q "True"; then
|
||||
echo "Output contains 'True'"
|
||||
exit 1
|
||||
fi
|
||||
if echo "${{ steps.stdout01.outputs.stdout }}" | grep -q "False"; then
|
||||
echo "Output contains 'False'"
|
||||
fi
|
||||
|
||||
- id: stdout02
|
||||
name: ssh command with stdout 01
|
||||
uses: ./
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
capture_stdout: true
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
echo "TMP TESTING IF"
|
||||
if [[ "1" == "1" ]]; then
|
||||
echo "True"
|
||||
else
|
||||
echo "False"
|
||||
fi
|
||||
|
||||
- name: check stdout 02
|
||||
run: |
|
||||
echo "stdout: ${{ steps.stdout02.outputs.stdout }}"
|
||||
if echo "${{ steps.stdout02.outputs.stdout }}" | grep -q "False"; then
|
||||
echo "Output contains 'False'"
|
||||
exit 1
|
||||
fi
|
||||
if echo "${{ steps.stdout02.outputs.stdout }}" | grep -q "True"; then
|
||||
echo "Output contains 'True'"
|
||||
fi
|
||||
|
||||
testing-script-error:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: create new ssh server
|
||||
run: |
|
||||
docker run -d \
|
||||
--name=openssh-server \
|
||||
--hostname=openssh-server \
|
||||
-p 2222:2222 \
|
||||
-e SUDO_ACCESS=false \
|
||||
-e PASSWORD_ACCESS=true \
|
||||
-e USER_PASSWORD=password \
|
||||
-e USER_NAME=linuxserver.io \
|
||||
--restart unless-stopped \
|
||||
lscr.io/linuxserver/openssh-server:latest
|
||||
docker exec openssh-server sh -c "hostname -i" > ip.txt
|
||||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
|
||||
cat ip.txt >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
echo "======= container ip address ========="
|
||||
cat ip.txt
|
||||
echo "======================================"
|
||||
sleep 2
|
||||
|
||||
- name: test script error
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
capture_stdout: true
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
ls /nonexistent
|
||||
|
63
.github/workflows/stable.yml
vendored
63
.github/workflows/stable.yml
vendored
@ -31,25 +31,13 @@ jobs:
|
||||
sleep 2
|
||||
|
||||
- name: ssh by username and password
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
||||
|
||||
- name: ssh commands from a file
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
port: 2222
|
||||
script_path: testdata/test.sh
|
||||
script: whoami
|
||||
|
||||
check-ssh-key:
|
||||
runs-on: ubuntu-latest
|
||||
@ -95,7 +83,7 @@ jobs:
|
||||
sleep 2
|
||||
|
||||
- name: ssh by private key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -104,7 +92,7 @@ jobs:
|
||||
script: whoami
|
||||
|
||||
- name: wrong password but correct key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -114,7 +102,7 @@ jobs:
|
||||
script: whoami
|
||||
|
||||
- name: correct password but wrong key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -123,6 +111,22 @@ jobs:
|
||||
port: 2222
|
||||
script: whoami
|
||||
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
password: password
|
||||
key: password
|
||||
port: 2222
|
||||
script_stop: true
|
||||
sync: true
|
||||
debug: true
|
||||
script: |
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
|
||||
support-key-passphrase:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -167,7 +171,7 @@ jobs:
|
||||
sleep 2
|
||||
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -179,7 +183,7 @@ jobs:
|
||||
ls -al
|
||||
|
||||
- name: missing ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
@ -192,13 +196,14 @@ jobs:
|
||||
|
||||
# https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
|
||||
- name: Multiline SSH commands interpreted as single lines
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
port: 2222
|
||||
passphrase: 1234
|
||||
script_stop: true
|
||||
script: |
|
||||
ls \
|
||||
-lah
|
||||
@ -269,12 +274,13 @@ jobs:
|
||||
|
||||
# https://github.com/appleboy/ssh-action/issues/85
|
||||
- name: Deployment to multiple hosts with different ports
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: "${{ env.REMOTE_HOST_01 }}:2222,${{ env.REMOTE_HOST_02 }}:2222"
|
||||
username: linuxserver.io
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
passphrase: 1234
|
||||
script_stop: true
|
||||
script: |
|
||||
whoami
|
||||
|
||||
@ -322,7 +328,7 @@ jobs:
|
||||
sleep 2
|
||||
|
||||
- name: testing id_ed25519 key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -375,7 +381,7 @@ jobs:
|
||||
sleep 2
|
||||
|
||||
- name: testing id_ed25519 key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
@ -386,7 +392,7 @@ jobs:
|
||||
ls -al
|
||||
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
env:
|
||||
FOO: "BAR"
|
||||
with:
|
||||
@ -400,7 +406,7 @@ jobs:
|
||||
echo "I am $BAR, thanks"
|
||||
|
||||
- name: pass multiple environment
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
env:
|
||||
FOO: "BAR"
|
||||
BAR: "FOO"
|
||||
@ -419,7 +425,7 @@ jobs:
|
||||
echo "port: $PORT"
|
||||
|
||||
- name: custom envs format
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
env:
|
||||
FOO: "BAR"
|
||||
AAA: "BBB"
|
||||
@ -437,7 +443,7 @@ jobs:
|
||||
echo "I am $TEST_AAA, thanks"
|
||||
|
||||
- name: pass all ENV variables to script
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
env:
|
||||
INPUT_FOO: "BAR"
|
||||
INPUT_AAA: "BBB"
|
||||
@ -454,12 +460,13 @@ jobs:
|
||||
echo "$GITHUB_REF"
|
||||
|
||||
- name: switch to root user
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
key: ${{ env.PRIVATE_KEY }}
|
||||
port: 2222
|
||||
script_stop: true
|
||||
request_pty: true
|
||||
command_timeout: 30s
|
||||
script: |
|
||||
|
@ -24,5 +24,5 @@ changelog:
|
||||
order: 4
|
||||
- title: "Documentation updates"
|
||||
regexp: ^.*?docs?(\(.+\))??!?:.+$
|
||||
order: 5
|
||||
order: 4
|
||||
- title: Others
|
||||
|
155
README.md
155
README.md
@ -1,30 +1,33 @@
|
||||
# 🚀 SSH for GitHub Actions
|
||||
|
||||
English | [繁體中文](./README.zh-tw.md) | [简体中文](./README.zh-cn.md)
|
||||
[繁體中文](./README.zh-tw.md)
|
||||
[简体中文](./README.zh-cn.md)
|
||||
|
||||
A [GitHub Action](https://github.com/features/actions) for executing remote SSH commands.
|
||||
[GitHub Action](https://github.com/features/actions) for executing remote ssh commands.
|
||||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
|
||||
This project is built with [Golang](https://go.dev) and [drone-ssh](https://github.com/appleboy/drone-ssh). 🚀
|
||||
**Important**: Only support **Linux** [docker](https://www.docker.com/) container.
|
||||
|
||||
This thing is built using [Golang](https://go.dev) and [drone-ssh](https://github.com/appleboy/drone-ssh). 🚀
|
||||
|
||||
## Input variables
|
||||
|
||||
Refer to [action.yml](./action.yml) for more detailed information.
|
||||
See [action.yml](./action.yml) for more detailed information.
|
||||
|
||||
| Input Parameter | Description | Default Value |
|
||||
| ------------------------- | ---------------------------------------------------------------------------------------- | ------------- |
|
||||
|---------------------------|------------------------------------------------------------------------------------------|---------------|
|
||||
| host | SSH host address | |
|
||||
| port | SSH port number | 22 |
|
||||
| passphrase | SSH key passphrase | |
|
||||
| username | SSH username | |
|
||||
| password | SSH password | |
|
||||
| protocol | SSH protocol version (tcp, tcp4, tcp6) | tcp |
|
||||
| sync | Enable synchronous execution if multiple hosts are specified | false |
|
||||
| sync | Enable synchronous execution if multiple hosts | false |
|
||||
| use_insecure_cipher | Include more ciphers with use_insecure_cipher | false |
|
||||
| cipher | Allowed cipher algorithms. If unspecified, sensible defaults are used | |
|
||||
| cipher | Allowed cipher algorithms. If unspecified, a sensible default | |
|
||||
| timeout | Timeout duration for SSH to host | 30s |
|
||||
| command_timeout | Timeout duration for SSH command | 10m |
|
||||
| key | Content of SSH private key. e.g., raw content of ~/.ssh/id_rsa | |
|
||||
@ -32,7 +35,6 @@ Refer to [action.yml](./action.yml) for more detailed information.
|
||||
| fingerprint | SHA256 fingerprint of the host public key | |
|
||||
| proxy_host | SSH proxy host | |
|
||||
| proxy_port | SSH proxy port | 22 |
|
||||
| proxy_protocol | SSH proxy protocol version (tcp, tcp4, tcp6) | tcp |
|
||||
| proxy_username | SSH proxy username | |
|
||||
| proxy_password | SSH proxy password | |
|
||||
| proxy_passphrase | SSH proxy key passphrase | |
|
||||
@ -43,37 +45,34 @@ Refer to [action.yml](./action.yml) for more detailed information.
|
||||
| proxy_cipher | Allowed cipher algorithms for the proxy | |
|
||||
| proxy_use_insecure_cipher | Include more ciphers with use_insecure_cipher for the proxy | false |
|
||||
| script | Execute commands | |
|
||||
| script_path | Execute commands from a file | |
|
||||
| envs | Pass environment variables to the shell script | |
|
||||
| script_stop | Stop script after first failure | false |
|
||||
| envs | Pass environment variables to shell script | |
|
||||
| envs_format | Flexible configuration of environment value transfer | |
|
||||
| debug | Enable debug mode | false |
|
||||
| allenvs | Pass the environment variables with prefix value of `GITHUB_` and `INPUT_` to the script | false |
|
||||
| allenvs | pass the environment variables with prefix value of `GITHUB_` and `INPUT_` to the script | false |
|
||||
| request_pty | Request a pseudo-terminal from the server | false |
|
||||
| curl_insecure | Allow curl to connect to SSL sites without certificates | false |
|
||||
| version | drone-ssh binary version. If not specified, the latest version will be used. | |
|
||||
|
||||
**Note:** Users can add `set -e` in their shell script to achieve similar functionality to the removed `script_stop` option.
|
||||
|
||||
## Usage
|
||||
|
||||
Executing remote SSH commands.
|
||||
Executing remote ssh commands.
|
||||
|
||||
```yaml
|
||||
name: remote ssh command
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: linuxserver.io
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
```
|
||||
|
||||
output:
|
||||
@ -82,17 +81,17 @@ output:
|
||||
======CMD======
|
||||
whoami
|
||||
======END======
|
||||
linuxserver.io
|
||||
===============================================
|
||||
✅ Successfully executed commands to all hosts.
|
||||
===============================================
|
||||
out: ***
|
||||
==============================================
|
||||
✅ Successfully executed commands to all host.
|
||||
==============================================
|
||||
```
|
||||
|
||||
### Setting up a SSH Key
|
||||
|
||||
Follow the steps below to create and use SSH Keys.
|
||||
It is best practice to create SSH Keys on your local machine, not on a remote machine.
|
||||
Log in with the username specified in GitHub Secrets and generate an RSA Key-Pair:
|
||||
Make sure to follow the below steps while creating SSH Keys and using them.
|
||||
The best practice is create the SSH Keys on local machine not remote machine.
|
||||
Login with username specified in Github Secrets. Generate a RSA Key-Pair:
|
||||
|
||||
### Generate rsa key
|
||||
|
||||
@ -106,7 +105,7 @@ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
```
|
||||
|
||||
Add the newly generated key to the Authorized keys. Read more about authorized keys [here](https://www.ssh.com/ssh/authorized_keys/).
|
||||
Add newly generated key into Authorized keys. Read more about authorized keys [here](https://www.ssh.com/ssh/authorized_keys/).
|
||||
|
||||
### Add rsa key into Authorized keys
|
||||
|
||||
@ -120,18 +119,18 @@ cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
|
||||
cat .ssh/id_ed25519.pub | ssh b@B 'cat >> .ssh/authorized_keys'
|
||||
```
|
||||
|
||||
Copy the Private Key content and paste it into GitHub Secrets.
|
||||
Copy Private Key content and paste in Github Secrets.
|
||||
|
||||
### Copy rsa Private key
|
||||
|
||||
Before copying the private key, install the `clip` command as shown below:
|
||||
Before copying the private key, install `clip` command as shown below:
|
||||
|
||||
```bash
|
||||
# Ubuntu
|
||||
sudo apt-get install xclip
|
||||
```
|
||||
|
||||
Copy the private key:
|
||||
copy the private key:
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
@ -140,8 +139,6 @@ pbcopy < ~/.ssh/id_rsa
|
||||
xclip < ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
Starting from and including the comment section `-----BEGIN OPENSSH PRIVATE KEY-----` and ending at and including the comment section `-----END OPENSSH PRIVATE KEY-----`, copy the private key and paste it into GitHub Secrets.
|
||||
|
||||
### Copy ed25519 Private key
|
||||
|
||||
```bash
|
||||
@ -151,13 +148,13 @@ pbcopy < ~/.ssh/id_ed25519
|
||||
xclip < ~/.ssh/id_ed25519
|
||||
```
|
||||
|
||||
See detailed information about [SSH login without a password](http://www.linuxproblem.org/art_9.html).
|
||||
See the detail information about [SSH login without password](http://www.linuxproblem.org/art_9.html).
|
||||
|
||||
**Note**: Depending on your version of SSH, you might also need to make the following changes:
|
||||
**A note** from one of our readers: Depending on your version of SSH you might also have to do the following changes:
|
||||
|
||||
- Put the public key in `.ssh/authorized_keys2`
|
||||
- Change the permissions of `.ssh` to 700
|
||||
- Change the permissions of `.ssh/authorized_keys2` to 640
|
||||
* Put the public key in `.ssh/authorized_keys2`
|
||||
* Change the permissions of `.ssh` to 700
|
||||
* Change the permissions of `.ssh/authorized_keys2` to 640
|
||||
|
||||
### If you are using OpenSSH
|
||||
|
||||
@ -167,13 +164,13 @@ If you are currently using OpenSSH and are getting the following error:
|
||||
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey]
|
||||
```
|
||||
|
||||
Ensure that your chosen key algorithm is supported. On Ubuntu 20.04 or later, you must explicitly allow the use of the ssh-rsa algorithm. Add the following line to your OpenSSH daemon file (either `/etc/ssh/sshd_config` or a drop-in file under `/etc/ssh/sshd_config.d/`):
|
||||
Make sure that your key algorithm of choice is supported. On Ubuntu 20.04 or later you must explicitly allow the use of the ssh-rsa algorithm. Add the following line to your OpenSSH daemon file (which is either `/etc/ssh/sshd_config` or a drop-in file under `/etc/ssh/sshd_config.d/`):
|
||||
|
||||
```bash
|
||||
CASignatureAlgorithms +ssh-rsa
|
||||
```
|
||||
|
||||
Alternatively, `ed25519` keys are accepted by default in OpenSSH. You can use this instead of rsa if needed:
|
||||
Alternatively, `ed25519` keys are accepted by default in OpenSSH. You could use this instead of rsa if needed:
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
@ -185,7 +182,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -198,7 +195,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -211,7 +208,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -224,24 +221,11 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||

|
||||
|
||||
#### Commands from a file
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### Multiple Hosts
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
@ -259,7 +243,7 @@ The default value of `port` is `22`.
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com:1234,bar.com:5678"
|
||||
@ -274,7 +258,7 @@ The default value of `port` is `22`.
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: "foo.com,bar.com"
|
||||
+ sync: true
|
||||
@ -290,7 +274,7 @@ The default value of `port` is `22`.
|
||||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
+ env:
|
||||
+ FOO: "BAR"
|
||||
+ BAR: "FOO"
|
||||
@ -309,6 +293,37 @@ The default value of `port` is `22`.
|
||||
|
||||
_Inside `env` object, you need to pass every environment variable as a string, passing `Integer` data type or any other may output unexpected results._
|
||||
|
||||
#### Stop script after first failure
|
||||
|
||||
> ex: missing `abc` folder
|
||||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
+ script_stop: true
|
||||
script: |
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
```
|
||||
|
||||
output:
|
||||
|
||||
```sh
|
||||
======CMD======
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
|
||||
======END======
|
||||
2019/11/21 01:16:21 Process exited with status 1
|
||||
err: mkdir: cannot create directory ‘abc/def’: No such file or directory
|
||||
##[error]Docker run failed with exit code 1
|
||||
```
|
||||
|
||||
#### How to connect remote server using `ProxyCommand`?
|
||||
|
||||
```bash
|
||||
@ -337,7 +352,7 @@ Host FooServer
|
||||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -360,7 +375,7 @@ It is not uncommon for files to leak from backups or decommissioned hardware, an
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -386,7 +401,7 @@ Now you can adjust you config:
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -404,7 +419,7 @@ Now you can adjust you config:
|
||||
|
||||
See the [issue comment](https://github.com/appleboy/ssh-action/issues/31#issuecomment-1006565847) about interactive vs non interactive shell. Thanks @kocyigityunus for the solution.
|
||||
|
||||
If you are running a command in a non-interactive shell, like ssh-action, on many Linux distros,
|
||||
Basically, if you are running a command in a non interactive shell, like ssh-action, on many linux distros,
|
||||
|
||||
`/etc/bash.bashrc` file has a specific command that returns only, so some of the files didn't run and some specific commands doesn't add to path,
|
||||
|
||||
@ -419,7 +434,7 @@ If you are running a command in a non-interactive shell, like ssh-action, on man
|
||||
[ -z "$PS1" ] && return`
|
||||
```
|
||||
|
||||
comment out the line that returns early, and everything should work fine. Alternatively, you can use the real paths of the commands you want to use.
|
||||
just comment out the line that returns early and everything should work fine, or you can use the real paths of the commands that you would like to use.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
264
README.zh-cn.md
264
README.zh-cn.md
@ -1,109 +1,98 @@
|
||||
# 🚀 用于 GitHub Actions 的 SSH
|
||||
|
||||
[English](./README.md) | [繁體中文](./README.zh-tw.md) | 简体中文
|
||||
|
||||
一个用于执行远程 SSH 命令的 [GitHub Action](https://github.com/features/actions)。
|
||||
[GitHub Action](https://github.com/features/actions) 用于执行远程 SSH 命令。
|
||||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
|
||||
该项目使用 [Golang](https://go.dev) 和 [drone-ssh](https://github.com/appleboy/drone-ssh) 构建。🚀
|
||||
**注意**: 只支持在 **Linux** [docker](https://www.docker.com/) 容器上执行。
|
||||
|
||||
## 输入变量
|
||||
|
||||
有关更详细的信息,请参阅 [action.yml](./action.yml)。
|
||||
更详细的信息,请参考 [action.yml](./action.yml)。
|
||||
|
||||
| 输入参数 | 描述 | 默认值 |
|
||||
| ------------------------- | ----------------------------------------------------- | ------ |
|
||||
| host | SSH 主机地址 | |
|
||||
| port | SSH 端口号 | 22 |
|
||||
| passphrase | SSH 密钥密码短语 | |
|
||||
| username | SSH 用户名 | |
|
||||
| password | SSH 密码 | |
|
||||
| protocol | SSH 协议版本(tcp, tcp4, tcp6) | tcp |
|
||||
| sync | 如果指定了多个主机,则启用同步执行 | false |
|
||||
| use_insecure_cipher | 使用不安全的密码算法 | false |
|
||||
| cipher | 允许的密码算法。如果未指定,则使用适当的默认值 | |
|
||||
| timeout | SSH 连接到主机的超时时间 | 30s |
|
||||
| command_timeout | SSH 命令的超时时间 | 10m |
|
||||
| key | SSH 私钥的内容,例如 ~/.ssh/id_rsa 的原始内容 | |
|
||||
| key_path | SSH 私钥的路径 | |
|
||||
| fingerprint | 主机公钥的 SHA256 指纹 | |
|
||||
| proxy_host | SSH 代理主机 | |
|
||||
| proxy_port | SSH 代理端口 | 22 |
|
||||
| proxy_protocol | SSH 代理协议版本(tcp, tcp4, tcp6) | tcp |
|
||||
| proxy_username | SSH 代理用户名 | |
|
||||
| proxy_password | SSH 代理密码 | |
|
||||
| proxy_passphrase | SSH 代理密钥密码短语 | |
|
||||
| proxy_timeout | SSH 连接到代理主机的超时时间 | 30s |
|
||||
| proxy_key | SSH 代理私钥的内容 | |
|
||||
| proxy_key_path | SSH 代理私钥的路径 | |
|
||||
| proxy_fingerprint | 代理主机公钥的 SHA256 指纹 | |
|
||||
| proxy_cipher | 代理允许的密码算法 | |
|
||||
| proxy_use_insecure_cipher | 使用不安全的密码算法 | false |
|
||||
| script | 执行命令 | |
|
||||
| script_path | 从文件执行命令 | |
|
||||
| envs | 传递环境变量到 shell 脚本 | |
|
||||
| envs_format | 环境变量传递的灵活配置 | |
|
||||
| debug | 启用调试模式 | false |
|
||||
| allenvs | 将带有 `GITHUB_` 和 `INPUT_` 前缀的环境变量传递给脚本 | false |
|
||||
| request_pty | 请求伪终端 | false |
|
||||
| curl_insecure | 在 curl 中使用不安全的证书验证 | false |
|
||||
| version | drone-ssh 版本号。若未指定,将使用最新版本。 | |
|
||||
* `host` - SSH 主机
|
||||
* `port` - SSH 连接端口,默认为 `22`
|
||||
* `username` - SSH 用户名称
|
||||
* `password` - SSH 密码
|
||||
* `passphrase` - 通常用于加密私钥的 passphrase
|
||||
* `sync` - 同步执行多个主机上的命令,默认为 false
|
||||
* `timeout` - SSH 连接到远程主机的超时时间,默认为 `30s`
|
||||
* `command_timeout` - SSH 命令超时时间,默认为 10m
|
||||
* `key` - SSH 私钥的内容,例如 ~/.ssh/id_rsa 的原始内容,请记得包含 BEGIN 和 END 行
|
||||
* `key_path` - SSH 私钥的路径
|
||||
* `fingerprint` - 主机公钥的 SHA256 指纹,默认为跳过验证
|
||||
* `script` - 执行命令
|
||||
* `script_stop` - 当出现第一个错误时停止执行命令
|
||||
* `envs` - 传递环境变量到 shell script
|
||||
* `debug` - 启用调试模式
|
||||
* `use_insecure_cipher` - 使用不安全的密码(ciphers)进行加密,详见 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `cipher` - 允许使用的密码(ciphers)算法。如果未指定,则使用适当的算法
|
||||
|
||||
**注意:** 用户可以在他们的 shell 脚本中添加 `set -e` 以实现类似于已删除的 `script_stop` 选项的功能。
|
||||
SSH 代理设置:
|
||||
|
||||
* `proxy_host` - 代理主机
|
||||
* `proxy_port` - 代理端口,默认为 `22`
|
||||
* `proxy_username` - 代理用户名
|
||||
* `proxy_password` - 代理密码
|
||||
* `proxy_passphrase` - 密码通常用于加密私有密钥
|
||||
* `proxy_timeout` - SSH 连接至代理主机的超时时间,默认为 `30s`
|
||||
* `proxy_key` - SSH 代理私有密钥内容
|
||||
* `proxy_key_path` - SSH 代理私有密钥路径
|
||||
* `proxy_fingerprint` - 代理主机公钥的 SHA256 指纹,默认为跳过验证
|
||||
* `proxy_use_insecure_cipher` - 使用不安全的加密方式,详见 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `proxy_cipher` - 允许的加密算法。如果未指定,则使用合理的算法
|
||||
|
||||
## 使用方法
|
||||
|
||||
执行远程 SSH 命令。
|
||||
执行远程 SSH 命令
|
||||
|
||||
```yaml
|
||||
name: remote ssh command
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: linuxserver.io
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
```
|
||||
|
||||
输出:
|
||||
画面输出
|
||||
|
||||
```sh
|
||||
======CMD======
|
||||
whoami
|
||||
======END======
|
||||
linuxserver.io
|
||||
===============================================
|
||||
✅ Successfully executed commands to all hosts.
|
||||
===============================================
|
||||
out: ***
|
||||
==============================================
|
||||
✅ Successfully executed commands to all host.
|
||||
==============================================
|
||||
```
|
||||
|
||||
### 设置 SSH 密钥
|
||||
|
||||
请按照以下步骤创建和使用 SSH 密钥。
|
||||
最佳做法是在本地机器上创建 SSH 密钥,而不是在远程机器上。
|
||||
使用 GitHub Secrets 中指定的用户名登录并生成 RSA 密钥对:
|
||||
请在创建 SSH 密钥并使用 SSH 密钥时遵循以下步骤。最佳做法是在本地机器上创建 SSH 密钥而不是远程机器上。请使用 Github Secrets 中指定的用户名登录。生成 RSA 密钥:
|
||||
|
||||
### 生成 RSA 密钥
|
||||
|
||||
```bash
|
||||
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
ssh-keygen -t rsa -b 4096 -C ”your_email@example.com“
|
||||
```
|
||||
|
||||
### 生成 ed25519 密钥
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
||||
```
|
||||
|
||||
将新生成的密钥添加到已授权的密钥中。详细了解已授权的密钥请点[此处](https://www.ssh.com/ssh/authorized_keys/)。
|
||||
@ -111,53 +100,36 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
### 将 RSA 密钥添加到已授权密钥中
|
||||
|
||||
```bash
|
||||
cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
|
||||
cat .ssh/id_rsa.pub | ssh b@B ’cat >> .ssh/authorized_keys‘
|
||||
```
|
||||
|
||||
### 将 ed25519 密钥添加到已授权密钥中
|
||||
|
||||
```bash
|
||||
cat .ssh/id_ed25519.pub | ssh b@B 'cat >> .ssh/authorized_keys'
|
||||
cat .ssh/id_ed25519.pub | ssh b@B ’cat >> .ssh/authorized_keys‘
|
||||
```
|
||||
|
||||
复制私钥内容,然后将其粘贴到 GitHub Secrets 中。
|
||||
复制私钥内容,然后将其粘贴到 Github Secrets 中。
|
||||
|
||||
### 复制 RSA 私钥内容
|
||||
|
||||
在复制私钥之前,按照以下步骤安装 `clip` 命令:
|
||||
### 复制 rsa 私钥内容
|
||||
|
||||
```bash
|
||||
# Ubuntu
|
||||
sudo apt-get install xclip
|
||||
clip < ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
复制私钥:
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
pbcopy < ~/.ssh/id_rsa
|
||||
# Ubuntu
|
||||
xclip < ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
从包含注释部分 `-----BEGIN OPENSSH PRIVATE KEY-----` 开始,到包含注释部分 `-----END OPENSSH PRIVATE KEY-----` 结束,复制私钥并将其粘贴到 GitHub Secrets 中。
|
||||
|
||||
### 复制 ed25519 私钥内容
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
pbcopy < ~/.ssh/id_ed25519
|
||||
# Ubuntu
|
||||
xclip < ~/.ssh/id_ed25519
|
||||
clip < ~/.ssh/id_ed25519
|
||||
```
|
||||
|
||||
有关无需密码登录 SSH 的详细信息,请[见该网站](http://www.linuxproblem.org/art_9.html)。
|
||||
|
||||
**注意**:根据您的 SSH 版本,您可能还需要进行以下更改:
|
||||
**来自读者的注意事项**: 根据您的 SSH 版本,您可能还需要进行以下更改:
|
||||
|
||||
- 将公钥放在 `.ssh/authorized_keys2` 中
|
||||
- 将 `.ssh` 的权限更改为 700
|
||||
- 将 `.ssh/authorized_keys2` 的权限更改为 640
|
||||
* 将公钥放在 `.ssh/authorized_keys2` 中
|
||||
* 将 `.ssh` 的权限更改为700
|
||||
* 将 `.ssh/authorized_keys2` 的权限更改为640
|
||||
|
||||
### 如果你使用的是 OpenSSH
|
||||
|
||||
@ -167,25 +139,25 @@ xclip < ~/.ssh/id_ed25519
|
||||
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey]
|
||||
```
|
||||
|
||||
请确保您所选择的密钥算法得到支持。在 Ubuntu 20.04 或更高版本上,您必须明确允许使用 ssh-rsa 算法。请在 OpenSSH 守护进程文件中添加以下行(它可以是 `/etc/ssh/sshd_config` 或 `/etc/ssh/sshd_config.d/` 中的一个附加文件):
|
||||
请确保您所选择的密钥算法得到支持。在 Ubuntu 20.04 或更高版本上,您必须明确允许使用 SSH-RSA 算法。请在 OpenSSH 守护进程文件中添加以下行(它可以是 `/etc/ssh/sshd_config` 或 `/etc/ssh/sshd_config.d/` 中的一个附加文件):
|
||||
|
||||
```bash
|
||||
CASignatureAlgorithms +ssh-rsa
|
||||
```
|
||||
|
||||
或者,`ed25519` 密钥在 OpenSSH 中默认被接受。如果需要,您可以使用它来替代 RSA:
|
||||
或者,`Ed25519` 密钥在 OpenSSH 中默认被接受。如果需要,您可以使用它来替代 RSA。
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
||||
```
|
||||
|
||||
### 示例
|
||||
### Example
|
||||
|
||||
#### 使用密码执行远程 SSH 命令
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -198,7 +170,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -211,7 +183,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -224,27 +196,14 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||

|
||||
|
||||
#### 从文件执行命令
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### 多台主机
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
- host: ”foo.com“
|
||||
+ host: ”foo.com,bar.com“
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
@ -253,16 +212,14 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
ls -al
|
||||
```
|
||||
|
||||
默认的 `port` 值是 `22`。
|
||||
|
||||
#### 多个不同端口的主机
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com:1234,bar.com:5678"
|
||||
- host: ”foo.com“
|
||||
+ host: ”foo.com:1234,bar.com:5678“
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
script: |
|
||||
@ -274,9 +231,9 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: "foo.com,bar.com"
|
||||
host: ”foo.com,bar.com“
|
||||
+ sync: true
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
@ -286,14 +243,14 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
ls -al
|
||||
```
|
||||
|
||||
#### 将环境变量传递到 shell 脚本
|
||||
#### 将环境变量传递到 Shell 脚本
|
||||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
+ env:
|
||||
+ FOO: "BAR"
|
||||
+ BAR: "FOO"
|
||||
+ FOO: ”BAR“
|
||||
+ BAR: ”FOO“
|
||||
+ SHA: ${{ github.sha }}
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
@ -302,19 +259,50 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
port: ${{ secrets.PORT }}
|
||||
+ envs: FOO,BAR,SHA
|
||||
script: |
|
||||
echo "I am $FOO"
|
||||
echo "I am $BAR"
|
||||
echo "sha: $SHA"
|
||||
echo ”I am $FOO“
|
||||
echo ”I am $BAR“
|
||||
echo ”sha: $SHA“
|
||||
```
|
||||
|
||||
_在 `env` 对象中,您需要将每个环境变量作为字符串传递,传递 `Integer` 数据类型或任何其他类型可能会产生意外结果。_
|
||||
|
||||
#### 在第一次失败后停止脚本
|
||||
|
||||
> ex: missing `abc` folder
|
||||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
+ script_stop: true
|
||||
script: |
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
```
|
||||
|
||||
画面输出:
|
||||
|
||||
```sh
|
||||
======CMD======
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
|
||||
======END======
|
||||
2019/11/21 01:16:21 Process exited with status 1
|
||||
err: mkdir: cannot create directory ‘abc/def’: No such file or directory
|
||||
##[error]Docker run failed with exit code 1
|
||||
```
|
||||
|
||||
#### 如何使用 `ProxyCommand` 连接远程服务器?
|
||||
|
||||
```bash
|
||||
+--------+ +----------+ +-----------+
|
||||
| Laptop | <--> | Jumphost | <--> | FooServer |
|
||||
+--------+ +----------+ +-----------+
|
||||
+———+ +-———+ +————+
|
||||
| Laptop | <—> | Jumphost | <—> | FooServer |
|
||||
+———+ +-———+ +————+
|
||||
```
|
||||
|
||||
在您的 `~/.ssh/config` 文件中,您会看到以下内容。
|
||||
@ -337,7 +325,7 @@ Host FooServer
|
||||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -352,13 +340,13 @@ Host FooServer
|
||||
ls -al
|
||||
```
|
||||
|
||||
#### 保护私钥
|
||||
#### 如何保护私钥?
|
||||
|
||||
密码短语通常用于加密私钥。这使得密钥文件本身对攻击者无用。文件泄露可能来自备份或停用的硬件,黑客通常可以从受攻击系统中泄露文件。
|
||||
密码短语通常用于加密私钥。这使得攻击者无法单独使用密钥文件。文件泄露可能来自备份或停用的硬件,黑客通常可以从受攻击系统中泄露文件。因此,保护私钥非常重要。
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -374,17 +362,17 @@ Host FooServer
|
||||
|
||||
设置 SSH 主机指纹验证可以帮助防止中间人攻击。在设置之前,运行以下命令以获取 SSH 主机指纹。请记得将 `ed25519` 替换为您适当的密钥类型(`rsa`、 `dsa`等),而 `example.com` 则替换为您的主机。
|
||||
|
||||
在现代 OpenSSH 版本中,默认提取的密钥类型是 `rsa`(从版本 5.1 开始)、`ecdsa`(从版本 6.0 开始)和 `ed25519`(从版本 6.7 开始)。
|
||||
现代 OpenSSH 版本中,需要提取的_默认密钥_类型是 `rsa`(从版本 5.1 开始)、`ecdsa`(从版本 6.0 开始)和 `ed25519`(从版本 6.7 开始)。
|
||||
|
||||
```sh
|
||||
ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' ' -f2
|
||||
ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ’ ‘ -f2
|
||||
```
|
||||
|
||||
现在您可以调整您的配置:
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -402,4 +390,4 @@ ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' '
|
||||
|
||||
## 授权方式
|
||||
|
||||
本项目中的脚本和文档采用 [MIT 许可证](LICENSE) 发布。
|
||||
本项目中的脚本和文档采用 [MIT](LICENSE) 许可证 发布。
|
202
README.zh-tw.md
202
README.zh-tw.md
@ -1,60 +1,50 @@
|
||||
# 🚀 GitHub Actions 的 SSH
|
||||
# 🚀 用於 GitHub Actions 的 SSH
|
||||
|
||||
[English](./README.md) | 繁體中文 | [简体中文](./README.zh-cn.md)
|
||||
|
||||
[GitHub Action](https://github.com/features/actions) 用於執行遠端 SSH 命令。
|
||||
[GitHub Action](https://github.com/features/actions) for executing remote ssh commands.
|
||||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
|
||||
此專案使用 [Golang](https://go.dev) 和 [drone-ssh](https://github.com/appleboy/drone-ssh) 建立。🚀
|
||||
**注意**: 只支援在 **Linux** [docker](https://www.docker.com/) 容器上執行。
|
||||
|
||||
## 輸入變數
|
||||
|
||||
請參閱 [action.yml](./action.yml) 以獲取更詳細的信息。
|
||||
更詳細的資訊,請參閱 [action.yml](./action.yml)。
|
||||
|
||||
| 輸入參數 | 描述 | 預設值 |
|
||||
| ------------------------- | ----------------------------------------------------- | ------ |
|
||||
| host | SSH 主機地址 | |
|
||||
| port | SSH 埠號 | 22 |
|
||||
| passphrase | SSH 金鑰密碼 | |
|
||||
| username | SSH 使用者名稱 | |
|
||||
| password | SSH 密碼 | |
|
||||
| protocol | SSH 協議版本 (tcp, tcp4, tcp6) | tcp |
|
||||
| sync | 如果有多個主機,啟用同步執行 | false |
|
||||
| use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
||||
| cipher | 允許的加密算法。如果未指定,則使用合理的預設值 | |
|
||||
| timeout | SSH 連接主機的超時時間 | 30s |
|
||||
| command_timeout | SSH 命令的超時時間 | 10m |
|
||||
| key | SSH 私鑰的內容。例如,~/.ssh/id_rsa 的原始內容 | |
|
||||
| key_path | SSH 私鑰的路徑 | |
|
||||
| fingerprint | 主機公鑰的 SHA256 指紋 | |
|
||||
| proxy_host | SSH 代理主機 | |
|
||||
| proxy_port | SSH 代理埠號 | 22 |
|
||||
| proxy_protocol | SSH 代理協議版本 (tcp, tcp4, tcp6) | tcp |
|
||||
| proxy_username | SSH 代理使用者名稱 | |
|
||||
| proxy_password | SSH 代理密碼 | |
|
||||
| proxy_passphrase | SSH 代理金鑰密碼 | |
|
||||
| proxy_timeout | SSH 連接代理主機的超時時間 | 30s |
|
||||
| proxy_key | SSH 代理私鑰的內容 | |
|
||||
| proxy_key_path | SSH 代理私鑰的路徑 | |
|
||||
| proxy_fingerprint | 代理主機公鑰的 SHA256 指紋 | |
|
||||
| proxy_cipher | 代理允許的加密算法 | |
|
||||
| proxy_use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
||||
| script | 執行命令 | |
|
||||
| script_path | 從文件中執行命令 | |
|
||||
| envs | 將環境變數傳遞給 shell 腳本 | |
|
||||
| envs_format | 環境值傳遞的靈活配置 | |
|
||||
| debug | 啟用調試模式 | false |
|
||||
| allenvs | 將帶有 `GITHUB_` 和 `INPUT_` 前綴的環境變數傳遞給腳本 | false |
|
||||
| request_pty | 從伺服器請求偽終端 | false |
|
||||
| curl_insecure | 在 curl 命令中使用不安全的 SSL 證書驗證 | false |
|
||||
| version | drone-ssh 版本號。若未指定,將使用最新版本。 | |
|
||||
* `host` - SSH 主機
|
||||
* `port` - SSH 連接埠,預設為 `22`
|
||||
* `username` - SSH 使用者名稱
|
||||
* `password` - SSH 密碼
|
||||
* `passphrase` - 通常用於加密私鑰的 passphrase
|
||||
* `sync` - 同步執行多個主機上的命令,預設為 false
|
||||
* `timeout` - SSH 連接到遠端主機的超時時間,預設為 `30s`
|
||||
* `command_timeout` - SSH 命令超時時間,預設為 10m
|
||||
* `key` - SSH 私鑰的內容,例如 ~/.ssh/id_rsa 的原始內容,請記得包含 BEGIN 和 END 行
|
||||
* `key_path` - SSH 私鑰的路徑
|
||||
* `fingerprint` - 主機公鑰的 SHA256 指紋,預設為略過驗證
|
||||
* `script` - 執行命令
|
||||
* `script_stop` - 當出現第一個錯誤時停止執行命令
|
||||
* `envs` - 傳遞環境變數到 shell script
|
||||
* `debug` - 啟用偵錯模式
|
||||
* `use_insecure_cipher` - 使用不安全的密碼(ciphers)進行加密,參見 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `cipher` - 允許使用的密碼(ciphers)演算法。如果未指定,則使用適當的演算法
|
||||
|
||||
**注意:** 用戶可以在他們的 shell 腳本中添加 `set -e` 以實現類似於已刪除的 `script_stop` 選項的功能。
|
||||
SSH 代理設置:
|
||||
|
||||
## 用法
|
||||
* `proxy_host` - 代理主機
|
||||
* `proxy_port` - 代理端口,預設為 `22`
|
||||
* `proxy_username` - 代理使用者名稱
|
||||
* `proxy_password` - 代理密碼
|
||||
* `proxy_passphrase` - 密碼通常用於加密私有金鑰
|
||||
* `proxy_timeout` - SSH 連線至代理主機的逾時時間,預設為 `30s`
|
||||
* `proxy_key` - SSH 代理私有金鑰內容
|
||||
* `proxy_key_path` - SSH 代理私有金鑰路徑
|
||||
* `proxy_fingerprint` - 代理主機公鑰的 SHA256 指紋,預設為跳過驗證
|
||||
* `proxy_use_insecure_cipher` - 使用不安全的加密方式,請參閱 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `proxy_cipher` - 允許的加密算法。如果未指定,則使用合理的算法
|
||||
|
||||
## 使用方式
|
||||
|
||||
執行遠端 SSH 命令
|
||||
|
||||
@ -62,18 +52,19 @@
|
||||
name: remote ssh command
|
||||
on: [push]
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: linuxserver.io
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
```
|
||||
|
||||
畫面輸出
|
||||
@ -82,10 +73,10 @@ jobs:
|
||||
======CMD======
|
||||
whoami
|
||||
======END======
|
||||
linuxserver.io
|
||||
===============================================
|
||||
✅ Successfully executed commands to all hosts.
|
||||
===============================================
|
||||
out: ***
|
||||
==============================================
|
||||
✅ Successfully executed commands to all host.
|
||||
==============================================
|
||||
```
|
||||
|
||||
### 設置 SSH 金鑰
|
||||
@ -122,40 +113,23 @@ cat .ssh/id_ed25519.pub | ssh b@B 'cat >> .ssh/authorized_keys'
|
||||
|
||||
### 複製 rsa 私鑰內容
|
||||
|
||||
在複製私鑰之前,請按照以下說明安裝 `clip` 命令:
|
||||
|
||||
```bash
|
||||
# Ubuntu
|
||||
sudo apt-get install xclip
|
||||
clip < ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
複製私鑰:
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
pbcopy < ~/.ssh/id_rsa
|
||||
# Ubuntu
|
||||
xclip < ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
從包含註釋部分 `-----BEGIN OPENSSH PRIVATE KEY-----` 開始,到包含註釋部分 `-----END OPENSSH PRIVATE KEY-----` 結束,複製私鑰並將其粘貼到 GitHub Secrets 中。
|
||||
|
||||
### 複製 ed25519 私鑰內容
|
||||
|
||||
```bash
|
||||
# macOS
|
||||
pbcopy < ~/.ssh/id_ed25519
|
||||
# Ubuntu
|
||||
xclip < ~/.ssh/id_ed25519
|
||||
clip < ~/.ssh/id_ed25519
|
||||
```
|
||||
|
||||
有關無需密碼登錄 SSH 的詳細信息,請[參見該網站](http://www.linuxproblem.org/art_9.html)。
|
||||
|
||||
**注意**:根據您的 SSH 版本,您可能還需要進行以下更改:
|
||||
**來自讀者的注意事項**: 根據您的 SSH 版本,您可能還需要進行以下更改:
|
||||
|
||||
- 將公鑰放在 `.ssh/authorized_keys2` 中
|
||||
- 將 `.ssh` 的權限更改為 700
|
||||
- 將 `.ssh/authorized_keys2` 的權限更改為 640
|
||||
* 將公鑰放在 `.ssh/authorized_keys2` 中
|
||||
* 將 `.ssh` 的權限更改為700
|
||||
* 將 `.ssh/authorized_keys2` 的權限更改為640
|
||||
|
||||
### 如果你使用的是 OpenSSH
|
||||
|
||||
@ -183,7 +157,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -196,7 +170,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -209,7 +183,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -222,24 +196,11 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||

|
||||
|
||||
#### 從文件中執行命令
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### 多台主機
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
@ -255,7 +216,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com:1234,bar.com:5678"
|
||||
@ -270,7 +231,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: "foo.com,bar.com"
|
||||
+ sync: true
|
||||
@ -286,7 +247,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
+ env:
|
||||
+ FOO: "BAR"
|
||||
+ BAR: "FOO"
|
||||
@ -305,6 +266,37 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
||||
|
||||
_在 `env` 對象中,您需要將每個環境變量作為字符串傳遞,傳遞 `Integer` 數據類型或任何其他類型可能會產生意外結果。_
|
||||
|
||||
#### 在第一次失敗後停止腳本
|
||||
|
||||
> ex: missing `abc` folder
|
||||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
+ script_stop: true
|
||||
script: |
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
```
|
||||
|
||||
畫面輸出:
|
||||
|
||||
```sh
|
||||
======CMD======
|
||||
mkdir abc/def
|
||||
ls -al
|
||||
|
||||
======END======
|
||||
2019/11/21 01:16:21 Process exited with status 1
|
||||
err: mkdir: cannot create directory ‘abc/def’: No such file or directory
|
||||
##[error]Docker run failed with exit code 1
|
||||
```
|
||||
|
||||
#### 如何使用 `ProxyCommand` 連接遠程服務器?
|
||||
|
||||
```bash
|
||||
@ -333,7 +325,7 @@ Host FooServer
|
||||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -354,7 +346,7 @@ Host FooServer
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
@ -370,7 +362,7 @@ Host FooServer
|
||||
|
||||
設置 SSH 主機指紋驗證可以幫助防止中間人攻擊。在設置之前,運行以下命令以獲取 SSH 主機指紋。請記得將 `ed25519` 替換為您的適當金鑰類型(`rsa`、 `dsa`等),而 `example.com` 則替換為您的主機。
|
||||
|
||||
現代 OpenSSH 版本中,需要提取的**默認金鑰**類型是 `rsa`(從版本 5.1 開始)、`ecdsa`(從版本 6.0 開始)和 `ed25519`(從版本 6.7 開始)。
|
||||
現代 OpenSSH 版本中,需要提取的_默認金鑰_類型是 `rsa`(從版本 5.1 開始)、`ecdsa`(從版本 6.0 開始)和 `ed25519`(從版本 6.7 開始)。
|
||||
|
||||
```sh
|
||||
ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' ' -f2
|
||||
@ -380,7 +372,7 @@ ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' '
|
||||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
91
action.yml
91
action.yml
@ -3,92 +3,75 @@ description: "Executing remote ssh commands"
|
||||
author: "Bo-Yi Wu"
|
||||
inputs:
|
||||
host:
|
||||
description: "SSH host address or IP to connect to."
|
||||
description: "SSH host address."
|
||||
port:
|
||||
description: "SSH port number for the connection."
|
||||
description: "SSH port number."
|
||||
default: "22"
|
||||
passphrase:
|
||||
description: "Passphrase to decrypt the SSH private key if protected."
|
||||
description: "Passphrase for the SSH key."
|
||||
username:
|
||||
description: "SSH username for authentication on the remote server."
|
||||
description: "SSH username."
|
||||
password:
|
||||
description: "SSH password for authentication (use secrets for sensitive data)."
|
||||
description: "SSH password."
|
||||
protocol:
|
||||
description: 'IP protocol version to use. Options: "tcp" (default), "tcp4" (IPv4 only), or "tcp6" (IPv6 only).'
|
||||
description: 'The IP protocol to use. Valid values are "tcp". "tcp4" or "tcp6". Default to tcp.'
|
||||
default: "tcp"
|
||||
sync:
|
||||
description: "When true, executes commands synchronously across multiple hosts (one after another)."
|
||||
description: "Enable synchronous execution if multiple hosts are involved."
|
||||
use_insecure_cipher:
|
||||
description: "Enable additional legacy ciphers that might be less secure but more compatible with older systems."
|
||||
description: "Include more ciphers by using insecure ciphers."
|
||||
cipher:
|
||||
description: "Specify custom cipher algorithms for encryption. Leave empty to use secure defaults."
|
||||
description: "Allowed cipher algorithms. If unspecified, a sensible default is used."
|
||||
timeout:
|
||||
description: "Maximum time to wait when establishing the SSH connection, e.g., '30s', '1m'."
|
||||
description: "Timeout duration for establishing SSH connection to the host."
|
||||
default: "30s"
|
||||
command_timeout:
|
||||
description: "Maximum execution time for the remote commands before terminating, e.g., '10m', '1h'."
|
||||
description: "Timeout duration for SSH commands execution."
|
||||
default: "10m"
|
||||
key:
|
||||
description: "Raw content of the SSH private key for authentication (use secrets for sensitive data)."
|
||||
description: "Content of the SSH private key. For example, the raw content of ~/.ssh/id_rsa."
|
||||
key_path:
|
||||
description: "Path to the SSH private key file on the runner."
|
||||
description: "Path to the SSH private key file."
|
||||
fingerprint:
|
||||
description: "SHA256 fingerprint of the host public key for verification to prevent MITM attacks."
|
||||
description: "SHA256 fingerprint of the host public key."
|
||||
proxy_host:
|
||||
description: "Proxy server hostname or IP if connecting through an SSH jump host."
|
||||
description: "SSH proxy host address."
|
||||
proxy_port:
|
||||
description: "SSH port number for the proxy connection."
|
||||
description: "SSH proxy port number."
|
||||
default: "22"
|
||||
proxy_username:
|
||||
description: "Username for authentication on the proxy server."
|
||||
description: "SSH proxy username."
|
||||
proxy_password:
|
||||
description: "Password for authentication on the proxy server (use secrets for sensitive data)."
|
||||
proxy_protocol:
|
||||
description: 'IP protocol version for proxy. Options: "tcp" (default), "tcp4" (IPv4 only), or "tcp6" (IPv6 only).'
|
||||
default: "tcp"
|
||||
description: "SSH proxy password."
|
||||
proxy_passphrase:
|
||||
description: "Passphrase to decrypt the proxy SSH private key if protected."
|
||||
description: "SSH proxy key passphrase."
|
||||
proxy_timeout:
|
||||
description: "Maximum time to wait when establishing the proxy SSH connection, e.g., '30s', '1m'."
|
||||
description: "Timeout duration for establishing SSH connection to the proxy host."
|
||||
default: "30s"
|
||||
proxy_key:
|
||||
description: "Raw content of the SSH proxy private key for authentication (use secrets for sensitive data)."
|
||||
description: "Content of the SSH proxy private key. For example, the raw content of ~/.ssh/id_rsa."
|
||||
proxy_key_path:
|
||||
description: "Path to the SSH proxy private key file on the runner."
|
||||
description: "Path to the SSH proxy private key file."
|
||||
proxy_fingerprint:
|
||||
description: "SHA256 fingerprint of the proxy host public key for verification."
|
||||
description: "SHA256 fingerprint of the proxy host public key."
|
||||
proxy_cipher:
|
||||
description: "Specify custom cipher algorithms for proxy connection encryption."
|
||||
description: "Allowed cipher algorithms for the proxy. If unspecified, a sensible default is used."
|
||||
proxy_use_insecure_cipher:
|
||||
description: "Enable additional legacy ciphers for proxy connections (less secure but more compatible)."
|
||||
description: "Include more ciphers for the proxy by using insecure ciphers."
|
||||
script:
|
||||
description: "Commands to execute on the remote server (inline script string)."
|
||||
script_path:
|
||||
description: "Path to a local file containing commands to execute on the remote server."
|
||||
description: "Commands to be executed."
|
||||
script_stop:
|
||||
description: "Stop the script after the first failure."
|
||||
envs:
|
||||
description: "Environment variables to expose to the remote script, format: key=value,key2=value2."
|
||||
description: "Environment variables to be passed to the shell script."
|
||||
envs_format:
|
||||
description: "Format specification for environment variable transfer (for advanced usage)."
|
||||
description: "Flexible configuration for environment value transfer."
|
||||
debug:
|
||||
description: "Set to true to enable verbose logging for troubleshooting connection issues."
|
||||
description: "Enable debug mode."
|
||||
allenvs:
|
||||
description: "When true, passes all GitHub Actions environment variables to the remote script."
|
||||
description: "pass all environment variable to shell script."
|
||||
request_pty:
|
||||
description: "Request a pseudo-terminal from the server (required for interactive commands or sudo)."
|
||||
curl_insecure:
|
||||
description: "When true, uses the --insecure option with curl for insecure downloads."
|
||||
default: "false"
|
||||
capture_stdout:
|
||||
description: "When true, captures and returns standard output from the commands as action output."
|
||||
default: "false"
|
||||
version:
|
||||
description: |
|
||||
The version of drone-ssh to use.
|
||||
|
||||
outputs:
|
||||
stdout:
|
||||
description: "Standard output of the executed commands when capture_stdout is enabled."
|
||||
value: ${{ steps.entrypoint.outputs.stdout }}
|
||||
description: "Request a pseudo-terminal from the server."
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@ -98,8 +81,7 @@ runs:
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_ACTION_PATH: ${{ github.action_path }}
|
||||
- id: entrypoint
|
||||
name: Run entrypoint.sh
|
||||
- name: Run entrypoint.sh
|
||||
run: entrypoint.sh
|
||||
shell: bash
|
||||
env:
|
||||
@ -125,7 +107,7 @@ runs:
|
||||
INPUT_PROXY_TIMEOUT: ${{ inputs.proxy_timeout }}
|
||||
INPUT_COMMAND_TIMEOUT: ${{ inputs.command_timeout }}
|
||||
INPUT_SCRIPT: ${{ inputs.script }}
|
||||
INPUT_SCRIPT_FILE: ${{ inputs.script_path }}
|
||||
INPUT_SCRIPT_STOP: ${{ inputs.script_stop }}
|
||||
INPUT_ENVS: ${{ inputs.envs }}
|
||||
INPUT_ENVS_FORMAT: ${{ inputs.envs_format }}
|
||||
INPUT_DEBUG: ${{ inputs.debug }}
|
||||
@ -136,9 +118,6 @@ runs:
|
||||
INPUT_PROXY_USE_INSECURE_CIPHER: ${{ inputs.proxy_use_insecure_cipher }}
|
||||
INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }}
|
||||
INPUT_SYNC: ${{ inputs.sync }}
|
||||
INPUT_CAPTURE_STDOUT: ${{ inputs.capture_stdout }}
|
||||
INPUT_CURL_INSECURE: ${{ inputs.curl_insecure }}
|
||||
DRONE_SSH_VERSION: ${{ inputs.version }}
|
||||
|
||||
branding:
|
||||
icon: "terminal"
|
||||
|
@ -1,56 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
export GITHUB="true"
|
||||
|
||||
GITHUB_ACTION_PATH="${GITHUB_ACTION_PATH%/}"
|
||||
DRONE_SSH_RELEASE_URL="${DRONE_SSH_RELEASE_URL:-https://github.com/appleboy/drone-ssh/releases/download}"
|
||||
DRONE_SSH_VERSION="${DRONE_SSH_VERSION:-1.8.1}"
|
||||
|
||||
function log_error() {
|
||||
echo "$1" >&2
|
||||
exit "$2"
|
||||
}
|
||||
DRONE_SSH_VERSION="${DRONE_SSH_VERSION:-1.7.7}"
|
||||
|
||||
function detect_client_info() {
|
||||
CLIENT_PLATFORM="${SSH_CLIENT_OS:-$(uname -s | tr '[:upper:]' '[:lower:]')}"
|
||||
CLIENT_ARCH="${SSH_CLIENT_ARCH:-$(uname -m)}"
|
||||
if [ -n "${SSH_CLIENT_OS-}" ]; then
|
||||
CLIENT_PLATFORM="${SSH_CLIENT_OS}"
|
||||
else
|
||||
local kernel
|
||||
kernel="$(uname -s)"
|
||||
case "${kernel}" in
|
||||
Darwin)
|
||||
CLIENT_PLATFORM="darwin"
|
||||
;;
|
||||
Linux)
|
||||
CLIENT_PLATFORM="linux"
|
||||
;;
|
||||
Windows)
|
||||
CLIENT_PLATFORM="windows"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported platform: ${kernel}." >&2
|
||||
echo "Supported platforms: Linux, Darwin and Windows." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 2
|
||||
esac
|
||||
fi
|
||||
|
||||
case "${CLIENT_PLATFORM}" in
|
||||
darwin | linux | windows) ;;
|
||||
*) log_error "Unknown or unsupported platform: ${CLIENT_PLATFORM}. Supported platforms are Linux, Darwin, and Windows." 2 ;;
|
||||
esac
|
||||
|
||||
case "${CLIENT_ARCH}" in
|
||||
x86_64* | i?86_64* | amd64*) CLIENT_ARCH="amd64" ;;
|
||||
aarch64* | arm64*) CLIENT_ARCH="arm64" ;;
|
||||
*) log_error "Unknown or unsupported architecture: ${CLIENT_ARCH}. Supported architectures are x86_64, i686, and arm64." 3 ;;
|
||||
esac
|
||||
if [ -n "${SSH_CLIENT_ARCH-}" ]; then
|
||||
CLIENT_ARCH="${SSH_CLIENT_ARCH}"
|
||||
else
|
||||
local machine
|
||||
machine="$(uname -m)"
|
||||
case "${machine}" in
|
||||
x86_64*|i?86_64*|amd64*)
|
||||
CLIENT_ARCH="amd64"
|
||||
;;
|
||||
aarch64*|arm64*)
|
||||
CLIENT_ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported architecture (${machine})." >&2
|
||||
echo "Supported architectures x86_64, i686, arm64." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
detect_client_info
|
||||
DOWNLOAD_URL_PREFIX="${DRONE_SSH_RELEASE_URL}/v${DRONE_SSH_VERSION}"
|
||||
CLIENT_BINARY="drone-ssh-${DRONE_SSH_VERSION}-${CLIENT_PLATFORM}-${CLIENT_ARCH}"
|
||||
TARGET="${GITHUB_ACTION_PATH}/${CLIENT_BINARY}"
|
||||
echo "Downloading ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
|
||||
INSECURE_OPTION=""
|
||||
if [[ "${INPUT_CURL_INSECURE}" == 'true' ]]; then
|
||||
INSECURE_OPTION="--insecure"
|
||||
fi
|
||||
|
||||
curl -fsSL --retry 5 --keepalive-time 2 ${INSECURE_OPTION} "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o "${TARGET}"
|
||||
chmod +x "${TARGET}"
|
||||
|
||||
echo "======= CLI Version Information ======="
|
||||
"${TARGET}" --version
|
||||
echo "======================================="
|
||||
if [[ "${INPUT_CAPTURE_STDOUT}" == 'true' ]]; then
|
||||
{
|
||||
echo 'stdout<<EOF'
|
||||
"${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}"
|
||||
echo 'EOF'
|
||||
} >>"${GITHUB_OUTPUT}"
|
||||
else
|
||||
"${TARGET}" "$@"
|
||||
fi
|
||||
echo "Will download ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
|
||||
curl -fsSL --retry 5 --keepalive-time 2 "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o ${TARGET}
|
||||
chmod +x ${TARGET}
|
||||
echo "======= CLI Version ======="
|
||||
sh -c "${TARGET} --version" # print version
|
||||
echo "==========================="
|
||||
sh -c "${TARGET} $*" # run the command
|
||||
|
3
testdata/test.sh
vendored
3
testdata/test.sh
vendored
@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
Loading…
x
Reference in New Issue
Block a user