Docker - Ubuntu SSH Setup
Host: Use the same port -> just change to the SSH port that does not conflict with NAS.
Environment Settings for Ubuntu Container
Dockerfile
dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:your_password' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
# Other installations
RUN apt-get upgrade -y
RUN apt-get install -y sudo nano vim curl git
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]Docker Build and Push to Docker Hub
shell
docker build -t ubuntu_ssh .
docker tag ubuntu_ssh wulukewu/ubuntu_ssh:latest
docker push wulukewu/ubuntu_ssh:latestInstall OpenSSH-Server
shell
apt-get update
apt-get install -y openssh-server
mkdir /var/run/sshd
echo 'root:your_password' | chpasswd
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
/usr/sbin/sshd -DPull and Run the ubuntu_ssh Image
Pull ubuntu_ssh from Docker Hub
shell
sudo docker pull wulukewu/ubuntu_ssh:latestRun ubuntu_ssh in Host
shell
sudo docker run -d --net=host --name ubuntu_ssh wulukewu/ubuntu_ssh:latestAccess the Ubuntu Container
shell
sudo docker exec -i -t ubuntu_ssh /bin/bashHostname Configuration
Change Hostname
shell
sudo nano /etc/hostname
sudo nano /etc/hosts
sudo rebootDisplay the Current Hostname
shell
hostnameSSH Configuration
Change SSH Port
shell
sudo nano /etc/ssh/sshd_config
service ssh restartUser Management
Add a New Sudo User
shell
adduser user_nameAdd the User to the Sudo Group
shell
usermod -aG sudo user_name
usermod -aG root user_nameChange User Password
shell
sudo passwd user_nameTest Sudo Access
shell
su - user_name