Skip to content

Simple SSH container. Great for secure connections into clusters.

License

Notifications You must be signed in to change notification settings

joaomarioss/docker-ssh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Docker Images Logo

Build Status License Support us Discourse users Discord

Hi! We're Dan and Jay. We're a two person team with a passion for open source products. We created Server Side Up to help share what we learn.

Find us at:

  • 📖 Blog - get the latest guides and free courses on all things web/mobile development.
  • 🙋 Community - get friendly help from our community members.
  • 🤵‍♂️ Get Professional Help - get guaranteed responses within next business day.
  • 💻 GitHub - check out our other open source projects
  • 📫 Newsletter - skip the algorithms and get quality content right to your inbox
  • 🐥 Twitter - you can also follow Dan and Jay
  • ❤️ Sponsor Us - please consider sponsoring us so we can create more helpful resources

Our Sponsors

All of our software is free an open to the world. None of this can be brought to you without the financial backing of our sponsors.

Sponsors

Individual Supporters

deligoez  alexjustesen  jeremykenedy  

About this project

This is a super simple SSHD container based on Ubuntu 20.04. It works great if you need to create a secure tunnel into your cluster.

Available Docker Images

This is a list of the docker images this repository creates:

🏷️ Tag ℹ️ Description
latest Use the latest version
release (example: v2.0.0) Lock into a specific release (tagged by the GitHub release)

What this image does

It does one thing very well:

  • It's a hardened SSH server (perfect for encrypted tunnels into your cluster)
  • Set authorized keys via the AUTHORIZED_KEYS environment variable or your own SSH_USER_HOME/.ssh/authorized_keys file
  • Set authorized IP addresses via the ALLOWED_IPS environment variable
  • It automatically generates the SSH host keys and will persist if you provide a volume
  • It's based off of S6 Overlay, giving you a ton of flexibility
  • It also includes the ping tool for troubleshooting connections
  • It's automatically updated via Github Actions

Usage instructions

All variables are documented here:

🔀 Variable Name 📚 Description #️⃣ Default Value
PUID User ID the SSH user should run as. 9999
PGID Group ID the SSH user should run as. 9999
DEBUG_MODE Display a bunch of helpful content for debugging. false
SSH_USER Username for the SSH user that other users will connect into as. tunnel
SSH_GROUP Group name used for our SSH user. tunnelgroup
SSH_USER_HOME Home location of the SSH user. /home/$SSH_USER
SSH_PORT Listening port for SSH server (on container only. You'll still need to publish this port). 2222
SSH_HOST_KEY_DIR Location of where the SSH host keys should be stored. /etc/ssh/ssh_host_keys/
AUTHORIZED_KEYS 🚨 Required to be set by you. Content of your authorized keys file (see below)
ALLOWED_IPS 🚨 Required to be set by you. Content of allowed IP addresses (see below)

1. Set your AUTHORIZED_KEYS environment variable or provide a /authorized_keys file

You can provide multiple keys by loading the contents of a file into an environment variable.

AUTHORIZED_KEYS="$(cat .ssh/my_many_ssh_public_keys_in_one_file.txt)"

Or you can provide the authorized_keys file via a volume. Ensure the volume references matches the path of /authorized_keys. The image will automatically take the file from /authorized_keys and configure it for use with your selected user.

ℹ️ NOTE: If both a file and variable are provided, the image will respect the value of the variable over the file.

2. Set your ALLOWED_IPS environment variable

Set this in the same context of AllowUsersThis example shows a few scenarios you can do:

ALLOWED_IPS="AllowUsers *@192.168.1.0/24 *@172.16.0.1 *@10.0.*.1"

3. Forward your external port to 2222 on the container

You can see I'm forwarding 12345 to 2222.

docker run --rm --name=ssh --network=web -p 12345:2222 localhost/ssh

This means I would connect with:

ssh -p 12345 [email protected]

Working example with MariaDB + SSH + Docker Swarm

Here's a perfect example how you can use it with MariaDB. This allows you to use Sequel Pro or TablePlus to connect securely into your database server 🥳

Example using ALLOWED_IPS variable:

version: '3.9'

services:
  mariadb:
    image: mariadb:10.6
    networks:
      - database
    environment:
        MYSQL_ROOT_PASSWORD: "myrootpassword"

  ssh:
    image: serversideup/docker-ssh
    #Publish the 12345 port to the 2222 port on the container
    ports:
      - target: 2222
        published: 12345
        mode: host
    # Set the Authorized Keys of who can connect
    environment:
      AUTHORIZED_KEYS: >
        "# Start Keys
         ssh-ed25519 1234567890abcdefghijklmnoqrstuvwxyz user-a
         ssh-ed25519 abcdefghijklmnoqrstuvwxyz1234567890 user-b
         # End Keys"
      # Lock down the access to certain IP addresses
      ALLOWED_IPS: "AllowUsers [email protected]"
    networks:
        - database

networks:
  database:

Example using $SSH_USER_HOME/.ssh/authorized_keys file:

version: '3.9'

services:
  mariadb:
    image: mariadb:10.6
    networks:
      - database
    environment:
        MYSQL_ROOT_PASSWORD: "myrootpassword"

  ssh:
    image: serversideup/docker-ssh
    #Publish the 12345 port to the 2222 port on the container
    ports:
      - target: 2222
        published: 12345
        mode: host
    # Set the Authorized Keys of who can connect
    environment:
      # Lock down the access to certain IP addresses
      ALLOWED_IPS: "AllowUsers [email protected]"
    configs:
      - source: ssh_authorized_keys
        # Mount the file to "/authorized_keys". The image will handle everything else
        target: /authorized_keys
        mode: 0600
    networks:
        - database

# Define the config to be used
configs:
  ssh_authorized_keys:
    file: ./authorized_keys

networks:
  database:

Submitting issues and pull requests

Since there are a lot of dependencies on these images, please understand that it can make it complicated on merging your pull request.

We'd love to have your help, but it might be best to explain your intentions first before contributing.

Like we said -- we're always learning

If you find a critical security flaw, please open an issue or learn more about our responsible disclosure policy.

About

Simple SSH container. Great for secure connections into clusters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dockerfile 100.0%