GitHub Actions 自动部署:配置 GitHub 仓库指定文件夹到 Ubuntu 服务器

原文地址:https://itxiaozhang.com//github-actions-sync-specific-folder-to-ubuntu-server-complete-guide/ 如果您需要远程电脑维修或者编程开发,请加我微信咨询。 需求分析 源: GitHub 仓库:[你的仓库地址] 需同步的文件夹:public/ 目标: 服务器:[服务器IP] SSH 端口:[SSH端口] 用户:[用户名] 目标路径:/var/www/html/[你的域名] 功能要求: 当 push 到 main 分支时自动部署 只同步 public 文件夹内容 部署前清空目标目录 无需构建步骤 无需部署后操作 工作流程 生成新的 public 文件夹中的文件 提交并推送到 GitHub GitHub Actions 自动触发 Actions 通过 SSH 连接服务器 清空目标目录 同步新文件到服务器 详细教程 1. 服务器配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # 1.1 SSH 登录服务器 ssh [用户名]@[服务器IP] -p [SSH端口] # 1.2 生成 SSH 密钥对 ssh-keygen -t ed25519 -C "github-actions-deploy" # 按三次回车,使用默认设置 # 1.3 设置 SSH 目录权限 mkdir -p ~/.ssh chmod 700 ~/.ssh # 1.4 配置授权 cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys # 1.5 查看私钥(需要复制这个内容) vim ~/.ssh/id_ed25519 # 使用 y 复制内容 # 使用 :q 退出 # 1.6 创建并设置部署目录 mkdir -p /var/www/html/[你的域名] chmod 755 /var/www/html/[你的域名] 2. GitHub 配置 添加 Repository Secrets ...

2024年11月19日 · 2 分钟 · IT小章