|
| 1 | +#!/bin/bash -eu |
| 2 | +# -e: Exit immediately if a command exits with a non-zero status. |
| 3 | +# -u: Treat unset variables as an error when substituting. |
| 4 | + |
| 5 | +# This installs an SSH private/public key pair on the build system, |
| 6 | +# so ssh can connect to remote servers without password. |
| 7 | +# Important: for passwordless connection to succeed, our public key must be |
| 8 | +# manually authorized on the remote server. |
| 9 | + |
| 10 | +# Our private key is the critical security component, it must remain secret. |
| 11 | +# We store it in the SSH_ID environment variable in Travis CI project settings. |
| 12 | +# As environment variables can only contain text, our key files are transformed |
| 13 | +# like this: tar, xz, base64. Then then can be decoded here. This is safe as |
| 14 | +# Travis CI never shows the contents of secure variables. |
| 15 | + |
| 16 | +# To generate the contents of the SSH_ID variable: |
| 17 | +# Be sure to be in an empty, temporary directory. |
| 18 | +# |
| 19 | +# mkdir .ssh |
| 20 | +# ssh-keygen -t rsa -b 4096 -C travis-ci.org/$USER/$PROJECT -N '' -f .ssh/id_rsa |
| 21 | +# tar Jcvf id.tar.xz .ssh |
| 22 | +# base64 -w 0 id.tar.xz |
| 23 | +# |
| 24 | +# Select the resulting encoded text (several lines) to copy it to the clipboard. |
| 25 | +# Then go to the Travis CI project settings: |
| 26 | +# https://travis-ci.org/$USER/$PROJECT/settings |
| 27 | +# Create a new environment variable named SSH_ID, and paste the value. |
| 28 | +# The script below will recreate the key files from that variable contents. |
| 29 | + |
| 30 | +if [ -z ${SSH_ID+x} ] |
| 31 | +then |
| 32 | + echo "error: SSH_ID is undefined" >&2 |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +echo $SSH_ID | base64 -d | tar -C ~ -Jx |
| 37 | + |
| 38 | +ls -l ~/.ssh |
0 commit comments