26 Commits

Author SHA1 Message Date
f9010ff7f1 docs: remove FAQ section
Some checks failed
remote ssh command / Build (push) Failing after 4s
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-07-29 21:24:53 +08:00
e1116226a0 updated readme envs option in example (#172) 2022-07-29 21:19:55 +08:00
a8d82ec39b Switch to appleboy/drone-ssh:1.6.4 (#171) 2022-07-29 21:19:21 +08:00
f82e23f1a3 updated README to include OpenSSH comments (#161) 2022-07-29 20:58:30 +08:00
ed1f3fc7c1 docs: problem with an EC2 instance
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-07-29 20:54:56 +08:00
dce9d565de Update FUNDING.yml 2022-05-28 16:42:12 +08:00
ea5c23a2b5 Enable Sponsor Button 2022-05-26 09:02:47 +08:00
c732d38392 chore: Add global environments
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-02-28 07:08:00 +08:00
ba1d4fb0eb chore(CI): show secrets.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-02-06 16:12:37 +08:00
c7671d858f docs: update format
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2022-02-06 15:15:00 +08:00
1a8b3784ea Document setup of SSH host fingerprint validation (#120) 2021-05-15 23:05:07 +08:00
29007ce6fb chore: update ssh key part
part from https://github.com/appleboy/ssh-action/issues/80
2021-05-09 21:11:10 +08:00
e59c0ee97a docu(restructure): update readme structure and add ed25519 ssh key instructions (#113) 2021-04-04 05:59:44 +08:00
c7104ccac4 chore: add ED25519 example 2021-03-06 23:00:38 +08:00
63dd9dd662 chore: replace ADD with COPY 2021-02-13 10:55:57 +08:00
61e292b601 docs: fix typo
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-11-17 10:54:18 +08:00
1d1b21ca96 Support multiple host with different port (#94)
Some checks failed
remote ssh command / Build (push) Failing after 3s
2020-11-17 10:51:06 +08:00
9fb11fb1f5 chore(host): support multiple port
https://github.com/appleboy/ssh-action/issues/85

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-11-17 10:20:18 +08:00
fd39ef0f18 Update README.md 2020-10-31 07:03:29 +08:00
ffff33f8fe docs: update readme 2020-08-13 01:06:27 +08:00
8bd4933b73 Instructions to use SSH Key (#77) 2020-08-13 01:03:55 +08:00
bf84735fa9 fix: Multiline SSH commands interpreted as single lines
Some checks failed
remote ssh command / Build (push) Failing after 5s
fix https://github.com/appleboy/ssh-action/issues/75
2020-08-08 15:39:00 +08:00
d09b6e0211 chore: try the latest version 2020-08-08 15:34:38 +08:00
3ac4675689 chore: Add Multiline SSH commands interpreted as single lines 2020-08-08 12:26:01 +08:00
269a4479eb chore: Multiline SSH commands interpreted as single lines 2020-08-03 22:15:09 +08:00
a2f91cbad1 (info) Pass env variable as string (#69) 2020-07-08 16:46:24 +08:00
4 changed files with 268 additions and 46 deletions

13
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: ssh-action
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.paypal.me/appleboy46']

View File

@ -1,5 +1,10 @@
name: remote ssh command name: remote ssh command
on: [push] on: [push]
env:
FOO: "BAR"
BAR: "FOO"
jobs: jobs:
build: build:
@ -39,6 +44,7 @@ jobs:
ls -al ls -al
# - name: stop script if command error # - name: stop script if command error
# if: always()
# uses: ./ # uses: ./
# with: # with:
# host: ${{ secrets.HOST }} # host: ${{ secrets.HOST }}
@ -70,16 +76,18 @@ jobs:
FOO: "BAR" FOO: "BAR"
BAR: "FOO" BAR: "FOO"
SHA: ${{ github.sha }} SHA: ${{ github.sha }}
PORT: ${{ secrets.PORT }}
with: with:
host: ${{ secrets.HOST }} host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }} username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }} key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }} port: ${{ secrets.PORT }}
envs: FOO,BAR,SHA envs: FOO,BAR,SHA,PORT
script: | script: |
echo "I am $FOO, thanks" echo "I am $FOO, thanks"
echo "I am $BAR, thanks" echo "I am $BAR, thanks"
echo "sha: $SHA" echo "sha: $SHA"
echo "port: $PORT"
- name: ssh key passphrase - name: ssh key passphrase
uses: ./ uses: ./
@ -100,5 +108,44 @@ jobs:
username: ${{ secrets.USERNAME }} username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }} password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }} port: ${{ secrets.PORT }}
script: whoami script: |
ls \
-lah
use_insecure_cipher: true use_insecure_cipher: true
# https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
- name: Multiline SSH commands interpreted as single lines
uses: ./
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script_stop: true
script: |
ls \
-lah
use_insecure_cipher: true
# https://github.com/appleboy/ssh-action/issues/85
- name: Deployment to multiple hosts with different ports
uses: ./
with:
host: "${{ secrets.HOST }}:${{ secrets.PORT }}"
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: 1024
script_stop: true
script: |
ls \
-lah
use_insecure_cipher: true
- name: SSH ED25519 Private Key
uses: ./
with:
host: ${{ secrets.TUNNEL_HOST }}
username: ${{ secrets.TUNNEL_USERNAME }}
key: ${{ secrets.ID_ED25519 }}
port: ${{ secrets.TUNNEL_PORT }}
script: whoami

