使用 SSH 密钥
当您使用 SSH 密钥而不是凭据助手从 Git 仓库克隆项目时,需要确保本地 SSH 代理 正在运行。
如果 SSH 代理正在运行,您可以使用 ssh-add 命令将本地 SSH 密钥添加到代理中。
请查看以下示例:
ssh-add $HOME/.ssh/<your ssh key>
疑难解答
由于在这些系统上 SSH 代理默认不运行,您在 Linux 和 Windows 上可能会收到错误。 在 macOS 上,SSH 代理默认运行。
要解决此类问题,请按以下步骤操作:
请确保以管理员身份运行本地 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年 12月 2日