ubuntu使用git提交github时,执行pull或者push命令要重新输入用户名和密码

ubuntu使用git提交github时,执行pull或者push命令要重新输入用户名和密码:

1:问题现象:

hlp@hlp:~/code/github_code/catch_imooc1$ git push
Username for 'https://github.com': XXXX
Password for 'https://[email protected]': 
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 [email protected]: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:声明:

    该博文只是为了规范自己的习惯,如有问题或者建议,请谅解。

猜你喜欢

转载自www.cnblogs.com/yun6853992/p/9348484.html