SCP with key and password
This commit is contained in:
parent
6e2f024bdc
commit
e82d84dcdd
8
.github/workflows/cicd.yml
vendored
8
.github/workflows/cicd.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
uses: srueda99/scp-action@v1
|
uses: srueda99/scp-action@v1
|
||||||
with:
|
with:
|
||||||
port: 22
|
port: 22
|
||||||
host:
|
host: ${{ secrets.SERVER_ADDRESS }}
|
||||||
target: "/home"
|
destination: "/home/${{ secrets.SERVER_USERNAME }}/"
|
||||||
username:
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
key:
|
key: ${{ secrets.SERVER_KEY }}
|
73
README.md
Normal file
73
README.md
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# SCP ACTION
|
||||||
|
## By SRUEDA99
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
This action to copy the files from your repository to a remote server using **SCP** (Secure Copy Protocol).
|
||||||
|
|
||||||
|
## How to use it
|
||||||
|
You must give:
|
||||||
|
- The `host` which is the public address or the public DNS of the destination server.
|
||||||
|
- The `username` that will be used in the remote server.
|
||||||
|
- The `destination` folder, where the content will be copied.
|
||||||
|
- The `password` for the user or the private `key` in case the connection is based on SSH keys.
|
||||||
|
Optional:
|
||||||
|
- The `origin` folder is set by default as _"./*"_ but you can also specify it.
|
||||||
|
- The `port` is set as **22** by default, you can also specify another one.
|
||||||
|
- The `passphrase` if necessary.
|
||||||
|
```
|
||||||
|
**Important**
|
||||||
|
Use Github secrets to give these parameters.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
**With password**
|
||||||
|
```
|
||||||
|
name: Copy using password
|
||||||
|
uses: srueda99/scp-action@v1
|
||||||
|
with:
|
||||||
|
port: 22
|
||||||
|
host: ${{ secrets.SERVER_ADDRESS }}
|
||||||
|
destination: "/home/${{ secrets.SERVER_USERNAME }}/"
|
||||||
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
|
password: ${{ secrets.SERVER_PASSWORD }}
|
||||||
|
```
|
||||||
|
|
||||||
|
**With key**
|
||||||
|
```
|
||||||
|
name: Copy using key
|
||||||
|
uses: srueda99/scp-action@v1
|
||||||
|
with:
|
||||||
|
port: 22
|
||||||
|
host: ${{ secrets.SERVER_ADDRESS }}
|
||||||
|
destination: "/home/${{ secrets.SERVER_USERNAME }}/"
|
||||||
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
|
key: ${{ secrets.SERVER_KEY }}
|
||||||
|
```
|
||||||
|
|
||||||
|
**With origin folder**
|
||||||
|
```
|
||||||
|
name: Copy using password
|
||||||
|
uses: srueda99/scp-action@v1
|
||||||
|
with:
|
||||||
|
port: 22
|
||||||
|
host: ${{ secrets.SERVER_ADDRESS }}
|
||||||
|
origin: "/home/*"
|
||||||
|
destination: "/home/${{ secrets.SERVER_USERNAME }}/"
|
||||||
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
|
password: ${{ secrets.SERVER_PASSWORD }}
|
||||||
|
```
|
||||||
|
|
||||||
|
**With passphrase**
|
||||||
|
```
|
||||||
|
name: Copy using key
|
||||||
|
uses: srueda99/scp-action@v1
|
||||||
|
with:
|
||||||
|
port: 22
|
||||||
|
host: ${{ secrets.SERVER_ADDRESS }}
|
||||||
|
destination: "/home/${{ secrets.SERVER_USERNAME }}/"
|
||||||
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
|
key: ${{ secrets.SERVER_KEY }}
|
||||||
|
passphrase: ${{ secrets.SERVER_PASSPHRASE }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Enjoy it!!
|
31
action.yml
31
action.yml
@ -10,18 +10,22 @@ inputs:
|
|||||||
host:
|
host:
|
||||||
description: 'IP Address or DNS of your target host'
|
description: 'IP Address or DNS of your target host'
|
||||||
# $3
|
# $3
|
||||||
target:
|
origin:
|
||||||
description: 'Destination route folder'
|
description: 'Source route folder'
|
||||||
|
default: "./*"
|
||||||
# $4
|
# $4
|
||||||
|
destination:
|
||||||
|
description: 'Destination route folder'
|
||||||
|
# $5
|
||||||
username:
|
username:
|
||||||
description: 'User for remote connection'
|
description: 'User for remote connection'
|
||||||
# $5
|
# $6
|
||||||
password:
|
password:
|
||||||
description: 'Password for the user'
|
description: 'Password for the user'
|
||||||
# $6
|
# $7
|
||||||
key:
|
key:
|
||||||
description: 'Private SSH key'
|
description: 'Private SSH key'
|
||||||
# $7
|
# $8
|
||||||
passphrase:
|
passphrase:
|
||||||
description: 'Passphrase for SSH key'
|
description: 'Passphrase for SSH key'
|
||||||
outputs:
|
outputs:
|
||||||
@ -30,11 +34,12 @@ outputs:
|
|||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
args:
|
# args:
|
||||||
- ${{ inputs.port }}
|
# - ${{ inputs.port }}
|
||||||
- ${{ inputs.host }}
|
# - ${{ inputs.host }}
|
||||||
- ${{ inputs.target }}
|
# - ${{ inputs.origin }}
|
||||||
- ${{ inputs.username }}
|
# - ${{ inputs.destination }}
|
||||||
- ${{ inputs.password }}
|
# - ${{ inputs.username }}
|
||||||
- ${{ inputs.key }}
|
# - ${{ inputs.password }}
|
||||||
- ${{ inputs.passphrase }}
|
# - ${{ inputs.key }}
|
||||||
|
# - ${{ inputs.passphrase }}
|
@ -1,2 +1,12 @@
|
|||||||
#!/bin/sh -l
|
#!/bin/sh -l
|
||||||
|
|
||||||
|
if [[ "$INPUT_KEY" ]]; then
|
||||||
|
echo -e "${INPUT_KEY}" > key
|
||||||
|
chmod 400 key
|
||||||
|
echo "Trying SCP process with SSH key"
|
||||||
|
scp -P $INPUT_PORT -o StrictHostKeyChecking=no -i key $INPUT_ORIGIN "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION"
|
||||||
|
else
|
||||||
|
echo "Trying SCP process with password"
|
||||||
|
sshpass -p $INPUT_PASSWORD scp -P $INPUT_PORT -o StrictHostKeyChecking=no $INPUT_ORIGIN "$INPUT_USERNAME"@"$INPUT_HOST":"$INPUT_DESTINATION"
|
||||||
|
fi
|
||||||
|
echo "Files successfully copied"
|
Loading…
Reference in New Issue
Block a user