网站首页 全球最实用的IT互联网站!

人工智能P2P分享Wind搜索发布信息网站地图标签大全

当前位置:诺佳网 > 软件工程 > 软件工程 > 软件工程其他 >

Git 免密认证:Git Credential Helper

时间:2025-10-29 15:15

人气:

作者:admin

标签:

导读:提到 Git 免密,也许大多数人会想到 SSH。但是当 SSH 不可用的时候怎么办? 比如你没有提交 SSH 公钥的权限。 又比如自建的 Git,如果所有域名都在 Cloudflare 的保护下,不想暴露 ip 地址,...

提到 Git 免密,也许大多数人会想到 SSH。但是当 SSH 不可用的时候怎么办?

比如你没有提交 SSH 公钥的权限。

又比如自建的 Git,如果所有域名都在 Cloudflare 的保护下,不想暴露 ip 地址,就只能用 https。(PS: 这种情况也可以用 Cloudflare Tunnel,而且需要客户端额外配置,不是很推荐)

Git Credential Helper

Git Credential Helper 就是解决在 HTTPS 协议下 Git 操作时需要频繁输入密码或者 PAT 的痛点。

设置仅需一行代码:

git config --global credential.helper <helper_name>

macOS

git config --global credential.helper osxkeychain

Windows

新版的 Windows Git 应该自动安装了 GCM,无需单独设置。

git config --global credential.helper manager
# 或者
git config --global credential.helper wincred

Linux

如果有桌面环境,可以存到GNOME Keyring 或者 KDE Wallet

git config --global credential.helper libsecret

如果没有,可以看下面的

通用方法

  1. Cache

    默认在内存中持续15分钟,如果有需要可以延长时间。

    git config --global credential.helper cache
    # 一小时
    git config --global credential.helper 'cache --timeout=3600'
    
  2. Store

    这种方法不安全,因为是明文存储,不要在公共环境或者生产环境使用,仅作为最后的手段。

    git config --global credential.helper store
    # 或者指定位置
    git config --global credential.helper 'store --file ~/.my-credentials'
    
  3. GCM: Git Credential Manager

    安装方法见:

    1. https://github.com/git-ecosystem/git-credential-manager/blob/release/docs/install.md

    2. https://docs.github.com/en/get-started/git-basics/caching-your-github-credentials-in-git

    据称只要安装,无需配置即可使用。

    对于Windows 用户来说,只要安装了 GCM,所有的 WSL 均可分享凭证,很方便。

参考资料:

  1. 7.14 Git Tools - Credential Storage
  2. Git credential helpers
温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信