Github搭建个人博客全攻略

Github搭建个人博客全攻略


一、Github

Github是开发者的代码仓库,一个开源和分享社区。

本文前提是已注册github账号。


二、配置博客仓库

假设用户名为MyName

  1. 进入个人主页(https://github.com/用户名),选择Repositories,点击New
  2. Repository name填入MyName.github.io,即MyName/MyName.github.io,点击Create Repository

三、配置Git用户SSH密钥

  1. 安装GitTortoiseGit(后者添加环境变量)
  2. 打开git bash或命令行,执行ssh-keygen -t ed25519 -C "your_email@example.com"
  3. 默认在C:/Users用户名/.ssh里找到id_ed25519.pub(如步骤2使用rsa则是 id_rsa.pub),记事本打开复制里面的内容
  4. 右上角头像进入Settings,选择SSH and GPG Keys,点New SSH Key,随意填入Title,Key粘贴步骤3的密钥,点击Add SSH Key

四、Deploy Key or Token

博客Hexo部署用到Deploy Key或者Token的方式,选其一即可

方法一: Deploy Key

  1. 进入仓库页面的Setting,选择Deploy Key,点击Add Deploy Key
  2. 密钥生成步骤同步骤三,生成的时候选择保存其他的文件名,复制密钥内容到Key栏

方法二: Token

  1. 点个人头像,选择Setting,再选Developer Settings,Person access tokens,点tokens (classic),Generate new Token(classic),填写信息,Expiration默认30天,Select scopes勾选repo栏即可
  2. 点击Generate token,复制生成的Token下一步使用

五、Hexo

  1. 下载安装node,添加环境变量,配置依赖下载路径
  2. 安装hexo
shell 复制代码
npm install -g hexo-cli
npm install -g hexo-renderer-pug
npm install -g hexo-renderer-stylus
npm install -g hexo-deployer-git
  1. 建立博客,预览效果
shell 复制代码
# 新建博客目录
mkdir blog
# 初始化hexo项目
hexo init blog
# 安装依赖
cd blog
npm install 
# 生成静态文件
hexo generate
# 启动本地服务器 http://localhost:4000
hexo server
  1. Github部署
shell 复制代码
# blog/_config.yml, token或ssh key选一个repo配置,每个:号后面必须带一个空格
url: https://MyName.github.io/MyName.github.io
deploy: 
  type: git
  repo: https://上一步得到的token值@github.com/MyName/MyName.github.io
  # repo: git@github.com:MyName/MyName.github.io.git
  branch: master
  message: 

#执行部署
hexo deploy

六、 主题

shell 复制代码
git clone https://github.com/主题仓库地址.git themes/主题名

# 编辑_config.yml
theme: 主题名

七、 发布博文

shell 复制代码
hexo new post "How to build a bolg with Hexo on Github"
hexo clean
hexo generate
hexo deploy

登录https://MyName.github.io/即可查看发布的博文,更多知识点请上Hexo官网查阅。


八、参考链接

1\] [Generating a new SSH key and adding it to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) \[2\] [在 GitHub Pages 上部署 Hexo](https://hexo.io/zh-cn/docs/github-pages)

相关推荐
闫记康2 小时前
scp工具
linux·运维·服务器·学习·ssh·github
逛逛GitHub3 小时前
狠狠的 Pua 你的 OpenClaw 小龙虾,这 2 个 GitHub 项目开源了。
github
testresultstomorrow5 小时前
GitHub 代码上传与故障排除实战指南
经验分享·笔记·开源·github
啊巴矲6 小时前
小白从零开始勇闯人工智能:GitHub基础入门(下)
github
研究点啥好呢7 小时前
每日GitHub热门项目推荐 | 2026年3月9日(补充)
ai·开源·github·openclaw
研究点啥好呢8 小时前
每日GitHub热门项目推荐 | 2026年3月9日
人工智能·ai·自动化·github·openclaw
itwangyang5208 小时前
GitHub Push Protection 报错解决指南(检测到 Token / Secret)
人工智能·python·github
天若有情6738 小时前
【C++实用工具】RandEmmet:致敬Emmet的极简随机数生成器(附完整源码+GitHub)
开发语言·c++·github
猫头虎9 小时前
Docker 安装 OpenClaw 报错排查完全手册(续):如何解决pairing required,`EACCES: permission denied`Docker 拉取镜像提示 `denied
运维·docker·容器·开源·github·aigc·ai编程
子夜江寒9 小时前
GitHub入门
github