# 测试 SSH 连接

设置 SSH 密钥并将其添加到 GitHub 后，可以测试连接。

测试 SSH 连接之前，应已完成以下各项：

* [检查现有 SSH 密钥](/zh/enterprise-server@3.22/authentication/connecting-to-github-with-ssh/checking-for-existing-ssh-keys)
* [生成新 SSH 密钥](/zh/enterprise-server@3.22/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
* [向 GitHub 帐户添加了新的 SSH 密钥](/zh/enterprise-server@3.22/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)

需要使用密码（即之前创建的 SSH 密钥密码）来验证此操作。 请参阅“[使用 SSH 密钥密码](/zh/enterprise-server@3.22/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases)”。

1. 打开<span class="platform-mac">终端</span><span class="platform-linux">终端</span><span class="platform-windows">Git Bash</span>。

2. 输入以下内容：

   ```shell copy
   ssh -T git@HOSTNAME
   # Attempts to ssh to GitHub
   ```

   您可能会看到类似如下的警告：

   ```shell
   > The authenticity of host 'HOSTNAME (IP ADDRESS)' can't be established.
   > ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
   > Are you sure you want to continue connecting (yes/no)?
   ```

3. 验证所看到消息中的指纹是否与 企业的公钥指纹匹配。 如果是，则键入 `yes`：

   ```shell
   > Hi USERNAME! You've successfully authenticated, but GitHub does not
   > provide shell access.
   ```

   <div class="ghd-tool linux">

   你可能会看到此错误消息：

   ```shell
   ...
   Agent admitted failure to sign using the key.
   debug1: No more authentication methods to try.
   Permission denied (publickey).
   ```

   这是某些 Linux 发行版的已知问题。 有关详细信息，请参阅“[错误：代理承认没有签署](/zh/enterprise-server@3.22/authentication/troubleshooting-ssh/error-agent-admitted-failure-to-sign)”。

   </div>

   > \[!NOTE]
   > 远程命令应以代码 1 退出。

4. 验证生成的消息包含您的用户名。 如果收到“权限被拒绝”消息，请参阅“[错误：权限被拒绝（公钥）](/zh/enterprise-server@3.22/authentication/troubleshooting-ssh/error-permission-denied-publickey)”。