简体   繁体   中英

Can't ssh to docker(ubuntu:19.04) because of happen permission denied

I made ssh service docker from this Dockerfile.

FROM ubuntu:19.04

RUN apt-get update && apt-get install -y openssh-server \
   postgresql-client \
   language-pack-ja

RUN update-locale LANG=ja_JP.UTF-8

RUN mkdir /var/run/sshd
ARG ROOT_PASSWORD
RUN echo root:${ROOT_PASSWORD} | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

I followed this page.
https://docs.docker.com/engine/examples/running_ssh_service/

It is differently that only changed ubuntu image version to 19.04.

However, I couldn't ssh as happened permission denid.

docker build --build-arg ROOT_PASSWORD=$ROOT_PASSWORD -t eg_sshd .

docker run -d -P --name test_sshd eg_sshd

docker port test_sshd 22
0.0.0.0:32770

ssh root@localhost -p 32770
root@localhost's password:
Permission denied, please try again.

Why did It happen permission denied?

The PermitRootLogin line was not comment out when it was 16.04, however comment out when it was 18.04, so I set it to #\\? in order to accommodate both.

It could execut from following Dockerfile.

FROM ubuntu:19.10

RUN apt-get update && apt-get install -y openssh-server

RUN mkdir /var/run/sshd

RUN echo 'root:root' | chpasswd
RUN sed -i 's/#\?PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM