# Build Ubuntu image with base functionality. FROM ubuntu:focal AS ubuntu-base ENV DEBIAN_FRONTEND noninteractive SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Setup the default user. RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo ubuntu RUN echo 'ubuntu:ubuntu' | chpasswd USER ubuntu WORKDIR /home/ubuntu # Build image with Python and SSHD. FROM ubuntu-base AS ubuntu-with-sshd USER root # Install required tools. RUN apt-get -qq update \ && apt-get -qq --no-install-recommends install vim-tiny=2:8.1.* \ && apt-get -qq --no-install-recommends install sudo=1.8.* \ && apt-get -qq --no-install-recommends install python3-pip=20.0.* \ && apt-get -qq --no-install-recommends install openssh-server=1:8.* \ && apt-get -qq clean \ && rm -rf /var/lib/apt/lists/* # Configure SSHD. # 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 RUN mkdir /var/run/sshd RUN bash -c 'install -m755 <(printf "#!/bin/sh\nexit 0") /usr/sbin/policy-rc.d' RUN ex +'%s/^#\zeListenAddress/\1/g' -scwq /etc/ssh/sshd_config RUN ex +'%s/^#\zeHostKey .*ssh_host_.*_key/\1/g' -scwq /etc/ssh/sshd_config RUN RUNLEVEL=1 dpkg-reconfigure openssh-server RUN ssh-keygen -A -v RUN update-rc.d ssh defaults # Configure sudo. RUN ex +"%s/^%sudo.*$/%sudo ALL=(ALL:ALL) NOPASSWD:ALL/g" -scwq! /etc/sudoers # Generate and configure user keys. USER ubuntu RUN ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 #COPY --chown=ubuntu:root "./files/authorized_keys" /home/ubuntu/.ssh/authorized_keys # Setup default command and/or parameters. EXPOSE 22 CMD ["/usr/bin/sudo", "/usr/sbin/sshd", "-D", "-o", "ListenAddress=0.0.0.0"]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter