ubuntu使用git提交github時,執行pull或者push命令要重新輸入用戶名和密碼:
1:問題現象:
hlp@hlp:~/code/github_code/catch_imooc1$ git push Username for 'https://github.com': XXXX Password for 'https://XXXX@github.com': Counting objects: 20, done.
2:問題原因:
使用git clone 克隆代碼的時候默認使用了https的方式而不是ssh的方式。
本地查看方式: hlp@hlp:~/code/github_code/catch_imooc1$ git remote -v origin https://github.com/XXXX/xxx.git (fetch) origin https://github.com/XXXX/xxx.git (push)
3:修改方案:
修改git clone 克隆代碼方式為ssh的方式:
1:獲取ssh代碼庫地址,在github項目主頁中,修改https地址方式為ssh方式:
2:移除本地https獲取方式,切換成ssh方式:
修改https獲取方式為ssh方式: hlp@hlp:~/code/github_code/catch_imooc1$ git remote rm origin 查看本地代碼庫獲取方式: hlp@hlp:~/code/github_code/catch_imooc1$ git remote -v 修改本地代碼庫git獲取地址為ssh方式: hlp@hlp:~/code/github_code/catch_imooc1$ git remote add origin git@github.com:XXXX/xxxx.git 查看本地代碼庫獲取方式: hlp@hlp:~/code/github_code/catch_imooc1$ git remote -v origin git@github.com:XXXX/xxxx.git (fetch) origin git@github.com:XXXX/xxxx.git (push) 測試驗證: hlp@hlp:~/code/github_code/catch_imooc1$ git push origin master Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts. Everything up-to-date
4:參考博文:
https://www.cnblogs.com/sky6862/p/7992736.html
5:聲明:
該博文只是為了規范自己的習慣,如有問題或者建議,請諒解。