在cPanel中配置多个私有Git仓库访问遇权限问题求助
解决cPanel配置多私有Git仓库的Permission denied问题
你遇到的核心问题是cPanel的Git工具没有正确匹配到自定义SSH密钥配置,以下是你可能遗漏的关键步骤:
1. 修正SSH config文件的配置与权限
配置文件内容
确保~/.ssh/config的每个仓库条目都包含IdentitiesOnly yes,强制SSH使用指定密钥,避免尝试默认密钥导致冲突,示例配置:
Host github-top25vineyards HostName github.com User git IdentityFile ~/.ssh/top25vineyards IdentitiesOnly yes Host github-top25restaurants HostName github.com User git IdentityFile ~/.ssh/top25restaurants IdentitiesOnly yes
设置正确的文件权限
SSH对.ssh目录下的文件权限要求严格,执行以下命令修正:
chmod 600 ~/.ssh/config chmod 600 ~/.ssh/top25vineyards ~/.ssh/top25restaurants chmod 644 ~/.ssh/top25vineyards.pub ~/.ssh/top25restaurants.pub chmod 700 ~/.ssh
2. 使用自定义Host别名的Clone URL
在cPanel的Git Version Control中添加仓库时,不能使用默认的git@github.com:<username>/<repo>.git,需要替换为config里定义的Host别名,比如:
- 对于top25vineyards仓库,使用
git@github-top25vineyards:<username>/top25vineyards.git - 对于top25restaurants仓库,使用
git@github-top25restaurants:<username>/top25restaurants.git
这样SSH才能匹配到对应的密钥配置。
3. 终端手动克隆验证(可选)
如果cPanel工具仍报错,先在终端手动执行克隆命令测试,确认密钥和配置正常:
git clone git@github-top25vineyards:<username>/top25vineyards.git
如果终端克隆成功,说明是cPanel工具的上下文问题,你可以手动克隆到目标目录后,再进入cPanel的Git Version Control选择“Import Repository”导入已有的本地仓库。
4. 验证GitHub Deploy Keys配置
- 确认每个仓库的Deploy Keys添加的是对应密钥的公钥(
top25vineyards.pub和top25restaurants.pub),内容无截断或多余字符 - 若需要推送代码,确保Deploy Keys勾选了
Allow write access(仅克隆的话无需此步骤)
内容的提问来源于stack exchange,提问作者penk
相关产品推荐
相关产品推荐

