2019-09-18 19:39:54 +08:00
# Install SSH key
2019-09-19 06:10:37 +08:00
[![Build][image-build]][link-build]
2019-12-31 09:56:18 +08:00
[![Windows][image-verify-windows]][link-verify-windows]
[![macOS][image-verify-macos]][link-verify-macos]
2019-12-31 12:23:55 +08:00
[![Ubuntu][image-verify-ubuntu]][link-verify-ubuntu]
[![Ubuntu 16.04][image-verify-ubuntu1604]][link-verify-ubuntu1604]
2019-09-19 06:05:03 +08:00
[![Release][image-release]][link-release]
[![License][image-license]][link-license]
2019-09-18 19:47:08 +08:00
This action installs SSH key into `~/.ssh` .
2019-09-18 19:39:54 +08:00
2019-09-22 14:30:47 +08:00
Useful for SCP, SFTP, and `rsync` over SSH in deployment script.
2019-09-18 19:39:54 +08:00
2019-12-31 12:23:55 +08:00
**Works on all [virtual environment ](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources ) -- Windows, macOS, Ubuntu and Ubuntu 16.04.**
2019-09-18 19:39:54 +08:00
## Usage
Add your SSH key to your product secrets by clicking `Settings` - `Secrets` - `Add a new secret` beforehand.
```yaml
runs-on: ubuntu-latest
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v1
with:
2019-09-22 06:58:50 +08:00
private-key: ${{ secrets.SSH_KEY }}
2019-09-18 21:55:24 +08:00
name: id_rsa # optional
2019-12-22 18:01:05 +08:00
known-hosts: ${{ secrets.KNOWN_HOSTS }} # known_hosts; optional
config: ${{ secrets.CONFIG }} # ssh_config; optional
2019-09-18 19:39:54 +08:00
- name: Install packages
run: apt install openssh-client rsync
- name: rsync over ssh
2019-09-29 12:18:35 +08:00
run: rsync ./foo/ user@remote:bar/
2019-09-18 19:39:54 +08:00
```
See [Workflow syntax for GitHub Actions ](https://help.github.com/en/articles/workflow-syntax-for-github-actions ) for details.
2019-12-30 07:24:22 +08:00
### Install multiple keys
If you want to install multiple keys, call this action multiple times.
It is useful for port forwarding.
2020-01-18 07:31:30 +08:00
**NOTE:** When this action is called multiple times, **the contents of `known-hosts` and `config` will be appended** . But `private-key` must be saved as different name, by using `name` option.
2019-12-30 07:24:22 +08:00
```yaml
runs-on: ubuntu-latest
steps:
- name: Install SSH key of bastion
uses: shimataro/ssh-key-action@v1
with:
private-key: ${{ secrets.SSH_KEY_OF_BASTION }}
name: id_rsa-bastion
known-hosts: ${{ secrets.KNOWN_HOSTS_OF_BASTION }}
config: |
Host bastion
HostName xxx.xxx.xxx.xxx
User user-of-bastion
IdentityFile ~/.ssh/id_rsa-bastion
- name: Install SSH key of target
uses: shimataro/ssh-key-action@v1
with:
private-key: ${{ secrets.SSH_KEY_OF_TARGET }}
name: id_rsa-target
known-hosts: ${{ secrets.KNOWN_HOSTS_OF_TARGET }} # will be appended!
config: | # will be appended!
Host target
HostName yyy.yyy.yyy.yyy
User user-of-target
IdentityFile ~/.ssh/id_rsa-target
ProxyCommand ssh -W %h:%p bastion
- name: Install packages
run: apt install openssh-client
- name: SCP via port-forwarding
run: scp ./foo/ target:bar/
```
2019-09-18 19:39:54 +08:00
## License
The scripts and documentation in this project are released under the [MIT License ](LICENSE )
2019-09-19 06:05:03 +08:00
## Changelog
See [CHANGELOG.md ](CHANGELOG.md ).
2019-09-19 06:10:37 +08:00
[image-build]: https://github.com/shimataro/ssh-key-action/workflows/Build/badge.svg
[link-build]: https://github.com/shimataro/ssh-key-action
2019-12-31 09:56:18 +08:00
[image-verify-windows]: https://github.com/shimataro/ssh-key-action/workflows/Windows/badge.svg
[image-verify-macos]: https://github.com/shimataro/ssh-key-action/workflows/macOS/badge.svg
2019-12-31 12:23:55 +08:00
[image-verify-ubuntu]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu/badge.svg
[image-verify-ubuntu1604]: https://github.com/shimataro/ssh-key-action/workflows/Ubuntu%2016.04/badge.svg
2019-12-31 09:56:18 +08:00
[link-verify-windows]: https://github.com/shimataro/ssh-key-action
[link-verify-macos]: https://github.com/shimataro/ssh-key-action
2019-12-31 12:23:55 +08:00
[link-verify-ubuntu]: https://github.com/shimataro/ssh-key-action
[link-verify-ubuntu1604]: https://github.com/shimataro/ssh-key-action
2019-09-19 06:05:03 +08:00
[image-release]: https://img.shields.io/github/release/shimataro/ssh-key-action.svg
[link-release]: https://github.com/shimataro/ssh-key-action/releases
[image-license]: https://img.shields.io/github/license/shimataro/ssh-key-action.svg
[link-license]: ./LICENSE