# 创建 SSH 配置

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

> **TL;DR**
> 所需插件：  FTP/SFTP/WebDAV 连接 （捆绑）

在 CLion 中，您可以将远程服务器的 SSH 连接参数保存为专用的 SSH 配置。 创建的配置随后可用于 [配置远程解释器](null)、 [连接到 SFTP 部署服务器](creating-a-remote-server-configuration.html)或 [启动 SSH 会话](running-ssh-terminal.html)。

Procedure:

1. 在   设置  对话框 ( `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `⌘ Comma` (Xcode), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (ReSharper), `⌘ Comma` (ReSharper (macOS)), `Ctrl+Alt+S` (QtCreator), `⌘ Comma` (QtCreator (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) 中，前往  `工具 | SSH 配置` 。

2. 在左侧窗格中，点击 ![添加 项目](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg)。

3. ![SSH 配置对话框](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ssh_configs_dialog.png)

使用   仅对该项目可见  复选框以启用在其他项目中重用此服务器访问配置。

* 选中复选框以将 SSH 配置的使用限制于当前项目。 这样的 SSH 配置无法在当前项目之外重用。 它没有出现在其他项目的可用配置列表中。 项目特定配置存储在 `.idea` 目录中。 在 [通过版本控制](version-control-integration.html) 共享这些文件之前，请先检查这些文件。 可供所有项目使用的服务器配置存储在 IDE 设置中。

* 当复选框被清除时，SSH 配置在所有 CLion 项目中是可见的。 其设置可以在多个项目中重复使用。

4. 在   主机  、   用户名   和   端口   字段中，指定连接参数。

5. 选择认证到服务器的方式。 请执行以下操作之一：

* 密码 ：使用密码访问主机。 要在 CLion 中保存密码，请选择 保存密码 复选框。

* 密钥对（OpenSSH 或 PuTTY） ：使用 [SSH 认证](https://www.ssh.com/)与密钥对。 要应用此身份验证方法，您必须在客户端计算机上拥有私钥，并在远程服务器上拥有公钥。 CLion 支持使用 [OpenSSH](https://www.openssh.com/) 工具生成的私钥。 指定存储您的 private key 的文件路径，并在相应的字段中输入密码短语（如果有）。 要让 CLion 记住密码短语，请选中 保存密码短语 复选框。

* OpenSSH 配置和认证代理 ：使用管理您的 SSH 密钥的凭据助手应用程序，例如 [ssh-agent](https://en.wikipedia.org/wiki/Ssh-agent) 或 [Pageant（仅限 Windows）](https://the.earth.li/~sgtatham/putty/0.70/htmldoc/Chapter9.html#pageant)。 > **Tip:** > 如果您同时运行了 OpenSSH ssh-agent 和 Pageant，即使 ssh-agent 中没有任何密钥，也只会使用 ssh-agent。

有关使用 SSH 密钥的更多信息，请参考 [生成新的 SSH 密钥并将其添加到 ssh-agent 的教程](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/)。

6. 请点击   测试连接  按钮以确保设置正确且 CLion 可以连接到目标服务器。

> **Note:**
> 请注意，创建的 SSH 服务器配置  尚未 成为 [部署服务器配置](deploying-applications.html)。 如果您需要将应用程序部署到远程 SSH 服务器，则需要创建 SFTP 类型的部署服务器配置。 详情请参见 [远程服务器配置](creating-a-remote-server-configuration.html)。

> **Tip: OpenSSH 日志**
> 要对 SSH 连接进行故障排除，请查看 [IDE 日志](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#logs-directory)。 对于身份验证错误，还要检查 SSH 服务器日志或咨询服务器管理员。 其位置取决于服务器操作系统和配置。
>
>
>
> 例如，在 Fedora 服务器上，运行  `sudo journalctl -u sshd.service`  以查看 SSH 服务器日志。 这些日志可以帮助识别身份验证失败和被拒绝的连接。

## 支持的 OpenSSH 指令

使用   OpenSSH 配置和认证代理   时，CLion 会读取 SSH 配置文件。 在  `设置 | 高级设置 | SSH | 配置文件解析器`  中选择读取方式。

默认的   OpenSSH   选项要求计算机上有 OpenSSH，并运行  `ssh -G`  来读取配置。 然后，CLion 会应用其 SSH 实现支持的设置，而不是每项 OpenSSH 功能。

遗留   选项使用内置于 CLion 的解析器，该解析器支持以下指令：

* [AliveInterval](https://man.openbsd.org/ssh_config#ServerAliveInterval)

* [ClearAllForwardings](https://man.openbsd.org/ssh_config#ClearAllForwardings)

* [压缩](https://man.openbsd.org/ssh_config#Compression)

* [ConnectTimeout](https://man.openbsd.org/ssh_config#ConnectTimeout)

* [ForwardAgent](https://man.openbsd.org/ssh_config#ForwardAgent)

* [ForwardX11](https://man.openbsd.org/ssh_config#ForwardX11)

* [ForwardX11Trusted](https://man.openbsd.org/ssh_config#ForwardX11Trusted)

* [GSSAPIAuthentication](https://man.openbsd.org/ssh_config#GSSAPIAuthentication)

* [HashKnownHosts](https://man.openbsd.org/ssh_config#HashKnownHosts)

* [主机](https://man.openbsd.org/ssh_config#Host)

* [主机名](https://man.openbsd.org/ssh_config#Hostname)

* [IdentitiesOnly](https://man.openbsd.org/ssh_config#IdentitiesOnly)

* [IdentityAgent](https://man.openbsd.org/ssh_config#IdentityAgent)

* [本地转发](https://man.openbsd.org/ssh_config#LocalForward)

* [PreferredAuthentications](https://man.openbsd.org/ssh_config#PreferredAuthentications)

* [ProxyCommand](https://man.openbsd.org/ssh_config#ProxyCommand)

* [RemoteForward](https://man.openbsd.org/ssh_config#RemoteForward)

* [ServerAliveCountMax](https://man.openbsd.org/ssh_config#ServerAliveCountMax)

* [StrictHostKeyChecking](https://man.openbsd.org/ssh_config#StrictHostKeyChecking)

* [UserKnownHostsFile](https://man.openbsd.org/ssh_config#UserKnownHostsFile)

* [XAuthLocation](https://man.openbsd.org/ssh_config#XAuthLocation)

> **Note:**
> 使用   遗留   解析器时，  `ForwardAgent`  仅在启用  `ssh.agent.forwarding`  注册表选项时生效。 此选项默认已启用。

