1.拷贝相关文件
建立hexo博客都会有一个独立的文件夹。电脑转移时安全的做法是将整个文件夹拷贝,这其中包括三个必备的文件:config.yml(站点配置_)、theme(主题文件夹)、source(博客内容文件)。次要文件:scaffolds(文章的模板)、package.json(使用包的说明文件)和.gitignore(限定在提交的时候哪些文件可以忽略)三个次要文件为自动生成的,因此丢失也不影响博客内容,后续在hexo init时会生成这三个文件。需要删除的文件:.git文件、node_modules(进行npm install会重新生成)、public(执行hexo g时会重新生成)、.deploy_git文件夹(执行hexo d时会重新生成)、db.json文件。其实上面这些可删除的文件即为.gitignore文件里面记载的可以忽略的内容。
总结:_config.yml、theme、source、scaffolds、package.json、.gitignore应该进行拷贝,.git/,node_modules/,public/,.deploy_git/,db.json文件需要删除
2.初始化环境
安装Node和Git环境。Windows环境下均有相关的exe可执行文件,两者的环境搭配均比较容易,特别的Node安装时自带有npm,可以方便执行后续的hexo安装。Hexo主要执行命令如下:
$ npm install hexo-cli -g
$ hexo init <your_blog_name> # your_blog_name 可以缺省,在博客文件夹内执行相关命令
$ npm install
3.新建SSH Key
$ ssh-keygen -t rsa -C "GitHub邮箱名"
之后会出现:
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/jacky/.ssh/id_rsa):
直接回车就可以。
然后会出现:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
要求你输入密码,这个密码会在你提交项目时使用,如果为空的话提交项目时则不用输入。这个设置是防止别人往你的项目里提交内容。
注意:输入密码的时候没有*字样的,直接输入就好。
然后会出现:
Your identification has been saved in /c/Users/jacky/.ssh/id_rsa.
Your public key has been saved in /c/Users/jacky/.ssh/id_rsa.pub.
The key fingerprint is:
65:58:······02:4b emailname@email.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . o . |
| . o o = o |
| . o * = o |
| E o + o . |
| . o. . . |
| .. |
+-----------------+
至此,密钥已在本地成功生成。
4.添加SSH Key
- 打开本地文件:id_rsa.pub(文件路径可以在上一步SSH生成成功后看到路径,具体在’Your public key has been saved in’后面),可以将这个文件在编辑器中打开,然后全选复制
- 登陆github,点击头像位置处 Settings ——> SSH and GPG keys,点击新建SSH Key
- 将复制的内容全部粘贴在Key文本框内,title填不填均可
5.测试设置是否成功
$ ssh -T git@github.com
有可能会出现:
The authenticity of host 'github.com (192.156.***.19)' can't be established.
RSA key fingerprint is 36:27:ac:a5:76:28:2d:45:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
或者是
The authenticity of host 'github.com (192.156.***.19)' can't be established.
RSA key fingerprint is nThbg***********************8.
Are you sure you want to continue connecting (yes/no)?
这种情况下,直接 yes 回车。
然后会出现:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
至此,设置成功。
6.设置用户信息
$ git config --global user.name "用户名"
$ git config --global user.email "你希望的邮箱名"
7.正常Hexo命令操作
$ hexo s # http://localhost:4000/预览
$ hexo g # 编译
$ hexo d # 发布
引用参考
https://blog.csdn.net/xr469786706/article/details/79837602
https://www.cnblogs.com/xsilence/p/6001938.html