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" )


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


一、系统级

整台电脑上的所有用户都有效:(不推荐)
配置项写入到 "C:\Program Files\Git\etc\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 目录下。

  • "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凭据,查看和删除。

借用网友的图片:
image


3.命令行添加到管理凭据

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.提示“找不到元素”,可能是凭据名称输入错误

image

添加后,凭据管理界面,返回 或 重新点击“windows 凭据” 刷新显示,新的凭据




来源:
https://blog.csdn.net/zhiyuan2021/article/details/124469882
https://blog.csdn.net/wzy901213/article/details/84334163
https://blog.csdn.net/yubin1285570923/article/details/87957959
https://blog.csdn.net/sean_8180/article/details/82710944
https://blog.51cto.com/u_5650011/5387085
https://blog.csdn.net/zhulianseu/article/details/122566902
https://zhuanlan.zhihu.com/p/343530933 (设置文件夹 everyone 权限,图文说明)



posted @ 2023-07-27 17:43  悟透  阅读(6524)  评论(0编辑  收藏  举报