Skip to content

Instantly share code, notes, and snippets.

@pataruco
Last active February 19, 2024 11:19
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pataruco/91b6cda6b02b61b3bcd2bbbfaa963fd9 to your computer and use it in GitHub Desktop.
Save pataruco/91b6cda6b02b61b3bcd2bbbfaa963fd9 to your computer and use it in GitHub Desktop.

GitHub pages deployment using SSH keys

  1. Create a GitHub workflow file;

    mkdir .github
    mkdir .github/worflows
    touch ci.yml
  2. Inside the file paste the updated steps for GitHub SSH action and Deploy to GitHub Pages

    name: Deploy
    on:
    push:
     tags:
       - 'GA*'
    # ...
    - name: Install SSH Client 🔑
      uses: webfactory/ssh-agent@v0.7.0
      with:
        ssh-private-key: ${{ secrets.DEPLOY_KEY }}
    
    - name: Deploy 🚀
      uses: JamesIves/github-pages-deploy-action@v4
      with:
        BASE_BRANCH: master
        BRANCH: gh-pages
        CLEAN: true
        FOLDER: .
        SSH: true
    # ...
  3. Create a SSH keys on this folder

    ssh-keygen -t rsa -b 4096 -C <YOUR_EMAIL>
  4. When it promted for Enter file in which to save the key change the name of the file, e.g: repo-name

    $ Generating public/private rsa key pair.
    $ Enter file in which to save the key (/Users/username/.ssh/id_rsa): repo-name
    $ Enter passphrase (empty for no passphrase):
    $ Enter same passphrase again:
  5. Copy secret SSK key:

    cat repo-name | pbcopy
  6. Create a DEPLOY_KEY GitHub secret on your repo: Settings > Secrets > New secret and paste the secret SSH key

  7. Copy public SSK key

    cat repo-name.pub | pbcopy
  8. Create a deploy key on your GitHub repo: Settings > Deploy keys > Add deploy key and paste the public secret key

  9. 🚀

@erwanvivien
Copy link

Very helpful !

@Dovineowuor
Copy link

This is great and very helpfull

@bmorrall
Copy link

Thanks very much for this, saved me a ton of time.

To save the next person even more time: I needed to change webfactory/ssh-agent@v0.4.0 to webfactory/ssh-agent@v0.7.0

@pataruco
Copy link
Author

Thanks @bmorrall,

I updated the libraries you mentioned

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