git config credential.helper 记住保存账号密码、关闭取消密码自动存储

参考文档:https://www.cnblogs.com/wutou/p/17585668.html

git config credential.helper 记住保存账号密码、关闭取消密码自动存储

 

git 记住账号密码:

说明:

Git支持多个配置文件,包括全局配置文件、系统配置文件和仓库配置文件。

Git 使用简单的 .ini 文件作为配置文件,配置文件中记录了很多 Git 命令使用的各种选项和设置,Git 支持不同级别的配置文件,下面按照优先级从高到低的顺序对它们进行介绍:

.git/config 当前版本库特定的配置文件,可使用 --file选项修改,是Git的默认选项,此文件中的设置具有最高优先级。

~/.gitconfig 当前用户的配置文件,可使用 --global选项修改。

/etc/gitconfig 系统级别的配置文件,可使用 --system 选项修改,此文件中的设置优先级最低。(Windows 的etc路径在你安装git目录下,默认"C:\Program Files\Git\etc\gitconfig" )


注意:不要将配置文件路径设置到项目文件夹里,会泄露账号密码
注意:不要将配置文件路径设置到项目文件夹里,会泄露账号密码
注意:不要将配置文件路径设置到项目文件夹里,会泄露账号密码

 

 

一、系统级

 

整台电脑上的所有用户都有效:(不推荐)
Windows 配置项写入到 "C:\Program Files\Git\etc\gitconfig" 文件中。
Linux 配置项写入到 "/etc/gitconfig" 文件中。

 

如果没有配置过,gitconfig 文件可能不存在

 

1.设置记录账户密码,模式为 store

  git config --system credential.helper store

 

2.取消(删除)记录账号和密码

 

  git config --system --unset credential.helper

 

3.查询 凭证存储模式

 

  git config --system credential.helper
 
  git config --system --list
 
  git config --system -l

 

4.修改 配置文件

 

  git config --file="C:\Program Files\Git\etc\gitconfig" --system credential.helper "store"
 
  git config --system user.name "store"

 

以上命令,不推荐使用:

 

1.需要在git bash上右键--"以管理员身份运行" 或 需要给 C:\Program Files\Git\下 etc 文件夹,everyone 完全控制权限,才能执行成功。
2.如果没有权限会提示 “error: could not lock config file C:/Program Files/Git/etc/gitconfig: Permission denied”


二、用户级

 

当前用户下,所有项目有效:
配置项写入到 "C:\Users\用户名\ .gitconfig" 文件中。

 

1.设置账号密码当前登录用户,全局项目 git 仓库有效

 

  git config --global credential.helper store
 
  git config --global credential.helper manager

 

2.取消(删除)记录账号和密码

 

  git config --global --unset credential.helper

 

3.查询 凭证存储模式

 

  git config --global credential.helper
 
  git config --global --list
 
  git config --global -l

 

4.修改 配置文件

 

  git config --file=~/.git_credentails --global credential.helper "store"
 
  git config --global user.name "store"


三、项目级

 

只在当前项仓库下有效,在有 .git 文件夹下执行:
配置项写入到项目的 ".git/config" 文件中。

 

1.设置账号密码当前项目 git 仓库有效

 

  git config credential.helper store

 

如果没有--global,则在当前项目下的.git/config文件中添加。

 

2.取消(删除)记录账号和密码

 

  git config --unset credential.helper

 

3.查询 凭证存储模式

 

  git config credential.helper
 
  git config --list
 
  git config -l

 

如果当前项目下没有设置,则显示 --global 的模式

 

4.修改 配置文件

 

  git config --file=.git/config credential.helper "store"
 
  git config user.name "store"


四、临时记住密码

 

1)默认记住15分钟:

 

  git config --global credential.helper cache

 

2)记住1小时:

 

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


五、其他:

 

1.可选凭证存储模式

 

https://zhuanlan.zhihu.com/p/157751660

 

  • "cache" 模式
    会将凭证存放在内存中一段时间。 密码永远不会被存储在磁盘中,并且在15分钟后从内存中清除。

  • "store" 模式
    会将凭证用明文的形式存放在磁盘中,并且永不过期。
    这意味着除非你修改了你在 Git 服务器上的密码,否则你永远不需要再次输入你的凭证信息。
    这种方式的缺点是你的密码是用明文的方式存放在你的 home 目录下。查看命令:

 

  cat ~/.git-credentials-store

 

请注意,存储凭证可能会带来安全风险,因为它会在你的本地机器上以纯文本形式保存你的密码。

 

  • "osxkeychain" 模式
    如果你使用的是 Mac,Git 还有一种 “osxkeychain” 模式,它会将凭证缓存到你系统用户的钥匙串中。
    这种方式将凭证存放在磁盘中,并且永不过期,但是是被加密的,这种加密方式与存放 HTTPS 凭证以及 Safari 的自动填写是相同的。

  • "manager" 模式
    如果你使用的是 Windows,你可以安装一个叫做 “Git Credential Manager for Windows” 的辅助工具。
    这和上面说的 “osxkeychain” 十分类似,但是是使用 Windows Credential Store 来控制敏感信息。

 

2.如果是 manager 模式

 

https://www.jianshu.com/p/8d8fb86e415a

 

使用命令后,凭据会被记录到系统的凭据管理里。
位置: 控制面板--用户账户--凭据管理--windows凭据,查看和删除。

 

借用网友的图片:

 

.命令行添加到管理凭据

1)删除某个存储在 “windows凭据” 的账号密码

  cmdkey /delete:git:https://gitee.com

2)添加某个存储在 "windows凭据" 的账号密码

  cmdkey /generic:git:http://gitee.com /user:%username% /password:%password%

1.或者可以在 “windows 凭据” 管理界面,点击 “添加普通凭证”
2.%username% 和 %password% 代表当前登录Windows用户的账号密码
3.提示“找不到元素”,可能是凭据名称输入错误

 

 

 

posted @   小小仓鼠  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
历史上的今天:
2024-02-19 FastJSON学习
2024-02-19 echarts自适应问题,echarts中怎么改变字体单位实现自适应
点击右上角即可分享
微信分享提示