# 创建 SSH 配置

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

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

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

Procedure: 启用 FTP/SFTP/WebDAV Connectivity 插件

此功能依赖于 [FTP/SFTP/WebDAV Connectivity](https://plugins.jetbrains.com/plugin/13125-ftp-sftp-webdav-connectivity)插件，该插件默认在 IntelliJ IDEA 中捆绑并启用。 如果相关功能不可用，请确保您没有禁用插件。

> **Note:**
> 在未订阅 Ultimate 版的情况下，IntelliJ IDEA 中无法使用 FTP/SFTP/WebDAV 连接插件。

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)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) 打开设置，然后选择  `插件` 。

2. 找到  FTP/SFTP/WebDAV Connectivity  插件并点击   启用  。

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)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))），转到  `工具 | SSH 配置` 。

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

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

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

* 当复选框被清除时，SSH 配置在所有 IntelliJ IDEA 项目中是可见的。 其设置可在多个项目之间复用。

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

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

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

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

* 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. 请点击   测试连接  按钮以确保设置正确且 IntelliJ IDEA 可以连接到目标服务器。

> **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 配置和身份验证代理   时，IntelliJ IDEA 会读取您的 SSH 配置文件。 在  `设置 | 高级设置 | SSH | 配置文件解析器`  中选择读取方式。

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

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

* [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`  注册表选项后才会生效。 此选项默认已启用。

