通过SourceTree连接SSL有问题的自建gitlab服务器

我用的是 SourceTree 作为Git客户端的,用它连接一个HTTPS证书过期的自建git服务,会收到下面错误:

abort: error: _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
fatal: repository 'https://****/guohongjun/mytest/' not found
Error validating server certificate for 'https://****:443':
- The certificate is not issued by a trusted authority. Use the fingerprint to validate the certificate manually!
- The certificate hostname does not match.
- The certificate has expired.
Certificate information:
- Hostname: *****
- Valid: from Thu, 12 Sep 2013 01:59:22 GMT until Fri, 12 Sep 2014 01:59:22 GMT
- Issuer: http://certs.godaddy.com/repository/, GoDaddy.com, Inc., Scottsdale, Arizona, US
- Fingerprint: a4:e0:66:ca:ba*******
(R)eject, accept (t)emporarily or accept (p)ermanently? svn: E175002: Unable to connect to a repository at URL 'https://******/guohongjun/mytest'
svn: E175002: OPTIONS of 'https://*****/guohongjun/mytest': Server certificate verification failed: certificate has expired, certificate issued for a different hostname, issuer is not trusted (https://*****) 

这是因为 SourceTree 新建仓库时,在 从URL 克隆时, 会去校验 ssl,如下图:

屏幕快照 2015-08-12 下午3.02.16

image

image

就是你在设置中设置了“禁止SSL校验也不行”

image

解决方案, 用命令行 clone 项目,然后通过添加已存在的本地仓库来使用。

 

Git 全局设置

git config --global user.name "郭红俊"
git config --global user.email guohongjun@***。**

 

创建仓库,并更新到远程服务器

mkdir mytest01
cd mytest01
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin http://*****/guohongjun/mytest01.git
git push -u origin master

 

Existing Git Repo   存在本地 Git Repo

cd existing_git_repo
git remote add origin http://118.194.63.8/guohongjun/mytest01.git
git push -u origin master
 
在做远程服务器提交之前,需要执行下面命令,禁用SSL校验

git config --global http.sslVerify false

 

准备好本地库相关

image

提交到远程服务器

image

这时候,我们通过 新仓库 - 新建本地已经存在的仓库 方式就可以增加了。

image


### 配置 SourceTree 连接GitLab 为了实现 SourceTreeGitLab连接,可以按照以下方法完成配置: #### 1. 创建 SSH 密钥 在本地计算机上生成一个新的 SSH 密钥用于身份验证。可以通过 Sourcetree 提供的功能或者手动执行命令来创建密钥。具体操作是在终端输入如下命令并替换其中的邮箱地址为您的 GitLab 账号邮箱[^2]: ```bash ssh-keygen -t rsa -C "your-gitlab-email@example.com" ``` 此过程会提示您指定保存位置以及密码保护(可选)。默认情况下,私钥会被存储在 `~/.ssh/id_rsa` 文件中,而公钥则位于 `~/.ssh/id_rsa.pub`。 #### 2. 将公钥添加至 GitLab 登录到您的 GitLab 帐户,在账户设置下的 **SSH Keys** 页面粘贴之前生成的公钥内容(即从 `id_rsa.pub` 文件读取的内容),从而允许远程服务器识别来自该设备的安全请求[^3]。 #### 3. 设置 SourceTree 使用 OpenSSH 客户端及指定 SSH 私钥路径 启动 SourceTree 应用程序之后进入其偏好设定区域: - 访问菜单栏中的 “工具” -> “选项” - 切换到左侧列表里的 'General' 或者 ‘高级’ 类目下找到关于 SSH Client Settings的部分 - 把 SSH client selector 改成 OpenSSH 并且准确填写 id_rsa 文件的具体绝对路径作为 Custom key path #### 4. 添加新的仓库克隆链接 当以上准备工作都完成后就可以回到源码管理界面上新增项目了。选择 Clone from URL 功能项,并把目标 git repository url 地址复制进去即可开始同步工作副本数据流[^1]。 通过上述步骤能够成功建立起两者之间的桥梁关系以便于后续更加便捷高效地开展协作开发活动。 ```python # 示例 Python脚本展示如何自动获取当前用户的 home目录结构以辅助构建完整的rsa文件名字符串表示形式 import os home_dir = os.path.expanduser("~") private_key_path = f"{home_dir}/.ssh/id_rsa" print(private_key_path) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值