背景
前几篇已经系统了解了git的常用命令,那我现在就来实际与托管平台操作一番
一番配置回顾经过
这里使用gitee平台进行在线代码托管。git add 、git commit一切正常,但是git push 的时候就异常了,提示如下:
Access deined: [31mDeployKey does not support push code[0m
Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
或者
Access deined: DeployKey does not support push code
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我一看到key,以为自己配置错了。因为我这里是配置了多个key,具体的配置如下:
- 生成多个ssh 公钥
$ ssh-keygen -t rsa -C ‘xxxxx@company.com’ -f ~/.ssh/gitee_id_rsa
- 配置使用多个ssh公钥
在~/.ssh目录下新建config文件,并添加配置信息,
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
这里最后一行就指定了访问主机名为‘gitee.com’,与其建立安全连接时使用到的身份验证文件,即我们通常说私钥。
- 验证可以连接成功
ssh -T git@gitee.com
成功的话,会给你返回信息如下:
Hi zhangfengxia (DeployKey)! You've successfully authenticated, but GITEE.COM does not provide shell access.
Note: Perhaps the current use is DeployKey.
Note: DeployKey only supports pull/fetch operations
具体细节点击了解更多
回顾流程正常,开始百度寻求解法
其实看看具体的报错,人家也提示说了,DeployKey only supports pull/fetch operations, 那么了解一下git中的key吧,有两种:
- deploy key
只读的,不能push,属于某个项目,在需要部署的项目的setting中设置 - SSH key
可读可写。属于所有项目,即全局的。在profile的 setting中设置
这样我就明白了,我配置的时delpoy key,那我就直接删除原来的针对某个项目配置的key删除,重新配置了一下我的ssh key。。。。。草率了
这两个key的作用,我的了解是,托管平台嘛,在创建项目时也让你选择了是私有还是public,既然我选择的是public,那么就支持所有人来pull代码,但是我不能随随便便让别人改我的,是不是,这时候这两个key的配置的区别和作用就出来啦
写在最后
。。。。。