Sign inSign up

polinux/ssh-ubuntu22

By polinux

โ€ขUpdated about 1 year ago

Ubuntu 22 SSH Docker Container - OpenSSH server with configurable passwords, user creation, sudo pri

Image
0

1.8K

polinux/ssh-ubuntu22 repository overview

โ ๐Ÿณ 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

FeatureDescription
๐Ÿ” SSH ServerOpenSSH server pre-configured for secure root access
๐Ÿ‘ค User CreationAutomatically create users with custom passwords via environment variables
๐Ÿ”‘ Sudo SupportGrant sudo privileges to created users with passwordless access
๐Ÿ‘ฅ Supervisor ManagementRobust process management using supervisor
๐Ÿ“ Password LoggingAll passwords logged to both stdout and persistent files
โš™๏ธ Configurable PasswordsSet custom passwords or auto-generate secure ones
๐Ÿ’พ Persistent LogsAll logs stored in /data/logs/ for easy access
๐Ÿ”„ Auto-restartServices automatically restart on failure
๐Ÿณ Docker Hub ReadyAvailable 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
VariableDefaultDescription
ROOT_PASWDsupersecurepassRoot 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
PortDescription
22SSH server port
โ Volumes
PathDescription
/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
ModeConfigurationDescription
๐Ÿ”’ DefaultNo env variableUses supersecurepass
๐ŸŽฏ CustomROOT_PASWD=mypasswordSet your own password
๐ŸŽฒ Auto-GeneratedROOT_PASWD=passwordRandom 16-character password
โ User Creation Modes
ModeConfigurationDescription
๐Ÿšซ No UserNo USER variableOnly root user available
๐Ÿ‘ค Standard UserUSER=usernameCreate user with auto-generated password
๐Ÿ” Custom Password UserUSER=username USER_PASWD=mypasswordCreate user with custom password
๐ŸŽฒ Auto-Generated UserUSER=username USER_PASWD=passwordCreate user with auto-generated password
๐Ÿ”‘ Sudo UserUSER=username USER_IN_SUDO=trueCreate user with sudo privileges
๐Ÿ”ง Sudo + Custom PasswordUSER=username USER_PASWD=mypassword USER_IN_SUDO=trueCreate 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

โš ๏ธ WarningDescription
๐Ÿงช Development UseContainer configured for development/testing purposes
๐Ÿ‘ค Root LoginSSH permits root login for convenience
๐Ÿ”‘ Production KeysConsider using SSH keys instead of passwords for production
๐Ÿ“ Password LoggingAll passwords are logged in plain text for convenience
๐Ÿ”ง Passwordless SudoCreated users with sudo privileges have passwordless access
๐Ÿ”„ Fresh KeysSSH 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!

Tag summary

Content type

Image

Digest

sha256:1248ff85dโ€ฆ

Size

194 MB

Last updated

about 1 year ago

docker pull polinux/ssh-ubuntu22