当前位置:   article > 正文

利用GitHub搭建个人网站_github部署个人网站

github部署个人网站

利用GitHub搭建个人网站

搭建个人网站的前期准备

1.安装node.js
2.安装git
3.申请GitHub账号

配置GitHub的ssh秘钥

第一步、检查自己之前有没有已经生成。

在开始菜单中打开git下的git bash(当然,在其他目录下打开git bash也是一样的),然后执行:

ls -al ~/.ssh 
  • 1

第二步、如果能进入到.ssh文件目录下 ,则证明,之前生成过.ssh秘钥,可以直接使用里面的秘钥。

检测配置,执行:

git config user.name
git config user.email
  • 1
  • 2

如果之前没有创建,则执行以下命令:

git config –global user.name ‘xxxxx’ 
git config –global user.email ‘xxx@xx.xxx’
  • 1
  • 2

生成秘钥:

ssh-keygen -t rsa -C ‘上面的邮箱’
  • 1

代码参数含义:
-t 指定密钥类型,默认是 rsa ,可以省略。
-C 设置注释文字,比如邮箱。
-f 指定密钥文件存储文件名。

如下图所示:
ssh秘钥生成截图
详细信息:

[root@localhost ~]# ssh-keygen -t rsa       <== 建立密钥对,-t代表类型,有RSA和DSA两种
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):   <==密钥文件默认存放位置,按Enter即可
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):     <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again:     <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa.    <== 生成的私钥
Your public key has been saved in /root/.ssh/id_rsa.pub.    <== 生成的公钥
The key fingerprint is:
SHA256:K1qy928tkk1FUuzQtlZK+poeS67vIgPvHw9lQ+KNuZ4 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|           +.    |
|          o * .  |
|        . .O +   |
|       . *. *    |
|        S =+     |
|    .    =...    |
|    .oo =+o+     |
|     ==o+B*o.    |
|    oo.=EXO.     |
+----[SHA256]-----+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

(C盘用户文件夹下.ssh目录)得到了两个文件:id_rsa(私有秘钥)和id_rsa.pub(公有密钥)

第三步、如果想登陆远端,则需要将rsa.pub里的秘钥添加到远端。

  1. 查找.ssh目录,找到id_rsa.pub这个文件夹打开复制全部内容。
    ssh文件
  2. 登录GitHub,选择Settings
    setting
  3. 点击SSH and GPG keys
    SSH and GPG keys
  4. 创建New SSH key
  5. 点击Add SSH key
    Add SSH key
  6. 再弹出窗口,输入你的GitHub密码,点击确认按钮。
  7. 测试
    ssh测试

创建GitHub仓库

  1. 在GitHub首页点击your repositoriesyour repositories

  2. 点击New按钮,创建仓库创建仓库

  3. 输入Repository name(仓库名称 )。**仓库名称为:用户名+.github.io **, 其他选择默认配置。点 击Create repository(创建仓库) Create repository

  4. 选择仓库的settings,点击Pages,查看仓库访问页 查看仓库地址

搭建博客模板

hexo为例搭建博客:

  1. 安装hexo
npm install hexo-cli -g
  • 1
  1. 初始化一个博客项目
hexo init blog
  • 1
  1. 切换到博客目录,下载相关依赖,运行博客项目,发布本地博客
npm install
hexo server
  • 1
  • 2
  1. 输入网址查看博客页面。
    博客项目运行
  2. 修改配置信息
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: git
  repo: 
    github: https://github.com/用户名//用户名.github.io.git
    # github: https://github.com/LemonMei/LemonMei.github.io.git
  branch: main
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. 安装hexo-deployer-git
npm install hexo-deployer-git --save
  • 1
  1. 创建发布的文件
hexo g
  • 1

创建发布的文件

  1. 生成Personal access tokens
    点击Developer settings在这里插入图片描述
    点击生成Personal access tokens
    在这里插入图片描述
    任意输入Note,选择30天有效时间,下面全选,点击生成。
    在这里插入图片描述
    复制保存Personal access tokens
    在这里插入图片描述

  2. 将博客项目上传至GitHub仓库

hexo d
  • 1

输入用户名:
在这里插入图片描述
输入Personal access tokens
在这里插入图片描述

  1. 博客搭建成功!访问https://用户名.github.io/
  2. 查看hexo文档,选择主题,查看文档,修改样式。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/990071
推荐阅读
相关标签
  

闽ICP备14008679号