前言
前段时间有同学反馈测试机个别项目git clone和git pull等都失败,提示权限过期,当时忙交给其他同学搞,没人再说过以为搞定了。今天准备改一个好长时间没动过的项目,git clone 后报错:The project you were looking for could not be found or you don't have permission to view it.
问了之后原来没有搞定,他们用http方式拉取,但这个方式有个很不好的体验就是每次操作都需要输入用户名和密码,贼麻烦,既然碰到了,还是处理一下吧,记录下处理的过程,方便后面同学遇到借鉴
报错信息
[root@10 htdocs]# git clone ssh://git@git.intra.ngxcode.com/search/openapi.git openapi_ngxcode
Cloning into 'openapi_ngxcode'...
remote:
remote: ========================================================================
remote:
remote: The project you were looking for could not be found or you don't have permission to view it.
remote:
remote: ========================================================================
remote:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决方案
网上查了一些方案,大部分基本都是让清理账户信息,重新git clone后再输入账户和密码生效,但这种方式我这没成功,所以想着用秘钥更新下,终于解决了
秘钥生成
登陆root账号信息,其他有权限的也可以其实,因为测试机器,我就直接用的最高权限
#1. ssh-keygen
[root@10 docker-web-start]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
#2. 提示已有文件,y,强制覆盖,后面一路回车就可以
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
83:3d:8d:d8:9c:7e:93:d2:16:29:34:5e:19:c6:5c:b5 root@10.185.27.117
The key's randomart image is:
+---[RSA 2048]----+
| oo.... |
| .oo . |
| o o E |
| O * . |
| o S + |
| . = o |
| o * |
| + . |
| |
+-----------------+
#3. 秘钥生成后,查看时间是否为最新时间,确认生成成功
[root@10 docker-web-start]# ll /root/.ssh/
total 16
-rw------- 1 root root 2181 Apr 17 18:32 authorized_keys
-rwx------ 1 root root 1679 May 25 14:42 id_rsa
-rw-r--r-x 1 root root 400 May 25 14:42 id_rsa.pub
-rw-r--r-- 1 root root 209 Apr 20 19:45 known_hosts
[root@10 docker-web-start]#
[root@10 docker-web-start]#
#4. 查看秘钥文件信息,复制内容
[root@10 docker-web-start]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+3MSXFnec5+QBrPeHZsjZ7Av4AhGqC5pOEfiGABuOG6ZMfCVFs8SdyAaViEjqYU+TNpXXYFGce2gnFLca94WDzGDVxPE519J+Qxfw5Nx0/WdLltcUZEDxSryT6cD20l7difY0Cq8R2vZmR5vb0Te1mGTTsUOsLEhmQwAYgDERP0nEYPwsmjeJmmlLT0QcUSWZAnxAlIiveJqE1kWAMoS6+8hJbaArlEldJQpa7vKLsaF/9S0T/txsedNev8cU66WVCB9sheuaOvF/DfXeuWBjCQytSjWjna/0WKSWipPvagcEvjrahi6OTC5yJcvtoNYtNE4RlOVqJITZGSD2yQ3t root@10.182.17.127
秘钥配置
公司用的GitLab
,登陆一个有Maintainer
权限的账户,进入ssh秘钥设置,粘贴刚才复制的秘钥,输入title(root@克隆机器ip)和过期时间,点击创建,这时候去测试机器重新clone,就没问题了!
结语
以上是Git ssh权限过期解决的具体过程,希望能帮助到需要的同学,更多文章请关注本站其他内容,感谢!