Add non-root user

This commit is contained in:
slashtechno 2023-08-20 16:30:43 -04:00
parent 715f4412a6
commit daae49a3e3
1 changed files with 34 additions and 19 deletions

View File

@ -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"]
#ENTRYPOINT ["service", "shellinabox", "start"]