You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

git-credential-store无法自动提供凭证,Git操作仍需输密码求助

问题原因与解决方法

核心问题:Git credential helper 默认不处理带自定义端口的SSH凭证,且SSH协议场景下更推荐用密钥认证而非密码存储

解决步骤:

1. 修正凭证存储的端口缺失问题

你当前的.git-credentials未包含SSH端口22322,Git无法匹配到目标服务器。重新执行git credential fill,输入以下内容:

protocol=ssh
host=my-nas.local:22322
username=gituser
password=My-S3cr3t-P4ssw0rd

按Ctrl+D提交后,.git-credentials内容会更新为:

ssh://gituser:My-S3cr3t-P4ssw0rd@my-nas.local:22322

2. 确保Git启用credential-store helper

需要在全局配置中明确启用凭证存储,执行命令:

git config --global credential.helper 'store --file ~/.git-credentials'

或手动编辑~/.gitconfig添加:

[credential]
    helper = store --file ~/.git-credentials

3. 更可靠的替代方案:SSH密钥认证

SSH协议本身更适合用密钥对实现免密操作,步骤如下:

  • 在MacBook生成SSH密钥(无密钥时执行):
    ssh-keygen -t ed25519 -C "your-email@example.com"
    
    全程回车默认生成,密钥存于~/.ssh/id_ed25519。
  • 将公钥同步到NAS的gituser账户:
    ssh-copy-id -p 22322 gituser@my-nas.local
    
    输入一次密码后,后续SSH连接无需再输入密码。
  • 验证连接有效性:
    ssh -p 22322 gituser@my-nas.local
    
    能直接登录则配置成功,Git操作会自动使用密钥认证。

原配置失效的原因

  • 凭证未包含自定义SSH端口,Git无法匹配目标服务器;
  • 可能未全局配置credential helper,导致Git未启用凭证存储功能;
  • Git credential helper对SSH协议的支持不如HTTPS完善,密钥认证是SSH场景下的标准做法。

内容的提问来源于stack exchange,提问作者AckThpfft

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 07:52:06