git push上傳代碼到gitlab上,報錯401或403

來源:互聯網
上載者:User

標籤:erro   comm   9.png   objects   touch   tin   問題   工程   使用者名稱   

 

 

之前部署的gitlab代碼託管平台,採用ssh方式串連gitlab,在客戶機上產生公開金鑰上傳到gitlab的SSH-Keys裡,則git clone下載和git push上傳都沒問題,這種方式很安全。

後來應開發同事要求採用http方式串連gitlab,那麼首先將project工程的“Visibility Level”改為“Public”公開模式,並且要保證gitlab的http連接埠像客戶機開放。

後面發現了一個問題:
http方式串連gitlab後,git clone下載沒有問題,但是git push上傳有報錯:
error: The requested URL returned error: 401 Unauthorized while accessing http://git.xqshijie.net:8081/weixin/weixin.git/info/refs
fatal: HTTP request failed

或者
The requested URL returned error: 403 Forbidden while accessing

執行個體如下:
假設git的url為http://git.wangshibo.net
[[email protected] ~]# mkdir /root/git
[[email protected] ~]# cd /root/git
[[email protected] git]# git init .
[[email protected] git]# git clone http://git.wangshibo.net:8081/weixin/weixin.git
Initialized empty Git repository in /root/git/weixin/.git/
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.

上面可以看出,已經能成功git clone下代碼
[[email protected] git]# ll
total 4
drwxr-xr-x. 3 root root 4096 Nov 30 15:58 weixin
[[email protected] git]# cd weixin/
[[email protected] weixin]# ll
total 8
-rw-r--r--. 1 root root 15 Nov 30 15:58 heihei
-rw-r--r--. 1 root root 1 Nov 30 15:38 README.md

現在測試下git push
[[email protected] weixin]# git rm heihei
[[email protected]iu weixin]# touch test.file
[[email protected] weixin]# echo "123456" > test.file
[[email protected] weixin]# git add .
[[email protected] weixin]# git commit -m "this is a test"
[[email protected] weixin]# git push                                      //或者git push -u origin master
error: The requested URL returned error: 401 Unauthorized while accessing http://git.wangshibo.net:8081/weixin/weixin.git/info/refs

fatal: HTTP request failed

 

解決辦法:
在代碼的.git/config檔案內[remote "origin"]的url的gitlab網域名稱前添加gitlab註冊時的“使用者名稱:密碼@”
如下,gitlab的使用者名稱是wangshibo,假設密碼是[email protected]!h8

查看gitlab介面裡的登陸使用者名稱:

 

然後修改代碼裡的.git/config檔案
[[email protected] weixin]# cd .git
[[email protected] .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://git.wangshibo.net:8081/weixin/weixin.git
[branch "master"]
remote = origin
merge = refs/heads/master

修改如下:
[[email protected] .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://wangshibo:[email protected][email protected]git.wangshibo.net:8081/weixin/weixin.git
[branch "master"]
remote = origin
merge = refs/heads/master

git push上傳代碼到gitlab上,報錯401或403

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.