# 使用 SSH 密钥

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/idea/llms.txt).

当使用 SSH 密钥而不是凭据助手从 Git 仓库克隆项目时，需要确保本地 [SSH 代理](https://www.ssh.com/academy/ssh/agent) 正在运行。

如果 SSH 代理正在运行，可以使用  `ssh-add`  命令将本地 SSH 密钥添加到代理中。

请查看以下示例：

```
ssh-add $HOME/.ssh/<your ssh key>

```

## 故障排除

由于 SSH agent 默认情况下在这些系统上未运行，您可能会在 Linux 和 Windows 上收到错误。 在 macOS 上，SSH agent 默认是运行的。

要解决此类问题，请按照以下步骤操作：

Windows:

Procedure:

1. 确保以管理员身份运行本地 PowerShell。

2. 输入以下命令：

```SHELL
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent

```

Unix / Linux:

Procedure:

1. 使用以下命令启动 SSH 代理：

```SHELL
eval "$(ssh-agent -s)"

```

2. 如果更愿意使用  `Zsh`  shell 而不是  `bash` ，请将以下行添加到  `~/.bash_profile`  或  `~/.zprofile` 。

```BASH
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`

