在go get或go mod download时,可能会依赖一些其他地方的库或是自己的git库,此时需要更改证书和配置git。
一. 证书安装
有些服务器需要配置证书,不同的系统有不同的添加证书方法
Mac OS X
1. add:
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/new-root- certificate.crt
2. Remove
sudo security delete-certificate -c "<name of existing certificate>"
Windows
1. add:
certutil -addstore -f "ROOT" new-root-certificate.crt
2. remove:
certutil -delstore "ROOT" serial-number-hex
Linux (Ubuntu, Debian):
1. add:
a. Copy your CA to dir /usr/local/share/ca-certificates/
b. Use command: sudo cp foo.crt /usr/local/share/ca-certificates/foo.crt
c. Update the CA store: sudo update-ca-certificates
2. remove
a. Remove your CA.
b. Update the CA store: sudo update-ca-certificates --fresh
Linux (CentOs 6)
1. Add
1. Install the ca-certificates package: yum install ca-certificates
2. Enable the dynamic CA configuration feature: update-ca-trust force-enable
3. Add it as a new file to /etc/pki/ca-trust/source/anchors/: cp foo.crt /etc/pki/ca-trust/source/anchors/
4. Use command: update-ca-trust extract
Linux (CentOs 5)
Add
1. Append your trusted certificate to file /etc/pki/tls/certs/ca-bundle.crt
2. cat foo.crt >>/etc/pki/tls/certs/ca-bundle.crt
二. 生成ssh访问密钥
$ ssh-keygen -t rsa
# 生成的文件在~/.ssh/下, 包含id_rsa,id_rsa.pub前者为私钥,后者为公钥,公钥放到自建git库的sshkey中。
$ chmod 600 ~/.ssh/id_rsa
二. git 配置
git config --global url.git@git.xx.com:.insteadOf https://git.xx.com/ #表示将ssh访问git库转为https访问