# 共享凭证

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

在远程服务器上构建 Dev Container 时，访问远程服务器和克隆项目需要身份验证。 支持的身份验证方法是使用 SSH 密钥或密码。

如果您有密码认证，请参阅以下步骤以了解如何生成包含 SSH 密钥的文件，将其转发到远程服务器并共享您的 Git 凭据。

Procedure: 创建并转发 SSH 密钥

1. 打开本地终端，并使用以下命令生成 SSH 密钥：

```SHELL
ssh-keygen
```

> **Note:**
> 有关 SSH 密钥的更多信息，请参阅 [SSH](https://www.ssh.com/academy/ssh/agent)文档。

系统会生成密钥对。 默认情况下，它将存储在您的  `~/.ssh/`  文件夹中，其中  `~`  是您的主目录。 公钥将与私钥存储在相同的位置。 它以与私钥相同的名称开始，并有一个  `.pub` 后缀。 例如，  `id_rsa` 和  `id_rsa.pub` 。 如果需要，您可以更改 key-pair 位置。

因此，您在本地机器上拥有了 SSH 密钥对文件。

2. 在生成密钥对之后，使用以下命令将密钥安装到远程服务器上：

```SHELL
ssh-copy-id your_remote_server_name
```

密钥已添加到远程服务器，您可以构建开发容器。 有关更多信息，请参阅 [SSH 文档](https://www.ssh.com/academy/ssh/copy-id#copy-the-key-to-a-server)。

3. 连接远程服务器并将项目克隆到开发容器。

![添加新的 Dev Container](https://resources.jetbrains.com/help/img/idea/2026.3/remote_server_dev_container.png)有关更详细的信息，请参阅 [Dev Container 概述](connect-to-devcontainer.html)。

4. 请确保您已在 GitHub 上完成身份验证。 您可以使用 [SSH agent forwarding](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/using-ssh-agent-forwarding#setting-up-ssh-agent-forwarding)或登录您的 GitHub 帐户。

![Git 登录](https://resources.jetbrains.com/help/img/idea/2026.3/github_login_dev_container.png)

5. 在 Dev Container 环境准备好之后，点击   继续   打开项目。

![环境已准备就绪](https://resources.jetbrains.com/help/img/idea/2026.3/cloning_to_dev_container.png)

