↓ 跳过正文
  1. 文章/

如何将GitHub的私有仓库部署到VPS上

·586 字·2 分钟· loading · loading · ·
QiYue
作者
QiYue
技术探索者,记录 Linux、数据库、开发工具的实践经验。
目录

将 GitHub 私有仓库部署到 InstaBox VPS
#

本文介绍如何在 Debian 13 的 InstaBox VPS 上,通过 GitHub Deploy Key 克隆私有仓库。Deploy Key 可单独授权某个仓库,建议保持只读权限。

1. 安装 Git 并生成 SSH 密钥
#

登录 InstaBox VPS 后执行:


sudo apt update

sudo apt install -y git

mkdir -p ~/.ssh

chmod 700 ~/.ssh

ssh-keygen -t ed25519 -C "instabox-deploy" -f ~/.ssh/github_instabox

系统询问 Enter passphrase 时,可以设置密钥口令。如果不想设置,直接按两次回车。

2. 将公钥添加到 GitHub 仓库
#

在 VPS 上显示公钥:


cat ~/.ssh/github_[instabox.pub](http://instabox.pub)

复制输出的整行内容。在 GitHub 打开目标私有仓库,进入:

Settings → Deploy keys → Add deploy key

粘贴公钥并保存。除非服务器需要向仓库推送代码,否则不要勾选 Allow write access。

只复制以 .pub 结尾的公钥。不要分享或上传 ~/.ssh/github_instabox 私钥。

3. 配置 SSH 连接
#

在 VPS 上执行:


cat >> ~/.ssh/config <<'EOF'

Host github-instabox

    HostName [github.com](http://github.com)

    User git

    IdentityFile ~/.ssh/github_instabox

    IdentitiesOnly yes

EOF

chmod 600 ~/.ssh/config

4. 克隆私有仓库
#

如果仓库的 HTTPS 地址是:


[https://github.com/OWNER/REPO](https://github.com/OWNER/REPO)

对应的 SSH 克隆命令是:


git clone git@github-instabox:OWNER/REPO.git

将 OWNER 替换成 GitHub 用户名或组织名,将 REPO 替换成仓库名。例如:


git clone git@github-instabox:alice/myapp.git

克隆完成后,进入项目目录:


cd myapp

5. 确认仓库已下载
#


git status

git remote -v

6. 拉取仓库更新
#

以后需要更新代码时,进入项目目录并执行:


git pull

7. 安装依赖并启动项目
#

部署和启动命令取决于项目使用的技术栈。先查看仓库内容和说明:


ls -la

如果仓库中有 README 文件,可以查看其中的部署说明:


cat [README.md](http://README.md)

常见项目文件包括:

  • requirements.txt 或 pyproject.toml:Python 项目

  • package.json:Node.js 项目

  • Dockerfile 或 docker-compose.yml:Docker 项目

  • pom.xml:Java Maven 项目

根据项目文档安装依赖、构建并启动服务。

相关文章