GIT 密码/凭证管理

设置记住密码:

# 默认缓存(默认15分钟)
git config --global credential.helper cache
# 指定缓存时长
git config credential.helper 'cache --timeout=3600'
# 长期存储密码
git config --global credential.helper store

增加远程地址的时候带上密码也是可以的(不建议)

# 进入仓库所在目录
cd projectfolder/
# 移除远程ssh方式的仓库地址
git remote rm origin
# 增加https远程仓库地址
git remote add origin http://yourname:password@git.oschina.net/name/project.git

http(s)->ssh

# 生成密钥对
ssh-keygen -t RSA -C email@email.com
# 添加 id_rea.pub 到仓库

# 如果本地仓库是使用的 http(s) 的需要执行如下操作,如果本身就是 ssh 克隆的,请忽略
git remote rm origin
git remote add origin git@gitee.com:{your path}/{project name}.git

重置凭证

当密码修改或重置后,也需要同步修改 credential 中的密码,可以使用如下命令,重置 credential 存储的密码

# 重置所有密码。也可以通过参数重置指定范围内的密码。具体请参照 git credential --help
git credential reject

# 或者
git config --global --unset credential.helper
git config --system --unset credential.helper
### 如何在 Windows 上管理 Git 凭证存储和凭据助手配置 #### 设置凭证助手 为了简化与远程仓库交互时的身份验证过程,可以通过配置 `credential.helper` 来指定如何处理凭证。对于 Windows 用户来说,有几种不同的方法可以选择: - **缓存到内存**:通过执行命令 `git config --global credential.helper cache` 可以让 Git凭证临时保存在内存里,默认持续时间为15分钟[^1]。 - **持久化至文件**:如果希望永久保存凭证,则可采用 `store` 方式,这会把用户名密码明文写入本地文件中。启用此功能需运行 `git config --global credential.helper store`。 - **利用 Windows 凭证管理器**:推荐的方式是在 Windows 平台上使用内置的凭证管理系统——Windows Credential Manager (WCM),它能够更安全地管理和保护用户的登录信息。激活该模式只需输入 `git config --global credential.helper manager-core` 即可。 #### 查阅现有配置 要确认当前使用的凭证辅助工具是什么,可以分别针对全局环境或特定项目发出如下指令获取详情: - 对于整个系统的设定:`git config --global credential.helper` - 针对单个项目库内的个性化调整:`git config credential.helper` 以上两条语句将会返回所对应的 `credential.helper` 参数值。 #### 清除已储存的凭证 当不再信任某台计算机或是更换了账户密码之后,应当及时清理旧有的认证记录。具体操作取决于之前选用的是哪种类型的凭证助手: - 如果是基于 WCM 存储的数据,那么应该前往「控制面板」> 「用户帐户」 > 「凭据管理器」界面手动移除相关条目; - 若选择了其他形式(比如 `cache` 或者 `store`),则可能需要重启系统或者删除相应的文本文件来完成清除工作。 ```bash # 示例:查看全局配置中的凭证助手设置 git config --global credential.helper ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值