git權限管理(linux)

一般的流程網上很多,只記錄一下自己踩的坑,摸索了好久。

1、push報錯

git push
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/facetosea/****.git

需要修改項目倉庫下的配置文件,(注意:通常git命令帶有--global都是修改全局配置,不帶--global則是修改項目倉庫配置)

vim .git/config 

[remote "origin"]
	url = https://github.com/facetosea/example.git

修改github.com爲[email protected]

[remote "origin"]
	url = https://[email protected]/facetosea/example.git

2、修改完後報錯

(gnome-ssh-askpass:5430):Gtk-WARNING **: cannot opendisplay: 

需要修改環境變量。Gtk這個錯誤,用unset SSH_ASKPASS之後不再報錯,只是每次操作需要輸入密碼。

3、linux退出再登錄,重新報錯(gnome-ssh-askpass:5430):Gtk-WARNING **: cannot opendisplay。

env查看變量,SSH_ASKPASS還在

LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1

使用grep指令找到了改環境變量的配置文件

[root@host-172-16-1-47 ~]# grep -r "SSH_ASKPASS" /etc/
/etc/profile.d/gnome-ssh-askpass.sh:SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
/etc/profile.d/gnome-ssh-askpass.sh:export SSH_ASKPASS
/etc/profile.d/gnome-ssh-askpass.csh:setenv SSH_ASKPASS /usr/libexec/openssh/gnome-ssh-askpass

註釋這幾行後,永久生效。下邊解決還要每次輸入密碼的問題。

4、網上有設置記住密碼方法

設置記住密碼(默認15分鐘):

git config --global credential.helper cache

如果想自己設置時間,可以這樣做:

git config credential.helper 'cache --timeout=3600'

這樣就設置一個小時之後失效

長期存儲密碼:(我使用這個方法去掉了--global,因爲另有公司內部git,不想影響,沒能生效)

git config --global credential.helper store

增加遠程地址的時候帶上密碼也是可以的。(這個使用後成功了)

http://yourname:[email protected]/name/project.git

5、git的連接分SSH和HTTPS不同方式,驗證方式也不同,上邊保存密碼的方法是HTTPS連接方式。

連接方式可以切換,如果你正在使用ssh而且想體驗https帶來的高速,那麼你可以這樣做:

切換到項目目錄下 :

cd projectfile/

移除遠程ssh方式的倉庫地址

git remote rm origin

增加https遠程倉庫地址

git remote add origin http://yourname:[email protected]/name/project.git

同樣也可以從HTTPS切換回SSH方式,不再贅述。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章