pozgo / docker-ssh-ubuntu22

Simple SSH Docker container.

Repository from Github https://github.compozgo/docker-ssh-ubuntu22Repository from Github https://github.compozgo/docker-ssh-ubuntu22

🐳 Ubuntu 22 SSH Docker Container

Docker Hub GitHub Stars License Ubuntu

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


πŸ“ Project Structure

πŸ“¦ 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

✨ Features

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

πŸš€ Quick Start

πŸ“₯ Pull from Docker Hub

# Pull the latest image
docker pull polinux/ssh-ubuntu22

πŸ”¨ Or Build Locally

# Clone and build
git clone https://github.com/pozgo/docker-ssh-ubuntu22.git
cd docker-ssh-ubuntu22
docker build -t polinux/ssh-ubuntu22 .

πŸ”‘ Run with Default Password

docker run -d -p 2222:22 --name ssh-container polinux/ssh-ubuntu22
# Default password: supersecurepass

🎯 Run with Custom Password

docker run -d -p 2222:22 --name ssh-container \
  -e ROOT_PASWD=mypassword \
  polinux/ssh-ubuntu22

🎲 Run with Auto-Generated Password

docker run -d -p 2222:22 --name ssh-container \
  -e ROOT_PASWD=password \
  polinux/ssh-ubuntu22

πŸ‘€ Run with User Creation

docker run -d -p 2222:22 --name ssh-container \
  -e USER=developer \
  polinux/ssh-ubuntu22

πŸ”‘ Run with User + Sudo Privileges

docker run -d -p 2222:22 --name ssh-container \
  -e USER=developer \
  -e USER_IN_SUDO=true \
  polinux/ssh-ubuntu22

πŸ” Run with User + Custom Password

docker run -d -p 2222:22 --name ssh-container \
  -e USER=developer \
  -e USER_PASWD=my-secure-password \
  polinux/ssh-ubuntu22

🎯 Run with User + Custom Password + Sudo

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

🎲 Run with User + Auto-Generated Password

docker run -d -p 2222:22 --name ssh-container \
  -e USER=developer \
  -e USER_PASWD=password \
  -e USER_IN_SUDO=true \
  polinux/ssh-ubuntu22

πŸ™ Using Docker Compose

# 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

πŸ”Œ Accessing the Container

πŸ” SSH Access

# 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>

πŸ“‹ Retrieve Passwords from Logs

# 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

βš™οΈ Configuration

Environment Variables

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

Ports

Port Description
22 SSH server port

Volumes

Path Description
/data/logs/ Log files including root and user password logs
/data/conf/ Configuration files
/data/run/ Runtime files (PIDs, sockets)

πŸ”‘ Password Management

The container supports multiple password and user configuration modes:

Root Password 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

User Creation Modes

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.log for root password
  • /data/logs/user-passwords.log for user passwords

πŸ’‘ Examples

πŸ› οΈ Development Setup

# 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

🏭 Production with Custom Password

# 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

πŸ‘¨β€πŸ’» Development with User Account

# 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

🎲 Development with Auto-Generated User Password

# 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

πŸ’Ύ With Persistent Data Volume

# 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

πŸ™ Docker Compose Example

# 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

πŸ”’ Security Notes

⚠️ 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

πŸ”§ Troubleshooting

🚫 SSH Connection Refused

# 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

πŸ” Cannot Find Password

# 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/

πŸ”Œ Port Already in Use

# 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

πŸ‘€ User Creation Issues

# 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"

🐳 Docker Hub

Docker Hub GitHub

Available Resources:

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository on GitHub
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. ✏️ Make your changes
  4. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  5. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  6. πŸ”ƒ Submit a pull request

πŸ—οΈ Built With

This container is built on the excellent polinux/ubuntu22-supervisor base image.


πŸ“„ License

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!

About

Simple SSH Docker container.

License:MIT License


Languages

Language:Shell 70.5%Language:Dockerfile 29.5%