Compare commits
10 Commits
a9e2fdf08d
...
49751ff516
Author | SHA1 | Date | |
---|---|---|---|
|
49751ff516 | ||
|
86aa40ddb7 | ||
|
66aa4d343b | ||
|
102c0d2e5f | ||
|
e13c387332 | ||
|
1c1ad10f6d | ||
|
48531853a7 | ||
|
b76e6173e8 | ||
|
6137f733fb | ||
|
43d4ebbb72 |
237
.github/workflows/main.yml
vendored
237
.github/workflows/main.yml
vendored
@@ -123,22 +123,6 @@ jobs:
|
|||||||
port: 2222
|
port: 2222
|
||||||
script: whoami
|
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:
|
support-key-passphrase:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -215,7 +199,6 @@ jobs:
|
|||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
port: 2222
|
port: 2222
|
||||||
passphrase: 1234
|
passphrase: 1234
|
||||||
script_stop: true
|
|
||||||
script: |
|
script: |
|
||||||
ls \
|
ls \
|
||||||
-lah
|
-lah
|
||||||
@@ -292,7 +275,6 @@ jobs:
|
|||||||
username: linuxserver.io
|
username: linuxserver.io
|
||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
passphrase: 1234
|
passphrase: 1234
|
||||||
script_stop: true
|
|
||||||
script: |
|
script: |
|
||||||
whoami
|
whoami
|
||||||
|
|
||||||
@@ -488,7 +470,6 @@ jobs:
|
|||||||
username: linuxserver.io
|
username: linuxserver.io
|
||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
port: 2222
|
port: 2222
|
||||||
script_stop: true
|
|
||||||
request_pty: true
|
request_pty: true
|
||||||
command_timeout: 30s
|
command_timeout: 30s
|
||||||
script: |
|
script: |
|
||||||
@@ -523,3 +504,221 @@ jobs:
|
|||||||
command_timeout: 30s
|
command_timeout: 30s
|
||||||
script: |
|
script: |
|
||||||
whoami
|
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
|
||||||
|
28
.github/workflows/stable.yml
vendored
28
.github/workflows/stable.yml
vendored
@@ -42,6 +42,15 @@ jobs:
|
|||||||
set -e
|
set -e
|
||||||
whoami
|
whoami
|
||||||
|
|
||||||
|
- name: ssh commands from a file
|
||||||
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
|
with:
|
||||||
|
host: ${{ env.REMOTE_HOST }}
|
||||||
|
username: linuxserver.io
|
||||||
|
password: password
|
||||||
|
port: 2222
|
||||||
|
script_path: testdata/test.sh
|
||||||
|
|
||||||
check-ssh-key:
|
check-ssh-key:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -114,22 +123,6 @@ jobs:
|
|||||||
port: 2222
|
port: 2222
|
||||||
script: whoami
|
script: whoami
|
||||||
|
|
||||||
- name: stop script if command error
|
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
|
||||||
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:
|
support-key-passphrase:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -206,7 +199,6 @@ jobs:
|
|||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
port: 2222
|
port: 2222
|
||||||
passphrase: 1234
|
passphrase: 1234
|
||||||
script_stop: true
|
|
||||||
script: |
|
script: |
|
||||||
ls \
|
ls \
|
||||||
-lah
|
-lah
|
||||||
@@ -283,7 +275,6 @@ jobs:
|
|||||||
username: linuxserver.io
|
username: linuxserver.io
|
||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
passphrase: 1234
|
passphrase: 1234
|
||||||
script_stop: true
|
|
||||||
script: |
|
script: |
|
||||||
whoami
|
whoami
|
||||||
|
|
||||||
@@ -469,7 +460,6 @@ jobs:
|
|||||||
username: linuxserver.io
|
username: linuxserver.io
|
||||||
key: ${{ env.PRIVATE_KEY }}
|
key: ${{ env.PRIVATE_KEY }}
|
||||||
port: 2222
|
port: 2222
|
||||||
script_stop: true
|
|
||||||
request_pty: true
|
request_pty: true
|
||||||
command_timeout: 30s
|
command_timeout: 30s
|
||||||
script: |
|
script: |
|
||||||
|
62
README.md
62
README.md
@@ -1,7 +1,6 @@
|
|||||||
# 🚀 SSH for GitHub Actions
|
# 🚀 SSH for GitHub Actions
|
||||||
|
|
||||||
[繁體中文](./README.zh-tw.md)
|
[繁體中文](./README.zh-tw.md) | [简体中文](./README.zh-cn.md)
|
||||||
[简体中文](./README.zh-cn.md)
|
|
||||||
|
|
||||||
[GitHub Action](https://github.com/features/actions) for executing remote SSH commands.
|
[GitHub Action](https://github.com/features/actions) for executing remote SSH commands.
|
||||||
|
|
||||||
@@ -44,8 +43,7 @@ See [action.yml](./action.yml) for more detailed information.
|
|||||||
| proxy_cipher | Allowed cipher algorithms for the proxy | |
|
| proxy_cipher | Allowed cipher algorithms for the proxy | |
|
||||||
| proxy_use_insecure_cipher | Include more ciphers with use_insecure_cipher for the proxy | false |
|
| proxy_use_insecure_cipher | Include more ciphers with use_insecure_cipher for the proxy | false |
|
||||||
| script | Execute commands | |
|
| script | Execute commands | |
|
||||||
| script_file | Execute commands from a file | |
|
| script_path | Execute commands from a file | |
|
||||||
| script_stop | Stop script after first failure | false |
|
|
||||||
| envs | Pass environment variables to shell script | |
|
| envs | Pass environment variables to shell script | |
|
||||||
| envs_format | Flexible configuration of environment value transfer | |
|
| envs_format | Flexible configuration of environment value transfer | |
|
||||||
| debug | Enable debug mode | false |
|
| debug | Enable debug mode | false |
|
||||||
@@ -60,19 +58,18 @@ Executing remote SSH commands.
|
|||||||
name: remote ssh command
|
name: remote ssh command
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: executing remote ssh commands using password
|
- name: executing remote ssh commands using password
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST }}
|
host: ${{ secrets.HOST }}
|
||||||
username: linuxserver.io
|
username: linuxserver.io
|
||||||
password: ${{ secrets.PASSWORD }}
|
password: ${{ secrets.PASSWORD }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script: whoami
|
script: whoami
|
||||||
```
|
```
|
||||||
|
|
||||||
output:
|
output:
|
||||||
@@ -152,9 +149,9 @@ See the detail information about [SSH login without password](http://www.linuxpr
|
|||||||
|
|
||||||
**A note** from one of our readers: Depending on your version of SSH you might also have to do 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`
|
- Put the public key in `.ssh/authorized_keys2`
|
||||||
* Change the permissions of `.ssh` to 700
|
- Change the permissions of `.ssh` to 700
|
||||||
* Change the permissions of `.ssh/authorized_keys2` to 640
|
- Change the permissions of `.ssh/authorized_keys2` to 640
|
||||||
|
|
||||||
### If you are using OpenSSH
|
### If you are using OpenSSH
|
||||||
|
|
||||||
@@ -231,7 +228,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||||||
username: ${{ secrets.USERNAME }}
|
username: ${{ secrets.USERNAME }}
|
||||||
key: ${{ secrets.KEY }}
|
key: ${{ secrets.KEY }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script_path: scripts/script.sh
|
script_path: scripts/script.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Multiple Hosts
|
#### Multiple Hosts
|
||||||
@@ -306,37 +303,6 @@ 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._
|
_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.2.0
|
|
||||||
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`?
|
#### How to connect remote server using `ProxyCommand`?
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
129
README.zh-cn.md
129
README.zh-cn.md
@@ -1,47 +1,54 @@
|
|||||||
# 🚀 用于 GitHub Actions 的 SSH
|
# 🚀 用于 GitHub Actions 的 SSH
|
||||||
|
|
||||||
|
[English](./README.md) | [繁體中文](./README.zh-tw.md)
|
||||||
|
|
||||||
[GitHub Action](https://github.com/features/actions) 用于执行远程 SSH 命令。
|
[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/workflows/main.yml)
|
||||||
|
|
||||||
|
该项目使用 [Golang](https://go.dev) 和 [drone-ssh](https://github.com/appleboy/drone-ssh) 构建。🚀
|
||||||
|
|
||||||
## 输入变量
|
## 输入变量
|
||||||
|
|
||||||
更详细的信息,请参考 [action.yml](./action.yml)。
|
更详细的信息,请参考 [action.yml](./action.yml)。
|
||||||
|
|
||||||
* `host` - SSH 主机
|
| 输入参数 | 描述 | 默认值 |
|
||||||
* `port` - SSH 连接端口,默认为 `22`
|
| ------------------------- | ----------------------------------------------------- | ------ |
|
||||||
* `username` - SSH 用户名称
|
| host | SSH 主机地址 | |
|
||||||
* `password` - SSH 密码
|
| port | SSH 端口号 | 22 |
|
||||||
* `passphrase` - 通常用于加密私钥的 passphrase
|
| passphrase | SSH 密钥密码短语 | |
|
||||||
* `sync` - 同步执行多个主机上的命令,默认为 false
|
| username | SSH 用户名 | |
|
||||||
* `timeout` - SSH 连接到远程主机的超时时间,默认为 `30s`
|
| password | SSH 密码 | |
|
||||||
* `command_timeout` - SSH 命令超时时间,默认为 10m
|
| protocol | SSH 协议版本(tcp, tcp4, tcp6) | tcp |
|
||||||
* `key` - SSH 私钥的内容,例如 ~/.ssh/id_rsa 的原始内容,请记得包含 BEGIN 和 END 行
|
| sync | 如果有多个主机,启用同步执行 | false |
|
||||||
* `key_path` - SSH 私钥的路径
|
| use_insecure_cipher | 使用不安全的密码算法 | false |
|
||||||
* `fingerprint` - 主机公钥的 SHA256 指纹,默认为跳过验证
|
| cipher | 允许的密码算法。如果未指定,则使用适当的算法 | |
|
||||||
* `script` - 执行命令
|
| timeout | SSH 连接到主机的超时时间 | 30s |
|
||||||
* `script_file` - 執行命令的文件
|
| command_timeout | SSH 命令的超时时间 | 10m |
|
||||||
* `script_stop` - 当出现第一个错误时停止执行命令
|
| key | SSH 私钥的内容,例如 ~/.ssh/id_rsa 的原始内容 | |
|
||||||
* `envs` - 传递环境变量到 shell script
|
| key_path | SSH 私钥的路径 | |
|
||||||
* `debug` - 启用调试模式
|
| fingerprint | 主机公钥的 SHA256 指纹 | |
|
||||||
* `use_insecure_cipher` - 使用不安全的密码(ciphers)进行加密,详见 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
| proxy_host | SSH 代理主机 | |
|
||||||
* `cipher` - 允许使用的密码(ciphers)算法。如果未指定,则使用适当的算法
|
| proxy_port | SSH 代理端口 | 22 |
|
||||||
|
| proxy_protocol | SSH 代理协议版本(tcp, tcp4, tcp6) | tcp |
|
||||||
SSH 代理设置:
|
| proxy_username | SSH 代理用户名 | |
|
||||||
|
| proxy_password | SSH 代理密码 | |
|
||||||
* `proxy_host` - 代理主机
|
| proxy_passphrase | SSH 代理密钥密码短语 | |
|
||||||
* `proxy_port` - 代理端口,默认为 `22`
|
| proxy_timeout | SSH 连接到代理主机的超时时间 | 30s |
|
||||||
* `proxy_username` - 代理用户名
|
| proxy_key | SSH 代理私钥的内容 | |
|
||||||
* `proxy_password` - 代理密码
|
| proxy_key_path | SSH 代理私钥的路径 | |
|
||||||
* `proxy_passphrase` - 密码通常用于加密私有密钥
|
| proxy_fingerprint | 代理主机公钥的 SHA256 指纹 | |
|
||||||
* `proxy_timeout` - SSH 连接至代理主机的超时时间,默认为 `30s`
|
| proxy_cipher | 代理允许的密码算法 | |
|
||||||
* `proxy_key` - SSH 代理私有密钥内容
|
| proxy_use_insecure_cipher | 使用不安全的密码算法 | false |
|
||||||
* `proxy_key_path` - SSH 代理私有密钥路径
|
| script | 执行命令 | |
|
||||||
* `proxy_fingerprint` - 代理主机公钥的 SHA256 指纹,默认为跳过验证
|
| script_path | 从文件执行命令 | |
|
||||||
* `proxy_use_insecure_cipher` - 使用不安全的加密方式,详见 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
| envs | 传递环境变量到 shell 脚本 | |
|
||||||
* `proxy_cipher` - 允许的加密算法。如果未指定,则使用合理的算法
|
| envs_format | 环境变量传递的灵活配置 | |
|
||||||
|
| debug | 启用调试模式 | false |
|
||||||
|
| allenvs | 将带有 `GITHUB_` 和 `INPUT_` 前缀的环境变量传递给脚本 | false |
|
||||||
|
| request_pty | 请求伪终端 | false |
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
|
|
||||||
@@ -51,19 +58,18 @@ SSH 代理设置:
|
|||||||
name: remote ssh command
|
name: remote ssh command
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: executing remote ssh commands using password
|
- name: executing remote ssh commands using password
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST }}
|
host: ${{ secrets.HOST }}
|
||||||
username: ${{ secrets.USERNAME }}
|
username: ${{ secrets.USERNAME }}
|
||||||
password: ${{ secrets.PASSWORD }}
|
password: ${{ secrets.PASSWORD }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script: whoami
|
script: whoami
|
||||||
```
|
```
|
||||||
|
|
||||||
画面输出
|
画面输出
|
||||||
@@ -126,9 +132,9 @@ clip < ~/.ssh/id_ed25519
|
|||||||
|
|
||||||
**来自读者的注意事项**: 根据您的 SSH 版本,您可能还需要进行以下更改:
|
**来自读者的注意事项**: 根据您的 SSH 版本,您可能还需要进行以下更改:
|
||||||
|
|
||||||
* 将公钥放在 `.ssh/authorized_keys2` 中
|
- 将公钥放在 `.ssh/authorized_keys2` 中
|
||||||
* 将 `.ssh` 的权限更改为700
|
- 将 `.ssh` 的权限更改为 700
|
||||||
* 将 `.ssh/authorized_keys2` 的权限更改为640
|
- 将 `.ssh/authorized_keys2` 的权限更改为 640
|
||||||
|
|
||||||
### 如果你使用的是 OpenSSH
|
### 如果你使用的是 OpenSSH
|
||||||
|
|
||||||
@@ -221,7 +227,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||||||
username: ${{ secrets.USERNAME }}
|
username: ${{ secrets.USERNAME }}
|
||||||
key: ${{ secrets.KEY }}
|
key: ${{ secrets.KEY }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script_path: scripts/script.sh
|
script_path: scripts/script.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 多个不同端口的主机
|
#### 多个不同端口的主机
|
||||||
@@ -278,37 +284,6 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||||||
|
|
||||||
_在 `env` 对象中,您需要将每个环境变量作为字符串传递,传递 `Integer` 数据类型或任何其他类型可能会产生意外结果。_
|
_在 `env` 对象中,您需要将每个环境变量作为字符串传递,传递 `Integer` 数据类型或任何其他类型可能会产生意外结果。_
|
||||||
|
|
||||||
#### 在第一次失败后停止脚本
|
|
||||||
|
|
||||||
> ex: missing `abc` folder
|
|
||||||
|
|
||||||
```diff
|
|
||||||
- name: stop script if command error
|
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
|
||||||
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` 连接远程服务器?
|
#### 如何使用 `ProxyCommand` 连接远程服务器?
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -374,7 +349,7 @@ Host FooServer
|
|||||||
|
|
||||||
设置 SSH 主机指纹验证可以帮助防止中间人攻击。在设置之前,运行以下命令以获取 SSH 主机指纹。请记得将 `ed25519` 替换为您适当的密钥类型(`rsa`、 `dsa`等),而 `example.com` 则替换为您的主机。
|
设置 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
|
```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
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
# 🚀 GitHub Actions 的 SSH
|
# 🚀 GitHub Actions 的 SSH
|
||||||
|
|
||||||
[English](./README.md)
|
[English](./README.md) | [简体中文](./README.zh-cn.md)
|
||||||
[简体中文](./README.zh-cn.md)
|
|
||||||
|
|
||||||
[GitHub Action](https://github.com/features/actions) 用於執行遠端 SSH 命令。
|
[GitHub Action](https://github.com/features/actions) 用於執行遠端 SSH 命令。
|
||||||
|
|
||||||
@@ -44,8 +43,7 @@
|
|||||||
| proxy_cipher | 代理允許的加密算法 | |
|
| proxy_cipher | 代理允許的加密算法 | |
|
||||||
| proxy_use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
| proxy_use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
||||||
| script | 執行命令 | |
|
| script | 執行命令 | |
|
||||||
| script_file | 從文件中執行命令 | |
|
| script_path | 從文件中執行命令 | |
|
||||||
| script_stop | 在第一次失敗後停止腳本 | false |
|
|
||||||
| envs | 將環境變數傳遞給 shell 腳本 | |
|
| envs | 將環境變數傳遞給 shell 腳本 | |
|
||||||
| envs_format | 環境值傳遞的靈活配置 | |
|
| envs_format | 環境值傳遞的靈活配置 | |
|
||||||
| debug | 啟用調試模式 | false |
|
| debug | 啟用調試模式 | false |
|
||||||
@@ -60,19 +58,18 @@
|
|||||||
name: remote ssh command
|
name: remote ssh command
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: executing remote ssh commands using password
|
- name: executing remote ssh commands using password
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
uses: appleboy/ssh-action@v1.2.0
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST }}
|
host: ${{ secrets.HOST }}
|
||||||
username: ${{ secrets.USERNAME }}
|
username: ${{ secrets.USERNAME }}
|
||||||
password: ${{ secrets.PASSWORD }}
|
password: ${{ secrets.PASSWORD }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script: whoami
|
script: whoami
|
||||||
```
|
```
|
||||||
|
|
||||||
畫面輸出
|
畫面輸出
|
||||||
@@ -135,9 +132,9 @@ clip < ~/.ssh/id_ed25519
|
|||||||
|
|
||||||
**來自讀者的注意事項**: 根據您的 SSH 版本,您可能還需要進行以下更改:
|
**來自讀者的注意事項**: 根據您的 SSH 版本,您可能還需要進行以下更改:
|
||||||
|
|
||||||
* 將公鑰放在 `.ssh/authorized_keys2` 中
|
- 將公鑰放在 `.ssh/authorized_keys2` 中
|
||||||
* 將 `.ssh` 的權限更改為700
|
- 將 `.ssh` 的權限更改為 700
|
||||||
* 將 `.ssh/authorized_keys2` 的權限更改為640
|
- 將 `.ssh/authorized_keys2` 的權限更改為 640
|
||||||
|
|
||||||
### 如果你使用的是 OpenSSH
|
### 如果你使用的是 OpenSSH
|
||||||
|
|
||||||
@@ -214,7 +211,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||||||
username: ${{ secrets.USERNAME }}
|
username: ${{ secrets.USERNAME }}
|
||||||
key: ${{ secrets.KEY }}
|
key: ${{ secrets.KEY }}
|
||||||
port: ${{ secrets.PORT }}
|
port: ${{ secrets.PORT }}
|
||||||
script_path: scripts/script.sh
|
script_path: scripts/script.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 多台主機
|
#### 多台主機
|
||||||
@@ -287,37 +284,6 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||||||
|
|
||||||
_在 `env` 對象中,您需要將每個環境變量作為字符串傳遞,傳遞 `Integer` 數據類型或任何其他類型可能會產生意外結果。_
|
_在 `env` 對象中,您需要將每個環境變量作為字符串傳遞,傳遞 `Integer` 數據類型或任何其他類型可能會產生意外結果。_
|
||||||
|
|
||||||
#### 在第一次失敗後停止腳本
|
|
||||||
|
|
||||||
> ex: missing `abc` folder
|
|
||||||
|
|
||||||
```diff
|
|
||||||
- name: stop script if command error
|
|
||||||
uses: appleboy/ssh-action@v1.2.0
|
|
||||||
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` 連接遠程服務器?
|
#### 如何使用 `ProxyCommand` 連接遠程服務器?
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -383,7 +349,7 @@ Host FooServer
|
|||||||
|
|
||||||
設置 SSH 主機指紋驗證可以幫助防止中間人攻擊。在設置之前,運行以下命令以獲取 SSH 主機指紋。請記得將 `ed25519` 替換為您的適當金鑰類型(`rsa`、 `dsa`等),而 `example.com` 則替換為您的主機。
|
設置 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
|
```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
|
||||||
|
15
action.yml
15
action.yml
@@ -65,8 +65,6 @@ inputs:
|
|||||||
description: "Commands to be executed."
|
description: "Commands to be executed."
|
||||||
script_path:
|
script_path:
|
||||||
description: "Path to the file containing commands to be executed."
|
description: "Path to the file containing commands to be executed."
|
||||||
script_stop:
|
|
||||||
description: "Stop the script after the first failure."
|
|
||||||
envs:
|
envs:
|
||||||
description: "Environment variables to be passed to the shell script."
|
description: "Environment variables to be passed to the shell script."
|
||||||
envs_format:
|
envs_format:
|
||||||
@@ -77,6 +75,14 @@ inputs:
|
|||||||
description: "pass all environment variable to shell script."
|
description: "pass all environment variable to shell script."
|
||||||
request_pty:
|
request_pty:
|
||||||
description: "Request a pseudo-terminal from the server."
|
description: "Request a pseudo-terminal from the server."
|
||||||
|
capture_stdout:
|
||||||
|
description: "Capture the stdout of the commands."
|
||||||
|
default: "false"
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
stdout:
|
||||||
|
description: 'Standard output of the executed commands.'
|
||||||
|
value: ${{ steps.entrypoint.outputs.stdout }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -86,7 +92,8 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
GITHUB_ACTION_PATH: ${{ github.action_path }}
|
GITHUB_ACTION_PATH: ${{ github.action_path }}
|
||||||
- name: Run entrypoint.sh
|
- id: entrypoint
|
||||||
|
name: Run entrypoint.sh
|
||||||
run: entrypoint.sh
|
run: entrypoint.sh
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
@@ -113,7 +120,6 @@ runs:
|
|||||||
INPUT_COMMAND_TIMEOUT: ${{ inputs.command_timeout }}
|
INPUT_COMMAND_TIMEOUT: ${{ inputs.command_timeout }}
|
||||||
INPUT_SCRIPT: ${{ inputs.script }}
|
INPUT_SCRIPT: ${{ inputs.script }}
|
||||||
INPUT_SCRIPT_FILE: ${{ inputs.script_path }}
|
INPUT_SCRIPT_FILE: ${{ inputs.script_path }}
|
||||||
INPUT_SCRIPT_STOP: ${{ inputs.script_stop }}
|
|
||||||
INPUT_ENVS: ${{ inputs.envs }}
|
INPUT_ENVS: ${{ inputs.envs }}
|
||||||
INPUT_ENVS_FORMAT: ${{ inputs.envs_format }}
|
INPUT_ENVS_FORMAT: ${{ inputs.envs_format }}
|
||||||
INPUT_DEBUG: ${{ inputs.debug }}
|
INPUT_DEBUG: ${{ inputs.debug }}
|
||||||
@@ -124,6 +130,7 @@ runs:
|
|||||||
INPUT_PROXY_USE_INSECURE_CIPHER: ${{ inputs.proxy_use_insecure_cipher }}
|
INPUT_PROXY_USE_INSECURE_CIPHER: ${{ inputs.proxy_use_insecure_cipher }}
|
||||||
INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }}
|
INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }}
|
||||||
INPUT_SYNC: ${{ inputs.sync }}
|
INPUT_SYNC: ${{ inputs.sync }}
|
||||||
|
INPUT_CAPTURE_STDOUT: ${{ inputs.capture_stdout }}
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: "terminal"
|
icon: "terminal"
|
||||||
|
@@ -64,7 +64,14 @@ TARGET="${GITHUB_ACTION_PATH}/${CLIENT_BINARY}"
|
|||||||
echo "Will download ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
|
echo "Will download ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
|
||||||
curl -fsSL --retry 5 --keepalive-time 2 "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o ${TARGET}
|
curl -fsSL --retry 5 --keepalive-time 2 "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o ${TARGET}
|
||||||
chmod +x ${TARGET}
|
chmod +x ${TARGET}
|
||||||
|
|
||||||
echo "======= CLI Version ======="
|
echo "======= CLI Version ======="
|
||||||
sh -c "${TARGET} --version" # print version
|
sh -c "${TARGET} --version" # print version
|
||||||
echo "==========================="
|
echo "==========================="
|
||||||
sh -c "${TARGET} $*" # run the command
|
if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then
|
||||||
|
echo 'stdout<<EOF' >> $GITHUB_OUTPUT # use heredoc for multiline output
|
||||||
|
sh -c "${TARGET} $*" | tee -a $GITHUB_OUTPUT # run the command
|
||||||
|
echo 'EOF' >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
sh -c "${TARGET} $*" # run the command
|
||||||
|
fi
|
||||||
|
Reference in New Issue
Block a user