1: Generate SSH Keys
Generate a new SSH key pair in your local terminal:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
After execution, it will prompt you to specify a filename. Press Enter to use the default path (~/.ssh/id_rsa), and you will receive two files:
id_rsa (Private Key) id_rsa.pub (Public Key)
2: Add Deploy Key to the GitHub Pages Repository
Open your GitHub Pages repository xgDebug/xgdebug.github.io. Go to Settings -> Deploy keys. Click Add deploy key. Title = Choose a descriptive title (e.g., “Hugo Blog Deployment Key”). Key: Copy and paste the content of the public key id_rsa.pub generated in the previous step. Check Allow write access, as write permissions are required. Click Add key.
3: Add Private Key to GitHub Secrets
In your Hugo repository xgDebug/xgDebug_blog, go to Settings -> Secrets -> Actions. Click New repository secret to create a new secret: Name: DEPLOY_KEY Value: Paste the content of the generated private key id_rsa.
4: Update GitHub Actions Configuration
Authenticate using DEPLOY_KEY in .github/workflows/gh-pages.yml:
name: Deploy Hugo Site to GitHub Pages
on:
push:
branches: - master
jobs:
deploy:
runs-on: ubuntu-latest
steps: - name: Checkout repository
uses: actions/checkout@v3
- name: Set up Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
- name: Install Hugo themes
run: git submodule update --init --recursive
- name: Build Hugo site
run: hugo --minify
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.DEPLOY_KEY }}
publish_dir: ./public
external_repository: xgDebug/xgdebug.github.io
publish_branch: gh-pages