ssh: review ssh copy and run actions, add port variable
This commit is contained in:
1 parent
b27762c0d3
commit
4878a62fb3
2 files changed
+41
-20
No files matched your search
+21
-11
@@ -16,26 +16,36 @@ inputs:
|
|||||||
target:
|
target:
|
||||||
description: destination path on remote
|
description: destination path on remote
|
||||||
required: true
|
required: true
|
||||||
|
port:
|
||||||
|
description: SSH port
|
||||||
|
required: false
|
||||||
|
default: "22"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: setup ssh
|
- name: setup ssh
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ inputs.key }}
|
||||||
|
HOST: ${{ inputs.host }}
|
||||||
|
PORT: ${{ inputs.port }}
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ inputs.key }}" > ~/.ssh/id_rsa
|
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts
|
||||||
- name: add remote host to known_hosts
|
chmod 600 ~/.ssh/known_hosts
|
||||||
shell: bash
|
|
||||||
run: ssh-keyscan -H "${{ inputs.host }}" >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: install rsync
|
|
||||||
shell: bash
|
|
||||||
run: sudo apt-get update && sudo apt-get install -y rsync
|
|
||||||
|
|
||||||
- name: rsync directory
|
- name: rsync directory
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
SRC: ${{ inputs.source }}
|
||||||
|
HOST: ${{ inputs.host }}
|
||||||
|
USER: ${{ inputs.user }}
|
||||||
|
TARGET: ${{ inputs.target }}
|
||||||
|
PORT: ${{ inputs.port }}
|
||||||
run: |
|
run: |
|
||||||
rsync -rlptz --delete ${{ inputs.source }} ${{ inputs.user }}@${{ inputs.host }}:${{ inputs.target }}
|
set -euo pipefail
|
||||||
|
rsync -rlptz --delete -e "ssh -p $PORT" "$SRC" "$USER@$HOST:$TARGET"
|
||||||
+20
-9
@@ -13,24 +13,35 @@ inputs:
|
|||||||
script:
|
script:
|
||||||
description: commands to run via SSH
|
description: commands to run via SSH
|
||||||
required: true
|
required: true
|
||||||
|
port:
|
||||||
|
description: SSH port
|
||||||
|
required: false
|
||||||
|
default: "22"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: setup ssh
|
- name: setup ssh
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ inputs.key }}
|
||||||
|
HOST: ${{ inputs.host }}
|
||||||
|
PORT: ${{ inputs.port }}
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ inputs.key }}" > ~/.ssh/id_rsa
|
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts
|
||||||
- name: add remote host to known_hosts
|
chmod 600 ~/.ssh/known_hosts
|
||||||
shell: bash
|
|
||||||
run: ssh-keyscan -H "${{ inputs.host }}" >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: run on docker host
|
- name: run on docker host
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
HOST: ${{ inputs.host }}
|
||||||
|
USER: ${{ inputs.user }}
|
||||||
|
PORT: ${{ inputs.port }}
|
||||||
|
SCRIPT: ${{ inputs.script }}
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ inputs.user }}@${{ inputs.host }} << 'EOF'
|
set -euo pipefail
|
||||||
${{ inputs.script }}
|
ssh -p "$PORT" "$USER@$HOST" bash -s <<< "$SCRIPT"
|
||||||
EOF
|
|
||||||
Reference in new issue
Block a user