# 运行 SSH 终端

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

> **TL;DR**
> 添加 SSH 配置：  `设置 | 工具 | SSH 配置项`
>
>
>
> 从主菜单启动 SSH 会话：  `工具 | 启动 SSH 会话`
>
>
>
> 配置 SSH 终端：  `设置 | 工具 | SSH 终端`

您可以直接从 IntelliJ IDEA 启动一个  SSH Session 。 通过在专用的 SSH 终端中运行命令，您可以通过 SSH 隧道访问远程 Web 服务器或 Vagrant 实例（虚拟机）上的数据，主要是上传和下载文件。

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: 设置 SSH 终端

1. 确保远程计算机上有 SSH 服务器，并且有可访问该服务器的账户。

2. 在  目标环境  中的 SSH 服务器上注册帐户，并根据服务器策略生成一对 SSH 密钥或密码。

3. 选择远程环境并配置 SSH 终端：

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.

在   连接设置   区域中，选择远程环境：

* 当前 Vagrant ：选择此选项可在当前正在运行的 [Vagrant 虚拟机](vagrant-support.html) 上执行 SSH 终端中的命令。

* SSH 配置 ：选择此选项可在可通过某个 [SSH 配置](create-ssh-configurations.html) 访问的本地或远程 Web 服务器上执行 SSH 终端中的命令。 * 每次运行时选择 SSH 配置 ：如果选择此选项，则每次从主菜单选择 `工具 | 启动 SSH 会话` 时，都必须从弹出窗口中选择所需的配置。 * 如果所需的 SSH 配置未显示在列表中，请点击 设置配置 链接，并在 [SSH 配置](settings-tools-ssh-configurations.html) 页面中定义一个。

要每次使用同一 SSH 连接，请选择一个   SSH 配置  。 要在每次启动会话时选择连接，请选择   每次运行时选择 SSH 配置  。

3.  从   默认编码   列表中，选择要在 SSH 终端中使用的编码。

Procedure: 启动 SSH 终端

1. 在主菜单中，前往  `工具 | 启动 SSH 会话…` 。 或者，调用   帮助 | 查找操作   `Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS))对话框，搜索  start ssh.. ，并选择   启动 SSH 会话  。

2. 根据在  `工具 | SSH 终端` 页面的   设置  对话框（ `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))）中定义的连接设置，可能出现以下行为类型：

* 如果选择了 当前 Vagrant 选项，SSH Terminal 将提供对当前运行的 Vagrant 虚拟机的访问。 有关更多信息，请参见 [Vagrant](vagrant-support.html)。

* 如果选择了 SSH 配置 选项，SSH 终端将会对通过列表中选择的 SSH configuration 访问的服务器上的数据进行控制。 如需更多信息，请参阅 [创建 SSH 配置](create-ssh-configurations.html)。

* 如果已选择 每次运行时选择 SSH 配置 选项，IntelliJ IDEA 将显示一个列表以选择所需的 SSH 配置 。

如果在 IntelliJ IDEA 中尚未设置 Vagrant 虚拟机或 SSH 连接，则会打开一个   SSH 会话   对话框，提示您 [创建 SSH 配置](create-ssh-configurations.html)。

Procedure: 查看 SSH 日志

要对 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 服务器日志。 这些日志可帮助识别身份验证失败和被拒绝的连接。

## See also

### 过程

[将文件部署到服务器](deploying-applications.html)

### 参考

[SSH 终端](settings-tools-ssh-terminal.html) [部署](settings-deployment.html)

