使用 SSH 密钥
当您使用 SSH 密钥而不是凭据助手从 Git 仓库克隆项目时,您需要确保本地 SSH 代理正在运行。
如果 SSH 代理正在运行,您可以使用 ssh-add 命令将本地 SSH 密钥添加到代理中。
请查看以下示例:
ssh-add $HOME/.ssh/<your ssh key>
故障排查
由于 SSH agent 默认情况下在这些系统上未运行,您可能会在 Linux 和 Windows 上收到错误。 在 macOS 上,SSH agent 默认是运行的。
要解决此类问题,请按照以下步骤操作:
确保以管理员身份运行本地 PowerShell。
输入以下命令:
Set-Service ssh-agent -StartupType Automatic Start-Service ssh-agent Get-Service ssh-agent
使用以下命令启动 SSH 代理:
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日