linux - SSH 连接要求输入密码连接到 Docker 容器
问题描述
我已经寻找过类似的问题并尝试在我的配置中更改一些内容,但无法提出解决方案。
我正在尝试通过 SSH 连接到 Docker 容器,这是 Dockerfile:
FROM ubuntu
RUN apt-get update && \
apt-get install -y openssh-server
RUN useradd remote_user && \
echo "remote_user:test1234" | chpasswd && \
mkdir /home/remote_user/.ssh -p && \
chmod 700 /home/remote_user/.ssh && \
mkdir -p -m0755 /var/run/sshd
COPY id_rsa.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user && \
chmod 600 /home/remote_user/.ssh/authorized_keys
RUN apt-get install -y php php-mbstring php-xml php-bcmath php-fpm && \
apt-get install -y composer && apt-get install -y vim
RUN apt-get install -y nginx
CMD /usr/sbin/sshd -D
一旦我尝试以“remote_user”身份连接到容器ssh -Tv remote_user@staging.local
(其中“staging.local”是容器IP),我会收到以下消息:
...
...
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/xxx/.ssh/id_rsa RSA SHA256:5QNPe89pdQp+tgE61N9YPaIJEs8QR9DxaChmStfvzBU agent
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: xxx@xxx RSA SHA256:C+VWlGUd4mVywHnh8JWtjL0gmO8cuqUEs4YYCbQGvaE agent
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/xxx/.ssh/id_dsa
debug1: Trying private key: /home/xxx/.ssh/id_ecdsa
debug1: Trying private key: /home/xxx/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/xxx/.ssh/id_ed25519
debug1: Trying private key: /home/xxx/.ssh/id_ed25519_sk
debug1: Trying private key: /home/xxx/.ssh/id_xmss
debug1: Next authentication method: password
remote_user@staging.local's password:
如您所见,它无法连接并要求输入密码。
如果我ls -ll
在我的主机中使用 .ssh 文件夹文件,我有这个:
-rw------- 1 xxx xxx 2610 Jan 3 12:08 id_rsa
-rw-r--r-- 1 xxx xxx 577 Jan 3 12:08 id_rsa.pub
-rw-r--r-- 1 xxx xxx 222 Jan 3 12:25 known_hosts
如果我docker exec
以 root 用户身份进入容器并查看/home/remote_user/.ssh
我拥有的权限:
主文件夹权限:
drwxr-xr-x 1 root root 4096 Jan 3 11:22 home
remote_user文件夹权限:
drwxr-xr-x 1 remote_user remote_user 4096 Jan 3 11:22 remote_user
.ssh文件夹权限:
drwx------ 1 remote_user remote_user 4096 Jan 3 11:22 .ssh
authorized_keys文件权限:
-rw------- 1 remote_user remote_user 577 Jan 3 11:08 authorized_keys
解决方案
如果您转发端口,它应该可以工作:
docker run -p 222:22 your-image
然后 :
ssh -p 222 remote_user@localhost
推荐阅读
- php - 如何强制用户仅在某些页面上进行 http?(PHP)
- python-3.x - 如何在地图功能中使用等待
- javascript - 如何提取打开的窗口数量?
- macos - react-native,调试器冻结 macOS 上的应用程序
- asp.net-web-api - 找不到类型或命名空间名称“ApiController” - 已安装 Nuget
- powershell - Powershell 5.#添加类型加速器并在同一文件中的类中使用
- amazon-web-services - AWS 现场队列 terraform 请求子网
- c++ - 为什么我改编的选择排序算法在 C++ 中不起作用
- c# - 将恢复的文件转换为 .cs
- javascript - 如何删除特定子节点