git每次操作提示输入密码问题解决

git每次pull提示需要密码

错误提示

Administrator@DEEP MINGW64 /f/code/xxx-service (master)
$ git pull
git@gitlab.xxx.com's password:

原因

只提示输入密码的情况,一般是秘钥验证失败。二种情况

1. 公钥验证错误

解决方法如下,以github为例

在https://github.com/settings/keys 界面,将生成的公钥添加到SSH keys项中

如没有则使用ssh-keygen命令生成

ssh-keygen -t rsa -C "Your Email Address" -f "~/.ssh/gitlab_id_rsa"

2. 私钥验证错误

git拉取代码时没有配置私钥认证

使用以下命令添加认证到ssh

ssh-add ~/.ssh/gitlab_id_rsa

使用以上命令,只能对当前环境生效,重启或新开终端会继续提示输入密码

永久解决:在~/.ssh/config文件中(没有则新建),指定对应git服务使用的认证秘钥文件即可

# GitLab.com 密钥
Host github.com
  Preferredauthentications publickey
  IdentityFile ~/.ssh/github_id_rsa

# GitLab.com 密钥
Host gitlab.xxx.com
  Preferredauthentications publickey
  IdentityFile ~/.ssh/gitlab_id_rsa

结束

  1. 直接提示输入密码的,为秘钥认证失败,使用以上方法即可解决
  2. 提示输入账号和密码的,为账号认证失败,使用git config --global credential.helper store 命令,可输入一次密码后永久存储
posted @ 2019-06-28 17:14  JaminX86  阅读(7697)  评论(0编辑  收藏  举报