# 在容器中使用 SSH

{% hint style="warning" %}
Edgegap 不建议在生产部署中开放 SSH 服务访问。
{% endhint %}

### 修改您的 Dockerfile

我们将使用不同的 Docker 构建此容器 `Dockerfile` 在此版本中。

我们需要安装 OpenSSH 服务并启用它，创建一个用户和密码以连接到您的服务器。

在运行于 **Alpine**, 合并以下内容：

```dockerfile
RUN apk --update add --no-cache openssh bash
RUN sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config
RUN echo "tester:$ecureP@ss" | chpasswd

EXPOSE 22
```

在运行于 **Ubuntu**，添加以下内容：

```dockerfile
RUN apt-get update
RUN apt-get install openssh-server sudo -y

RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000
RUN echo 'tester:$ecureP@ss' | chpasswd

EXPOSE 22
```

在您的 entrypoint 中，您需要添加以下命令：

```sh
service ssh start
```

我们建议在本地测试部署，使用 docker run 命令测试服务器启动。

测试完成后，您可以将新版本推送到容器仓库。

### 在 Edgegap 上

我们建议有一个名为 `-dev` 或其他对您的服务有意义的名称。这样，您将能够执行一些测试并通过 Edgegap 基础设施轻松登录到您的容器。

1. 创建应用的新版本，添加 `公开 TCP 端口 22`
2. 使用您刚创建的新版本创建部署
3. 一旦服务运行（就绪），查看您的部署信息。您将看到端口 22 的外部端口映射。
4. 您可以使用 Putty，使用部署的 FQDN 或 IP 与所使用的端口映射进行连接
5. 以及您配置的用户名和密码。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edgegap.com/zh/docs/tools-and-integrations/container/ssh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
