gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
Create Dockerfile with sshd inside and blocking acces with ufw
- User
Create Dockerfile with sshd inside and blocking acces with ufw
- Assistant
Certainly! Below is an example of a Dockerfile that:
- Installs and runs
sshd(OpenSSH server). - Installs and configures
ufw(Uncomplicated Firewall) to block all incoming connections except SSH (port 22). - Starts both
sshdandufwwhen the container runs.
Dockerfile
# Use an official Ubuntu base image FROM ubuntu:22.04 # Prevent interactive prompts during package installation ENV DEBIAN_FRONTEND=noninteractive # Install openssh-server and ufw RUN apt-get update && \ apt-get install -y openssh-server ufw && \ mkdir /var/run/sshd # Set root password (change 'rootpassword' to a secure password) RUN echo 'root:rootpassword' | chpasswd # Allow SSH through UFW and enable UFW with default deny incoming RUN ufw default deny incoming && \ ufw allow 22/tcp && \ ufw --force enable # Expose SSH port EXPOSE 22 # Start sshd and keep container running CMD service ssh start && tail -f /dev/null
Explanation:
- Base image: Ubuntu 22.04.
- Packages:
openssh-serverfor SSH,ufwfor firewall. - Password: Sets root password (change it before use).
- UFW: Default deny incoming, allow SSH port 22, enable firewall.
- Expose: Port 22 for SSH.
- CMD: Starts sshd and keeps container alive.
Build and Run
docker build -t sshd-ufw . docker run -d -p 2222:22 sshd-ufwThen connect with:
ssh root@localhost -p 2222
Notes
- You might want to add SSH keys or improve security for production.
- UFW inside Docker is unusual because Docker manages iptables rules; this is mostly for demonstration.
- The container runs
tail -f /dev/nullto keep running after starting sshd and ufw.
If you want me to help with a more advanced setup or key-based auth, just ask!
- Installs and runs
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.