使用 SSH 密钥
当您从 Git 仓库克隆项目时,如果使用的是 SSH 密钥而非凭据助手,您需要确保本地 SSH agent 正在运行。
如果 SSH agent 正在运行,您可以通过 ssh-add 命令将本地 SSH 密钥添加到 agent。
请查看以下示例:
ssh-add $HOME/.ssh/<your ssh key>
故障排除
在 Linux 和 Windows 上,可能会因为系统默认未运行 SSH agent 而出现错误。 在 macOS 上,SSH agent 默认运行。
要解决此类问题,请按照以下步骤操作:
请确保已以管理员身份运行本地 PowerShell。
输入以下命令:
Set-Service ssh-agent -StartupType Automatic Start-Service ssh-agent Get-Service ssh-agent
使用以下命令启动 SSH agent:
eval "$(ssh-agent -s)"如果您更愿意使用
Zshshell 而非bash,请将以下内容添加到~/.bash_profile或~/.zprofile。if [ -z "$SSH_AUTH_SOCK" ]; then # Check for a currently running instance of the agent RUNNING_AGENT="`ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]'`" if [ "$RUNNING_AGENT" = "0" ]; then # Launch a new instance of the agent ssh-agent -s > $HOME/.ssh/ssh-agent fi eval `cat $HOME/.ssh/ssh-agent` > /dev/null ssh-add $HOME/.ssh/<your ssh key> 2> /dev/null fi在建议代码的最后一行,将 <your ssh key> 替换为您的具体 ssh 密钥。 例如,
ssh-add $HOME/.ssh/id_ed344 2> /dev/null
最后修改日期: 2025年 9月 26日