Skip to content

Commit

Permalink
customisable user and pass args, perms, lots and lots
Browse files Browse the repository at this point in the history
  • Loading branch information
fexofenadine committed Feb 24, 2022
1 parent 9c87aad commit 3f2ab59
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 48 deletions.
51 changes: 21 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,49 @@
# Require: Docker (http://www.docker.io/)
# -----------------------------------------------------------------------------


# Base system is the latest rolling version of Ubuntu.
FROM ubuntu:rolling


# Make sure we don't get notifications we can't answer during building.
ENV DEBIAN_FRONTEND noninteractive
ENV TZ="Etc/UTC"

# defaults if not specified at build time or runtime
ARG USERNAME=master
ARG PASSWORD=password

# Prepare scripts and configs
ADD ./scripts/start /start

# edit start cmd script hardcode username. nasty.
RUN sed -i "s/%USERNAME%/${USERNAME}/g" /start

# Download and install everything from the repos.
RUN apt-get -q -y update; apt-get -q -y dist-upgrade && \
apt-get -q -y install sudo openssh-server && \
# Download and install everything from apt repos.
RUN dpkg-reconfigure debconf --frontend=noninteractive; \
apt-get -q -y update; \
apt-get -q -y dist-upgrade && \
apt-get -q -y install nano sudo openssh-server && \
mkdir /var/run/sshd


# Set root password
RUN echo 'root:password' >> /root/passwdfile

RUN echo root:${PASSWORD} >> /root/passwdfile

# Create user and its password
RUN useradd -m -G sudo master && \
echo 'master:password' >> /root/passwdfile

RUN useradd -m -G sudo ${USERNAME} && \
echo ${USERNAME}:${PASSWORD} >> /root/passwdfile

# Apply root password
RUN chpasswd -c SHA512 < /root/passwdfile && \
rm /root/passwdfile

rm /root/passwdfile

# Port 22 is used for ssh
EXPOSE 22


# Assign /data as static volume.
VOLUME ["/data"]


# Fix all permissions
# Fix startup script permissions
RUN chmod +x /start

# Set default shell to bash
RUN chsh -s /bin/bash master
# Set default user's shell to bash
RUN chsh -s /bin/bash ${USERNAME}

# clean up apt cache
RUN rm -rf /var/lib/apt/lists/*
# clean up apt cache and revert interactivity to normal
#RUN rm -rf /var/lib/apt/lists/*
#RUN dpkg-reconfigure debconf --frontend=teletype

# Starting sshd
CMD ["/start"]


CMD ["/start ${USERNAME}"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Ubuntu Rolling with SSH (Docker)
Ubuntu LTS with SSH (Docker)
=========

A Docker file to build a [docker.io] base container with Ubuntu Rolling and a sshd service
A Docker file to build a [docker.io] base container with Ubuntu LTS and a sshd service
[docker.io]: http://docker.io
Nice and easy way to get any server up and running using docker

Expand All @@ -14,7 +14,7 @@ Instructions

- Clone this repository:

`$ git clone https://github.com/fexofenadine/docker-ubuntu-sshd.git`
`$ git clone https://github.com/art567/docker-ubuntu-sshd.git`


- Enter local directory:
Expand All @@ -27,12 +27,12 @@ Instructions

- Build the container:

`$ sudo docker build -t fexofenadine/ubuntu-sshd .`
`$ sudo docker build -t art567/ubuntu .`


- Run the container:

`$ sudo docker run -d=true --name=ubuntu --restart=always -p=2222:22 -v=/opt/data:/data fexofenadine/ubuntu-sshd /start`
`$ sudo docker run -d=true --name=ubuntu --restart=always -p=2222:22 -v=/opt/data:/data art567/ubuntu /start`


- Your container will start and bind ssh to 2222 port.
Expand Down Expand Up @@ -63,10 +63,10 @@ Versions
-----------
Some branches represents Ubuntu versions.

Branch `master` is always represented by latest Ubuntu Rolling
Branch `master` is always represented by latest Ubuntu LTS

For example:
- 12.04 - Ubuntu 12.04 Rolling
- 14.04 - Ubuntu 14.04 Rolling
- 16.04 - Ubuntu 16.04 Rolling
- 12.04 - Ubuntu 12.04 LTS
- 14.04 - Ubuntu 14.04 LTS
- 16.04 - Ubuntu 16.04 LTS

31 changes: 22 additions & 9 deletions scripts/start
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@
# Authors: Art567, fexofenadine
# Updated: 21st Feb 2021
# -----------------------------------------------------------------------------
USERNAME='%USERNAME%'
echo username set to $USERNAME at image buildtime
if [[ $USERNAME == "" ]]; then
USERNAME='master'
fi
echo username set to $USERNAME at runtime


# create/recreate home folder in case of external mount
mkdir /home/master
sudo chown master:users /home/master

if test ! -d /home/${USERNAME}; then
echo creating ${USERNAME} home folder
mkdir /home/${USERNAME}
fi
echo setting ownership of /home/${USERNAME} to ${USERNAME}
chown -R ${USERNAME}:users /home/${USERNAME}

# create new ssh server host keys on first boot
FILE=/data/.ssh/keys_recreated
if test -f "$FILE"; then
echo "ssh keys previously recreated"
FILE="/root/host_keys_recreated"
if test -f $FILE; then
echo ssh keys previously recreated
else
echo "ssh keys are defaults, recreating"
echo ssh keys are defaults, recreating
rm -v /etc/ssh/ssh_host_*
dpkg-reconfigure debconf --frontend=noninteractive
dpkg-reconfigure openssh-server
touch /data/.ssh/keys_recreated
touch $FILE
fi

# run plextraktsync in scrobble mode
# plextraktsync watch

# Run OpenSSH server in daemon mode
/usr/sbin/sshd -D
echo starting sshd daemon
/usr/sbin/sshd -D

0 comments on commit 3f2ab59

Please sign in to comment.