View File

@ -1,5 +1,5 @@
FROM appleboy/drone-ssh:1.6.1-linux-amd64 FROM appleboy/drone-ssh:1.6.4-linux-amd64
ADD entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

246
README.md
View File

@ -8,6 +8,42 @@
**Important**: Only support **Linux** [docker](https://www.docker.com/) container. **Important**: Only support **Linux** [docker](https://www.docker.com/) container.
## Input variables
See [action.yml](./action.yml) for more detailed information.
* `host` - ssh host
* `port` - ssh port, default is `22`
* `username` - ssh username
* `password` - ssh password
* `passphrase` - the passphrase is usually to encrypt the private key
* `sync` - synchronous execution if multiple hosts, default is false
* `timeout` - timeout for ssh to remote host, default is `30s`
* `command_timeout` - timeout for ssh command, default is `10m`
* `key` - content of ssh private key. ex raw content of ~/.ssh/id_rsa
* `key_path` - path of ssh private key
* `fingerprint` - fingerprint SHA256 of the host public key, default is to skip verification
* `script` - execute commands
* `script_stop` - stop script after first failure
* `envs` - pass environment variable to shell script
* `debug` - enable debug mode
* `use_insecure_cipher` - include more ciphers with use_insecure_cipher (see [#56](https://github.com/appleboy/ssh-action/issues/56))
* `cipher` - the allowed cipher algorithms. If unspecified then a sensible
SSH Proxy Setting:
* `proxy_host` - proxy host
* `proxy_port` - proxy port, default is `22`
* `proxy_username` - proxy username
* `proxy_password` - proxy password
* `proxy_passphrase` - the passphrase is usually to encrypt the private key
* `proxy_timeout` - timeout for ssh to proxy host, default is `30s`
* `proxy_key` - content of ssh proxy private key.
* `proxy_key_path` - path of ssh proxy private key
* `proxy_fingerprint` - fingerprint SHA256 of the proxy host public key, default is to skip verification
* `proxy_use_insecure_cipher` - include more ciphers with use_insecure_cipher (see [#56](https://github.com/appleboy/ssh-action/issues/56))
* `proxy_cipher` - the allowed cipher algorithms. If unspecified then a sensible
## Usage ## Usage
Executing remote ssh commands. Executing remote ssh commands.
@ -43,45 +79,114 @@ out: ***
============================================== ==============================================
``` ```
## Input variables ### Setting up a SSH Key
See [action.yml](./action.yml) for more detailed information. 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:
* host - ssh host <details>
* port - ssh port, default is `22` <summary>rsa</summary>
* username - ssh username <p>
* password - ssh password
* passphrase - the passphrase is usually to encrypt the private key
* sync - synchronous execution if multiple hosts, default is false
* timeout - timeout for ssh to remote host, default is `30s`
* command_timeout - timeout for ssh command, default is `10m`
* key - content of ssh private key. ex raw content of ~/.ssh/id_rsa
* key_path - path of ssh private key
* fingerprint - fingerprint SHA256 of the host public key, default is to skip verification
* script - execute commands
* script_stop - stop script after first failure
* envs - pass environment variable to shell script
* debug - enable debug mode
* use_insecure_cipher - include more ciphers with use_insecure_cipher (see [#56](https://github.com/appleboy/ssh-action/issues/56))
* cipher - the allowed cipher algorithms. If unspecified then a sensible
SSH Proxy Setting: ```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```
* proxy_host - proxy host </p>
* proxy_port - proxy port, default is `22` </details>
* proxy_username - proxy username
* proxy_password - proxy password <details>
* proxy_passphrase - the passphrase is usually to encrypt the private key <summary>ed25519</summary>
* proxy_timeout - timeout for ssh to proxy host, default is `30s` <p>
* proxy_key - content of ssh proxy private key.
* proxy_key_path - path of ssh proxy private key ```bash
* proxy_fingerprint - fingerprint SHA256 of the proxy host public key, default is to skip verification ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
* proxy_use_insecure_cipher - include more ciphers with use_insecure_cipher (see [#56](https://github.com/appleboy/ssh-action/issues/56)) ```
* proxy_cipher - the allowed cipher algorithms. If unspecified then a sensible
</p>
</details>
Add newly generated key into Authorized keys. Read more about authorized keys [here](https://www.ssh.com/ssh/authorized_keys/).
<details>
<summary>rsa</summary>
<p>
```bash
cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
```
</p>
</details>
<details>
<summary>ed25519</summary>
<p>
```bash
cat .ssh/id_ed25519.pub | ssh b@B 'cat >> .ssh/authorized_keys'
```
</p>
</details>
Copy Private Key content and paste in Github Secrets.
<details>
<summary>rsa</summary>
<p>
```bash
clip < ~/.ssh/id_rsa
```
</p>
</details>
<details>
<summary>ed25519</summary>
<p>
```bash
clip < ~/.ssh/id_ed25519
```
</p>
</details>
See the detail information about [SSH login without password](http://www.linuxproblem.org/art_9.html).
**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
### If you are using OpenSSH
If you are currently using OpenSSH and are getting the following error:
```bash
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey]
```
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 could use this instead of rsa if needed:
```bash
ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
```
### Example ### Example
Executing remote ssh commands using password. #### Executing remote ssh commands using password
```yaml ```yaml
- name: executing remote ssh commands using password - name: executing remote ssh commands using password
@ -94,7 +199,7 @@ Executing remote ssh commands using password.
script: whoami script: whoami
``` ```
Using private key #### Using private key
```yaml ```yaml
- name: executing remote ssh commands using ssh key - name: executing remote ssh commands using ssh key
@ -107,7 +212,7 @@ Using private key
script: whoami script: whoami
``` ```
Multiple Commands #### Multiple Commands
```yaml ```yaml
- name: multiple command - name: multiple command
@ -124,7 +229,7 @@ Multiple Commands
![result](./images/output-result.png) ![result](./images/output-result.png)
Multiple Hosts #### Multiple Hosts
```diff ```diff
- name: multiple host - name: multiple host
@ -140,7 +245,22 @@ Multiple Hosts
ls -al ls -al
``` ```
Synchronous execution on multiple hosts #### Multiple hosts with different port
```diff
- name: multiple host
uses: appleboy/ssh-action@master
with:
- host: "foo.com"
+ host: "foo.com:1234,bar.com:5678"
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
whoami
ls -al
```
#### Synchronous execution on multiple hosts
```diff ```diff
- name: multiple host - name: multiple host
@ -156,7 +276,7 @@ Synchronous execution on multiple hosts
ls -al ls -al
``` ```
Pass environment variable to shell script #### Pass environment variable to shell script
```diff ```diff
- name: pass environment - name: pass environment
@ -170,14 +290,18 @@ Pass environment variable to shell script
username: ${{ secrets.USERNAME }} username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }} key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }} port: ${{ secrets.PORT }}
+ envs: FOO,BAR + envs: FOO,BAR,SHA
script: | script: |
echo "I am $FOO" echo "I am $FOO"
echo "I am $BAR" echo "I am $BAR"
echo "sha: $SHA" echo "sha: $SHA"
``` ```
Stop script after first failure. ex: missing `abc` folder _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 ```diff
- name: stop script if command error - name: stop script if command error
@ -206,7 +330,7 @@ err: mkdir: cannot create directory abc/def: No such file or directory
##[error]Docker run failed with exit code 1 ##[error]Docker run failed with exit code 1
``` ```
How to connect remote server using `ProxyCommand`? #### How to connect remote server using `ProxyCommand`?
```bash ```bash
+--------+ +----------+ +-----------+ +--------+ +----------+ +-----------+
@ -230,7 +354,7 @@ Host FooServer
ProxyCommand ssh -q -W %h:%p Jumphost ProxyCommand ssh -q -W %h:%p Jumphost
``` ```
How to convert to YAML format of GitHubActions. #### How to convert to YAML format of GitHubActions
```diff ```diff
- name: ssh proxy command - name: ssh proxy command
@ -249,7 +373,11 @@ How to convert to YAML format of GitHubActions.
ls -al ls -al
``` ```
Protecting a Private Key. The purpose of the passphrase is usually to encrypt the private key. This makes the key file by itself useless to an attacker. It is not uncommon for files to leak from backups or decommissioned hardware, and hackers commonly exfiltrate files from compromised systems. #### Protecting a Private Key
The purpose of the passphrase is usually to encrypt the private key.
This makes the key file by itself useless to an attacker.
It is not uncommon for files to leak from backups or decommissioned hardware, and hackers commonly exfiltrate files from compromised systems.
```diff ```diff
- name: ssh key passphrase - name: ssh key passphrase
@ -264,3 +392,37 @@ Protecting a Private Key. The purpose of the passphrase is usually to encrypt th
whoami whoami
ls -al ls -al
``` ```
#### Using host fingerprint verification
Setting up SSH host fingerprint verification can help to prevent Person-in-the-Middle attacks. Before setting this up, run the command below to get your SSH host fingerprint. Remember to replace `ed25519` with your appropriate key type (`rsa`, `dsa`, etc.) that your server is using and `example.com` with your host.
In modern OpenSSH releases, the _default_ key types to be fetched are `rsa` (since version 5.1), `ecdsa` (since version 6.0), and `ed25519` (since version 6.7).
```sh
ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' ' -f2
```
Now you can adjust you config:
```diff
- name: ssh key passphrase
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
+ fingerprint: ${{ secrets.FINGERPRINT }}
script: |
whoami
ls -al
```
## Contributing
We would love for you to contribute to `appleboy/ssh-action`, pull requests are welcome!
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)