Skip to content

Instantly share code, notes, and snippets.

@qoomon
Last active August 6, 2023 04:59
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save qoomon/c57b0dc866221d91704ffef25d41adcf to your computer and use it in GitHub Desktop.
Save qoomon/c57b0dc866221d91704ffef25d41adcf to your computer and use it in GitHub Desktop.
Setup GitHub Deploy Keys For Travis

Setup Travis Deploy (macOS)

see Travis documentation

gem install travis

ssh-keygen -t rsa -b 4096 -f 'github_deploy_key' -N ''

cat github_deploy_key.pub

copy public key and set as a deploy key on github e.g https://github.com/<USER>/<REPOSITORY>/settings/keys

travis login --org --auto

travis encrypt-file 'github_deploy_key'

git add 'github_deploy_key.enc'

add openssl line to before_install stage in your .travis.yml

  • replace $encrypted_xxxxxxxxxxxx_key and $encrypted_xxxxxxxxxxxx_iv, see output of travis encrypt-file
before_install:
  - >-
    openssl aes-256-cbc 
    -K $encrypted_xxxxxxxxxxxx_key 
    -iv $encrypted_xxxxxxxxxxxx_iv 
    -in github_deploy_key.enc 
    -out github_deploy_key 
    -d
  - chmod 600 github_deploy_key
  - eval $(ssh-agent -s)
  - ssh-add github_deploy_key

git add '.travis.yml'

git commit -m 'chore: add github deploy key'

git push

@Regenhardt
Copy link

I tried this on windows 10, haven't got gem or pbcopy. WSL didnn't work either. What do I need here? Linux? Some other application I haven't got?

@pablen
Copy link

pablen commented Mar 21, 2019

@Regenhardt, follow these instructions to install Travis CLI https://github.com/travis-ci/travis.rb#windows
Regarding pbcopy, it's just to copy the key to your clipboard, you can omit it and copy it by hand.

@betteridiot
Copy link

For the sake of posterity, users that are on a Windows Subsystem for Linux (WSL), you can use cat <filename> | clip.exe to copy to clipboard

@sodacrackers
Copy link

What is encrypted_xxxxxxxxxxxx_key and where does it come from?

@qoomon
Copy link
Author

qoomon commented Oct 23, 2019

@sodacrackers you will find the xxxxxxxxxxxx value within the output of travis encrypt-file 'github_deploy_key'

@martinacantaro
Copy link

Hi, thanks for the step-by-step.

I followed it and I got this error from Travis:

The command "openssl aes-256-cbc -K $encrypted_xxxxx_key -iv $encrypted_xxxxx_iv -in travis_deploy.enc -out travis_deploy -d" failed and exited with 1 during .

What might be the problem?

@qoomon
Copy link
Author

qoomon commented Feb 12, 2020

@martinacantaro may have look at Travis documentation

you may add -verbose flag to openssl command to get some debug output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment