Ubuntu 22 SSH Docker Container - OpenSSH server with configurable passwords, user creation, sudo pri
1.8K
A secure, feature-rich Docker container based on polinux/ubuntu22-supervisor that provides SSH access with configurable passwords, user creation, sudo privileges, and comprehensive logging.
๐ Quick Startโ โข ๐ Configurationโ โข ๐ค Contributingโ โข ๐ Issuesโ
๐ฆ docker-ssh-ubuntu22
โโโ ๐ณ Dockerfile # Main container definition
โโโ ๐ docker-compose.yml # Docker Compose configuration
โโโ ๐ README.md # This documentation
โโโ ๐ LICENSE # MIT License file
โโโ ๐ .github/ # GitHub configuration
โ โโโ ๐ workflows/
โ โโโ ๐ docker.yml # CI/CD pipeline for Docker Hub
โโโ ๐ container-files/ # Files copied to container
โโโ โ๏ธ config/
โ โโโ ๐ง init/
โ โโโ ๐ 10-init-set-root-pass.sh # Root password initialization script
โ โโโ ๐ค 20-init-create-user.sh # User creation and sudo setup script
โโโ ๐ etc/
โโโ ๐ฅ supervisor.d/
โโโ ๐ sshd.conf # SSH daemon supervisor config
| Feature | Description |
|---|---|
| ๐ SSH Server | OpenSSH server pre-configured for secure root access |
| ๐ค User Creation | Automatically create users with custom passwords via environment variables |
| ๐ Sudo Support | Grant sudo privileges to created users with passwordless access |
| ๐ฅ Supervisor Management | Robust process management using supervisor |
| ๐ Password Logging | All passwords logged to both stdout and persistent files |
| โ๏ธ Configurable Passwords | Set custom passwords or auto-generate secure ones |
| ๐พ Persistent Logs | All logs stored in /data/logs/ for easy access |
| ๐ Auto-restart | Services automatically restart on failure |
| ๐ณ Docker Hub Ready | Available as pre-built image on Docker Hub |
# Pull the latest image
docker pull polinux/ssh-ubuntu22
# Clone and build
git clone https://github.com/pozgo/docker-ssh-ubuntu22.git
cd docker-ssh-ubuntu22
docker build -t polinux/ssh-ubuntu22 .
docker run -d -p 2222:22 --name ssh-container polinux/ssh-ubuntu22
# Default password: supersecurepass
docker run -d -p 2222:22 --name ssh-container \
-e ROOT_PASWD=mypassword \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e ROOT_PASWD=password \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e USER=developer \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e USER=developer \
-e USER_IN_SUDO=true \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e USER=developer \
-e USER_PASWD=my-secure-password \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e USER=developer \
-e USER_PASWD=my-secure-password \
-e USER_IN_SUDO=true \
polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name ssh-container \
-e USER=developer \
-e USER_PASWD=password \
-e USER_IN_SUDO=true \
polinux/ssh-ubuntu22
# Run the default service
docker compose up -d
# Run with custom password profile
docker compose --profile custom up -d ssh-custom
# Run with auto-generated password profile
docker compose --profile auto up -d ssh-auto
# Run with user creation profile
docker compose --profile user up -d ssh-user
# Run with user + sudo privileges profile
docker compose --profile sudo up -d ssh-sudo
# Run with user creation and custom password
docker compose --profile user-custom up -d ssh-user-custom
# Run with user + custom password + sudo privileges
docker compose --profile user-sudo-custom up -d ssh-user-sudo-custom
# Run with user + auto-generated password
docker compose --profile user-auto up -d ssh-user-auto
# Run development environment (user with sudo + auto password)
docker compose --profile dev up -d ssh-dev
# Connect via SSH as root (default password: supersecurepass)
ssh root@localhost -p 2222
# Connect via SSH as created user (password from logs)
ssh developer@localhost -p 2222
# Or with custom port mapping
ssh root@localhost -p <your-port>
ssh developer@localhost -p <your-port>
# View container logs to see all passwords
docker logs ssh-container | grep "password"
# Access the root password log file directly
docker exec ssh-container cat /data/logs/root-password.log
# Access the user passwords log file directly
docker exec ssh-container cat /data/logs/user-passwords.log
| Variable | Default | Description |
|---|---|---|
ROOT_PASWD | supersecurepass | Root user password. Set to password to auto-generate |
USER | "" | Username to create. If empty, no user is created |
USER_PASWD | "" | User password. Set to password to auto-generate, or specify custom password |
USER_IN_SUDO | "" | Set to true to grant sudo privileges to created user |
| Port | Description |
|---|---|
| 22 | SSH server port |
| Path | Description |
|---|---|
/data/logs/ | Log files including root and user password logs |
/data/conf/ | Configuration files |
/data/run/ | Runtime files (PIDs, sockets) |
The container supports multiple password and user configuration modes:
| Mode | Configuration | Description |
|---|---|---|
| ๐ Default | No env variable | Uses supersecurepass |
| ๐ฏ Custom | ROOT_PASWD=mypassword | Set your own password |
| ๐ฒ Auto-Generated | ROOT_PASWD=password | Random 16-character password |
| Mode | Configuration | Description |
|---|---|---|
| ๐ซ No User | No USER variable | Only root user available |
| ๐ค Standard User | USER=username | Create user with auto-generated password |
| ๐ Custom Password User | USER=username USER_PASWD=mypassword | Create user with custom password |
| ๐ฒ Auto-Generated User | USER=username USER_PASWD=password | Create user with auto-generated password |
| ๐ Sudo User | USER=username USER_IN_SUDO=true | Create user with sudo privileges |
| ๐ง Sudo + Custom Password | USER=username USER_PASWD=mypassword USER_IN_SUDO=true | Create user with custom password and sudo privileges |
๐ Password Logging: All passwords are logged to:
- Container stdout (visible in
docker logs)/data/logs/root-password.logfor root password/data/logs/user-passwords.logfor user passwords
# Pull and run for development
docker pull polinux/ssh-ubuntu22
docker run -d -p 2222:22 --name dev-ssh polinux/ssh-ubuntu22
# Get the password
docker logs dev-ssh | grep "Root password"
# Connect via SSH
ssh root@localhost -p 2222
# Run with secure custom password
docker run -d -p 2222:22 --name prod-ssh \
-e ROOT_PASWD=my-secure-password-123 \
--restart unless-stopped \
polinux/ssh-ubuntu22
# Run with dedicated developer user having sudo privileges and custom password
docker run -d -p 2222:22 --name dev-ssh \
-e USER=developer \
-e USER_PASWD=my-dev-password \
-e USER_IN_SUDO=true \
--restart unless-stopped \
polinux/ssh-ubuntu22
# Connect as developer user with known password
ssh developer@localhost -p 2222
# Run with developer user having auto-generated password
docker run -d -p 2222:22 --name dev-auto-ssh \
-e USER=developer \
-e USER_PASWD=password \
-e USER_IN_SUDO=true \
--restart unless-stopped \
polinux/ssh-ubuntu22
# Get user password from logs
docker logs dev-auto-ssh | grep "User.*password set to"
# Or get from password file
docker exec dev-auto-ssh cat /data/logs/user-passwords.log
# Connect as developer user
ssh developer@localhost -p 2222
# Run with persistent data volume
docker run -d -p 2222:22 --name ssh-persistent \
-v ssh-data:/data \
--restart unless-stopped \
polinux/ssh-ubuntu22
# Access logs from volume
docker run --rm -v ssh-data:/data alpine \
cat /data/logs/root-password.log
# Clone repository and use docker-compose
git clone https://github.com/pozgo/docker-ssh-ubuntu22.git
cd docker-ssh-ubuntu22
# Run default container
docker-compose up -d
# View logs to get password
docker-compose logs ssh-ubuntu22 | grep "Root password"
# Connect via SSH
ssh root@localhost -p 2222
โ ๏ธ Important Security Information
| โ ๏ธ Warning | Description |
|---|---|
| ๐งช Development Use | Container configured for development/testing purposes |
| ๐ค Root Login | SSH permits root login for convenience |
| ๐ Production Keys | Consider using SSH keys instead of passwords for production |
| ๐ Password Logging | All passwords are logged in plain text for convenience |
| ๐ง Passwordless Sudo | Created users with sudo privileges have passwordless access |
| ๐ Fresh Keys | SSH host keys are regenerated on each build |
# Check if SSH service is running
docker exec ssh-container supervisorctl status sshd
# View SSH logs for errors
docker exec ssh-container cat /data/logs/sshd.log
# Restart SSH service if needed
docker exec ssh-container supervisorctl restart sshd
# Check initialization logs for root password
docker logs ssh-container | grep SSH-INIT
# Check initialization logs for user creation
docker logs ssh-container | grep USER-INIT
# Check password log files directly
docker exec ssh-container cat /data/logs/root-password.log
docker exec ssh-container cat /data/logs/user-passwords.log
# List all log files
docker exec ssh-container ls -la /data/logs/
# Use different port mapping
docker run -d -p 2223:22 --name ssh-container polinux/ssh-ubuntu22
ssh root@localhost -p 2223
# Or find what's using the port
sudo lsof -i :2222
# Check if user was created successfully
docker exec ssh-container id testuser
# Check sudo configuration for user
docker exec ssh-container cat /etc/sudoers.d/testuser
# Check user groups
docker exec ssh-container groups testuser
# Test sudo access
docker exec ssh-container su - testuser -c "sudo whoami"
Available Resources:
We welcome contributions! Here's how you can help:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This container is built on the excellent polinux/ubuntu22-supervisorโ base image.
This project is licensed under the MIT License - see the LICENSEโ file for details.
Copyright (c) 2025 Przemyslaw (Ozzy) Ozgo
This project follows the same license as the base image polinux/ubuntu22-supervisorโ .
Made with โค๏ธ by the Polinux Team
โญ Star us on GitHub if this project helped you!
Content type
Image
Digest
sha256:1248ff85dโฆ
Size
194 MB
Last updated
about 1 year ago
docker pull polinux/ssh-ubuntu22