From daae49a3e34b4f1e06c49980a362afb8e2740c76 Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:30:43 -0400 Subject: [PATCH] Add non-root user --- Dockerfile.devenv | 53 ++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/Dockerfile.devenv b/Dockerfile.devenv index 3de9b8f..86cee07 100644 --- a/Dockerfile.devenv +++ b/Dockerfile.devenv @@ -1,32 +1,47 @@ # docker build --file Dockerfile-devenv.txt -t devenv . # docker run -it --name devenv -p 4200:4200 -d devenv zsh FROM ubuntu:latest -WORKDIR /root +ARG USERNAME=user +ARG USER_UID=1000 +ARG USER_GID=$USER_UID -RUN apt-get update -RUN apt-get upgrade -y -RUN apt-get install zsh git curl bash vim nano openssh-server shellinabox -y -RUN chsh -s $(which zsh) + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +WORKDIR /home/$USERNAME +USER $USERNAME + + +RUN sudo apt-get update +RUN sudo apt-get upgrade -y +RUN sudo apt-get install zsh git curl bash vim nano openssh-server shellinabox -y +RUN sudo chsh -s $(which zsh) $USERNAME RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended -RUN git clone https://github.com/zsh-users/zsh-autosuggestions.git /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions -RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /root/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting +RUN git clone https://github.com/zsh-users/zsh-autosuggestions.git /home/$USERNAME/.oh-my-zsh/custom/plugins/zsh-autosuggestions +RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /home/$USERNAME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting -RUN curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash +# RUN curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash -RUN echo export ZSH=\"\$HOME/.oh-my-zsh\" > /root/.zshrc -RUN echo ZSH_THEME=\"robbyrussell\" >> /root/.zshrc -RUN echo plugins=\(git zsh-autosuggestions zsh-syntax-highlighting\) >> /root/.zshrc -RUN echo source \$ZSH/oh-my-zsh.sh >> /root/.zshrc -RUN echo service shellinabox start >> /root/.zshrc +RUN echo export ZSH=\"\$HOME/.oh-my-zsh\" > /home/$USERNAME/.zshrc +RUN echo ZSH_THEME=\"robbyrussell\" >> /home/$USERNAME/.zshrc +RUN echo plugins=\(git zsh-autosuggestions zsh-syntax-highlighting\) >> /home/$USERNAME/.zshrc +RUN echo source \$ZSH/oh-my-zsh.sh >> /home/$USERNAME/.zshrc +#RUN echo service shellinabox start >> /home/$USERNAME/.zshrc - -RUN echo "root:password" | chpasswd +USER root +#RUN echo -e "new_password\nnew_password" | (passwd $USERNAME) +RUN echo "$USERNAME:password" | chpasswd RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config RUN sed -i 's/SHELLINABOX_ARGS="--no-beep"/SHELLINABOX_ARGS="--no-beep --disable-ssl"/g' /etc/default/shellinabox - +USER $USERNAME EXPOSE 4200 -# RUN echo "#!/bin/bash\nservice shellinabox start" > /entrypoint.sh -# RUN chmod +x /entrypoint.sh -# ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +#ENTRYPOINT ["service", "shellinabox", "start"]