[英]docker image - centos 7 > ssh service not found
I installed docker image - centos 7 on my ubuntu machine. 我在ubuntu机器上安装了docker image-centos 7。 But ssh service not found.
但是找不到ssh服务。 so I cant run this service.
因此我无法运行此服务。
[root@990e92224a82 /]# yum install openssh-server openssh-clients
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirror.dhakacom.com
* extras: mirror.dhakacom.com
* updates: mirror.dhakacom.com
Package openssh-server-6.6.1p1-31.el7.x86_64 already installed and latest version
Package openssh-clients-6.6.1p1-31.el7.x86_64 already installed and latest version
Nothing to do
[root@990e92224a82 /]# ss
ssh ssh-agent ssh-keygen sshd ssltap
ssh-add ssh-copy-id ssh-keyscan sshd-keygen
How can I remotely login docker image? 如何远程登录Docker镜像?
You have to do the following instructions on Dockerfile. 您必须在Dockerfile上执行以下说明。
RUN yum install -y sudo wget telnet openssh-server vim git ncurses-term
RUN useradd your_account
RUN mkdir -p /home/your_account/.ssh && chown -R your_account /home/your_account/.ssh/
# Create known_hosts
RUN touch /home/your_account/.ssh/known_hosts
COPY files/authorized_keys /home/your_account/.ssh/
COPY files/config /home/your_account/.ssh/
COPY files/pam.d/sshd /etc/pam.d/sshd
RUN touch /home/your_account/.ssh/environment
RUN chown -R your_account /home/your_account/.ssh
RUN chmod 400 -R /home/your_account/.ssh/*
RUN chmod 700 -R /home/your_account/.ssh/known_hosts
RUN chmod 700 /home/your_account/.ssh/environment
# Enable sshd
COPY files/sshd_config /etc/ssh/
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
# Add a account into sudoers and this account doesn't need to type his password
COPY files/sudoers /etc/
COPY files/start.sh /root/
I have to remove "pam_nologin.so" on the file /etc/pam.d/sshd, because when I upgrade the openssh-server's version to openssh-server-6.6.1p1-31.el7, the pam_nologin.so will disallow remote login for any users even the file /etc/nologin is not exist. 我必须删除文件/etc/pam.d/sshd上的“ pam_nologin.so”,因为当我将openssh-server的版本升级到openssh-server-6.6.1p1-31.el7时,pam_nologin.so将不允许远程即使文件/ etc / nologin不存在,也可以为任何用户登录。
start.sh start.sh
#!/bin/bash
/usr/sbin/sshd -E /tmp/sshd.log
Start centos container 启动centos容器
Login container 登录容器
In extend to @puritys 在扩展到@puritys
You could do this in the Dockerfile instead 您可以改为在Dockerfile中执行此操作
Last in the file: 文件中的最后一个:
ENTRYPOINT /usr/sbin/sshd -E /tmp/sshd.log && /bin/bash
Then you will only need to run: 然后,您只需要运行:
docker run -d -p -t $(sshPort):22 --name $(containerName) $(imageName) /bin/bash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.