::: tip
使用 github action 实现个人 vuepress 博客自动部署到阿里云服务器
:::
当 github 仓库发生 push 操作时,action 会通过 ssh(配置公钥与私钥与阿里云服务器免密连接)传送到 nginx 服务器的静态资源目录下。
写在前面的
因为在我购买阿里云服务器时选择的系统配置是 windows server 2019 版本的,所以不能通过 ssh 来实现阿里云服务器与本地电脑实现 ssh 免密连接,进而也不能实现 github action 与阿里云服务器的免密连接。
最后的解决方案是更改阿里云服务器的系统配置。
更改服务器系统配置的具体操作如下:
正文开始
生成一个新的 ssh key:
将生成的 ssh 公钥 public key 添加到 github 中:
遇到的主要问题
添加阿里云服务器.ssh 目录下的 ssh 私钥 private key 到 github 当前项目的 setting》secrets 中:
将公钥写入 authorized_keys 文件中的命令是:
1 | [root@iZm5e8dv3a3meqZ .ssh]# cat id_rsa.pub >> ~/.ssh/authorized_keys |
打开 authorized_keys 文件中的命令是:
1 | vim authorized_keys |
退出 authorized_keys 文件中的命令是:
1 | :wq |
删除文件命令:rm -f authorized_keys
我的 github action(nodejs)配置
1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node |
写在后面的
this all thank you!
References
- 阿里云服务器-自动部署一键部署(哔哩哔哩视频)
- Centos 7 下安装配置 Nginx
- GitHub Actions 入门教程
- ssh key 与 github 配置(实现本地电脑/阿里云服务器与 github 的免密通信)
- Linux 学习笔记–rm 命令(删除文件或目录)
__END__