记录一下如何同时将hexo部署到github和个人ubuntu服务器

1、申请秘钥对的时候需要指定位置和名称

1
ssh-keygen -t rsa -C "eystasy@gmail.com" -f C:\Users\Colar\github\my_ssh_key

说明:

-t 表示选择加密方式。

-c 表示用户,通常填写邮箱表示

-f 指定秘钥保存路径,最后的“my_ssh_key”表示秘钥名称

2、用notepad等软件打开.pub的公钥,复制后粘贴到github的SSH key的位置。具体见图。

3.配置config文件

1
路径:C:\Users\Colar\.ssh

config配置

1
2
3
4
5
Host github.com
HostName github.com
User git
IdentityFile C:\\Users\\Colar/github/my_ssh_key
IdentitiesOnly yes
  • C:/path/to/your/private_key替换为你的私钥文件的实际路径。注意路径使用正斜杠(/)或双反斜杠(\)。

  • Host可以是任何你想要的别名,如果你连接的是GitHub,通常直接使用github.com

  • HostName是Git服务器的地址,对于GitHub,它就是github.com

  • User是SSH连接中使用的用户名,对于GitHub而言,通常是git

  • IdentitiesOnly yes确保SSH只使用指定的IdentityFile

  • 运行下列代码检测连通性:
  • ssh -T git@github.com
    
    1
    2
    3
    4
    5

    ![](https://cdn.318666.xyz/gh/Eystasy/piclist-blog-hosting/piclist/202403010259858.png)

    或者下面的代码(区别是有错误输出):

    ssh -vT git@github.com
    1
    2
    3
    4
    5

    ![](https://cdn.318666.xyz/gh/Eystasy/piclist-blog-hosting/piclist/202403010300250.png)

    ### 4.hexo中的_config主文件中进行相关修改

    deploy:
  • type: git
    repo:
    branch:

  • type: heroku
    repo:
    branch:

    1
    2
    3

    ##### 因为我是用的nginx proxy manager管理网站,所以同时采用了git链接和ssh链接,附上个人部署方案:

    deploy:


### 5.尝试部署,注意看是否部署两次,即可判定是否成功。

![](https://cdn.318666.xyz/gh/Eystasy/piclist-blog-hosting/piclist/202403010305753.png)

![](https://cdn.318666.xyz/gh/Eystasy/piclist-blog-hosting/piclist/202403010305255.png)

### 6.至此成功解决问题,这个问题都花了好几个小时才解决。记录一下,以被不时之需。