hexo-迁移到linux所遇到的问题

来源:互联网 发布:阿里云搭建vpn云免 编辑:程序博客网 时间:2024/06/04 00:29

在安装了linux后,我决定将hexo博客移到linux上,其配置过程和在windows上大致相同,但是转移过程中还是遇到了很多困难,以防万一我将其记录下来。

Nodejs 安装(参考 Linux下安装Nodejs)

首先可以直接使用命令安装

$ sudo apt-get install nodejs$ sudo apt-get install npm

但是我使用这种方法安装出现了各种问题,可能是版本太低,而且它会直接安装在/usr/local/bin/下,所以如果这种方法行不通一定要将其下的npm nodejs文件删掉。

然后就是选择在[]Nodejs官网](https://nodejs.org/en/)上下载推介的比较新的版本v6.9.2 LTS,但是下载比较慢,我将我下载的上传
点击下载
下载解压好后

#path_to为解压文件后实际地址$ ln -s /path_to/bin/node /usr/local/bin/node$ ln -s /path_to/bin/npm /usr/local/bin/npm

这样在/usr/local/bin/中也会生成nodejsnpm文件,以后在任意路径下都可以执行nodenpm两个命令了。

安装Git

$ sudo apt-get install git

安装hexo

$ sudo npm install hexo-cli -g

安装Hexo安成后,使用如下命令快速新建一个博客系统

$ hexo init blog$ cd blog$ npm install

如果npm安装失败,请使用sudo安装

http://0.0.0.0:4000/ 无法访问

在执行hexo server进行预览时,我发现http://0.0.0.0:4000/ 无法显示,原因是为了翻墙我曾经覆盖过hosts文件,新的hosts文件缺了127.0.0.1 localhost 127.0.1.1 ed//用户名,补回后便可预览。

转移原备份博客

将原来博客目录下的source theme _config.yml覆盖到新的博客目录中

hexo deploy失败

  • 修改_config.yml deploy type: git
  • $ npm install hexo-deployer-git --save

hexo deploy必须使用sudo

ctrl H显示隐藏文件夹.deploy_git,其中的文件都有个上锁的标号(权限不够)
$ sudo chmod -R 777 .deploy_git我索性将其权限最大化(可能700等也可以),这样就省掉了sudo的麻烦

添加SSH后deploy仍然需要输入账户和密码

生成本地SSH密匙

首先打开命令行工具,通常我们可以直接右键鼠标任意位置打开 Git Bash Here,然后输入以下命令

$ cd ~/.ssh# Checks to see if there is a directory named ".ssh" in your user directory

使用 ssh-keygen 生成密钥

$ ssh-keygen -t rsa -C "your_email@example.com"# Creates a new ssh key using the provided emailGenerating public/private rsa key pair.Enter file in which to save the key (/home/you/.ssh/id_rsa):

使用默认的文件名直接enter,接下来显示如下

Enter passphrase (empty for no passphrase): [Type a passphrase]Enter same passphrase again: [Type passphrase again]

按提示输入密码即可(简化流程的话在键入命令 ssh-keygen -t rsa -C "your_email@example.com"以后的三次提示输入都可以直接回车跳过)。

密钥生成成功

Your identification has been saved in /home/you/.ssh/id_rsa.Your public key has been saved in /home/you/.ssh/id_rsa.pub.The key fingerprint is:…………………此处是密钥内容…………………… your_email@example.comba

设置github SSH keys

可以选择是在用户设置中添加密钥(Settings –> SSH GPG keys)还是单个项目中添加密钥,在这里我就在我们的博客项目中添加密钥,此处以我的博客为例。
eddyguo.github.io 的首页菜单栏中点击 Settings –> Deploy keys –> Add deploy key,然后将生成的id_rsa.pub中的内容全选复制到 key 输入框中,然后点击 Add key 完成添加公钥。

接下来测试配置是否成功

$ ssh -T git@github.com

如果出现以下内容即表示配置完成并且成功!

Hi username! You've successfully authenticated, but GitHub does notprovide shell access.

解决SSH不起作用的问题

将https改成git:
把博客目录下_config.yml/.deploy_git/.git/config中url都改成git@github.com:Name/project.git

阅读全文
0 0