最新消息:20210917 已从crifan.com换到crifan.org

【已解决】git记住密码不要每次都提示输入

Git crifan 5183浏览 0评论

之前每次git pull都提示要输出用户名和密码:

<code>[root@x-general-01 x]# git pull
Username for 'https://gitee.com': xxx
Password for 'https://x_crifan@gitee.com': 
</code>

很是麻烦。

希望:

git 记住密码

Git 保存用户名和密码 – 简书

git保存用户名密码的方式 – 简书

https://www.jianshu.com/p/3948a96cec54

<code>git config --global credential.helper store
</code>

即可。

但是去参考:

https://www.jianshu.com/p/3948a96cec54

发现的确是:

密码会被明文保存在了:

<code>[root@x-general-01 x]# cat ~/.git-credentials
https://user:your_pwd@gitee.com
</code>

很不安全啊

所以还是删了这个文件吧

<code>[root@x-general-01 x]# rm ~/.git-credentials 
rm: remove regular file ‘/root/.git-credentials’? y
</code>

然后想办法设置密码有效期,在有效期内,不用输入

一个月=2592000秒

<code>[root@x-general-01 x]# git config --global user.user x_crifan
[root@x-general-01 x]# git config --global user.email crifan.li@x.com
[root@x-general-01 x]# git config credential.helper 'cache --timeout=2592000'
</code>

等过些天(1个月内),看看是否生效,是否还要输入。

后来确认了,1个月内,都不需要再输入密码了。

【总结】

如果想要长期保存密码,则可以用:

<code>git config --global credential.helper store
</code>

但是有个缺点:

密码会被明文形式保存在:

<code>~/.git-credentials
</code>

觉得不安全。

所以就删除

~/.git-credentials

然后用:

<code>git config --global user.user x_crifan
git config --global user.email crifan.li@x.com
git config credential.helper 'cache --timeout=2592000'
</code>

其中2592000秒=30天=1个月

表示:记住密码,有效期是一个月,一个月内不需要再输入密码。

【后记20181225】

后来去CentOS中,记住了密码后,发现没有

~/.git-credentials

只有

<code>[xxx]# ls ~/.git-credential-cache/ -lh
total 0
srwxr-xr-x 1 root root 0 Nov 27 21:40 socket
[root@x x]# cat ~/.git-credential-cache/socket 
cat: /root/.git-credential-cache/socket: No such device or address
</code>

没有明文可以查看的。

不过倒是用config记录了user和email:

<code>cat ~/.gitconfig 
[user]
        user = x_crifan
        email = crifan.li@x.com
</code>

不过没有包含密码信息,所以也没关系的。

转载请注明:在路上 » 【已解决】git记住密码不要每次都提示输入

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.191 seconds, using 23.33MB memory