Skip to content

Instantly share code, notes, and snippets.

@pataruco
Last active November 14, 2024 16:23
Show Gist options
  • 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/[email protected]
      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. 🚀

@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