书接上文,在部署过简单的springboot和html项目后,我们可以尝试直接将github仓库的项目克隆至华为云耀云服务器L实例上,既作为一种简单的传输手段,又可直接部署现成的开源项目。
本篇以github上的开源项目(https://github.com/ruanjiancheng/StudentManageSystem)为例,这是一个基于springboot+vue的前后端分离项目,

看起来你的 CentOS 服务器上还没有安装 Git。你可以通过以下命令来安装 Git:
```bash
sudo yum install git -y
```
安装完成后,尝试克隆 GitHub 仓库:
git clone git@github.com:ruanjiancheng/StudentManageSystem.git
倘若出现提示:
[root@hcss-ecs-8ba6 ~]# git clone git@github.com:ruanjiancheng/StudentManageSystem.git
Cloning into 'StudentManageSystem'...
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts
是正常的,它出现是因为这是第一次尝试从这台服务器连接到 GitHub。系统需要确认 GitHub 的身份,以确保不是连接到一个恶意服务器。
输入 `yes` 并按 Enter 后,GitHub 会被添加到已知的主机列表中,以后就不会再出现这个提示了。
成功地确认 GitHub 的身份后,现在 Git 会继续克隆仓库。

这个错误表明 SSH 公钥认证失败了。这通常意味着我们没有正确设置 GitHub 上的 SSH 密钥,或者你没有将 SSH 密钥添加到 SSH 代理(`ssh-agent`)中。
### 解决方案:
1. **生成 SSH 密钥对**(如果你还没有的话):
```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

这一步是在询问想将 SSH 密钥保存在哪个文件里。默认路径是 `/root/.ssh/id_rsa`,直接按 Enter 键即可。
接下来,输入一个密码以保护你的密钥。这一步是可选的,但增加了一个额外的安全层,也可以直接敲两次回车,若选择输入密码,则不可少于5个字符
这将在 `~/.ssh/` 目录下生成一个新的 SSH 密钥对。
2. **将 SSH 公钥添加到 GitHub**:
成功地生成了一个新的 SSH 密钥对后,要将这个公钥添加到你GitHub 账户。
### 查看并复制 SSH 公钥
使用以下命令查看你的 SSH 公钥:
```bash
cat ~/.ssh/id_rsa.pub
```

这将显示 SSH 公钥。使用鼠标选中并复制这段文本。
### 将 SSH 公钥添加到 GitHub
(1)打开 GitHub 账户,并点击右上角的头像选择 "Settings"。

(2)在左侧菜单中,找到并点击 "SSH and GPG keys"。

(3)点击右上角的 "New SSH key" 按钮。

(4)在 "Title" 字段中,输入一个标识这个密钥的名称,比如 "My HUAWEI Server"。
(5)在 "Key" 字段中,粘贴刚才复制的 SSH 公钥。
(6)点击 "Add SSH key" 按钮。


完成这些步骤后,新 SSH 密钥已经添加 GitHub 账户中,现在能够通过 SSH 克隆 GitHub 仓库了。
3. **添加 SSH 密钥到 SSH 代理**:
```bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
```

4. **测试 SSH 连接**:
ssh -T git@github.com

测试成功,我们已经成功地完成了与GitHub的SSH连接
5. **再次尝试克隆仓库**:
git clone git@github.com:ruanjiancheng/StudentManageSystem.git

如图所示,我们已经成功地开始克隆github仓库到云服务器上。
本篇中,我们成功地完成了github与华为云耀云服务器L实例的连接配置,并且成功克隆了一个github仓库项目到华为云耀云服务器L实例上,这大大减少了已完成打包配置的开源项目部署的时间,以便尽快开展它在华为云耀云服务器L实例上的下一步部署。
网友评论