Giter Club home page Giter Club logo

dockssh's Introduction

Dockssh

Dockssh, ssh into any container from anywhere

Why

  • For learning and fun
  • Wasting some free time in my weekend :D
  • For testing/staging/development environments

How it works

  • Dockssh running on port 22022 on host example.com
  • A user connects to container1 using dockssh from remote computer i.e ssh -p 22022 [email protected]
  • Dockssh checks if the user provided password is the same as the one stored in redis key dockssh:container1:pass
  • On success, Dockssh will open a PTY (pseudotty) to docker exec -it container1 /bin/sh

Why redis for configurations

  • No configurations files
  • Simple & tiny
  • Makes Dockssh loads configurations in realtime, no need to restart

Requirements

  • Linux
  • Docker
  • Redis

Downloads

Download the binary from here

Building from source

You need to get the dependencies using the command: go get github.com/alash3al/dockssh

Usage

On the host machine:

  • Install Redis using the commands:
    Debian: sudo apt install redis
    RHEL: sudo yum install redis
  • Create a container for testing, I will name it TestCont:
    sudo docker create --name TestCont -it ubuntu:latest bash
  • Start the container:
    sudo docker start TestCont
  • Set a password for the container over SSH:
    redis-cli set dockssh:TestCont:pass "mypass"
  • Download the latest Dockssh binary from here.
  • Rename the file to dockssh.
  • Make it executable:
    chmod 775 dockssh
  • Make sure to open the port in the firewall:
    sudo ufw allow 22022
  • Run the server:
    ./dockssh
  • You should see a message:
    Now listening on port: 22022

On the remote machine:

  • Connect to your container:
    ssh TestCont@host_ip_address -p 22022
  • Enter yes.
  • Enter your password and press Enter.

Run Server in Background

You can make a service to run the dockssh in background

  • Firlstly go to /etc/systemd/system:
    cd /etc/systemd/system
  • Create a file named dockssh.service:
    sudo nano dockssh.service
  • Paste the following code:
    [Unit]
    Description=Dockssh Service to listen for connections
    After=network.target
    
    [Service]
    type=simple
    Restart=always
    RestartSec=1
    User=root
    ExecStart=/root/dockssh
    
    [Install]
    WantedBy=multi-user.target
    
  • Save the file with Ctrl+O then hit Enter
  • Enable the service file:
    sudo systemctl enable dockssh.service
  • Start the service:
    sudo systemctl start dockssh
  • Make sure the service has started successfully:
    sudo systemctl status dockssh
    You should see something like:
    dockssh.service - Dockssh Service to listen for connections
    Loaded: loaded (/etc/systemd/system/dockssh.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2020-01-08 04:40:36 UTC; 6h ago
    Main PID: 16132 (dockssh)
    Tasks: 17 (limit: 1109)
    CGroup: /system.slice/dockssh.service
           ├─16132 /root/dockssh
           └─16556 docker exec -it test2 bash
    
  • Enjoy ^^

dockssh's People

Contributors

alash3al avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dockssh's Issues

Documentation issue

in one part of your documentation, you mentioned that the redis key has to start with "dockerssh", but the correct form is "dockssh"

start at boot time

any suggestion for start dockssh at boot time over CentOS 7 ? it should be basic however I am missing something; dockssh is an excellent utility, thanks.

Unexpected behavior, Invalid param

I've tried to went further and containerize this client.
Almost works, but somehow gets https://github.com/alash3al/dockssh/blob/v1.0.0/main.go#L80 all the time.

My docker-compose.yml is

version: '2'
services:
  redis:
    container_name: dockssh_db
    image: redis
    volumes:
    - /var/dockssh/redis_data:/data
    ports:
    - "6379:6379"
    networks:
    - dockssh
  ssh:
    container_name: dockssh_client
    image: ubuntu:16.04
    entrypoint: /entrypoint.sh
    volumes:
    - /var/dockssh/entrypoint.sh:/entrypoint.sh
    - /var/dockssh/dockssh:/dockssh
    - /var/dockssh/.ssh:/root/.ssh
    ports:
    - "22022:22022"
    networks:
    - dockssh

networks:
  dockssh:

And entrypoint.sh

#!/bin/bash

/dockssh -redis-addr redis:6379

p.s.

  • without container wrapping it works fine
  • password auth works fine with container

Not a very needed one, since it's better not to do it in the container because of known_hosts rejection after each rebuild.

Security concern

Storing passwords in Redis is really risky, couldn't you come up with a better idea with solid security? It would be awesome to be able to connect with a SSH key.

Your SSH client didn't request a PTY

Hi I'm having an issue when trying to make SSH connection via Microsoft's "Remote - SSH" extension in Visual Studio Code.
It makes the connection, asks for the password and enters but soon after that it disconnects.
I can make the SSH connection through Putty and MobaXTerm only the Visual Studio Code that doesn't work, does anyone know what might be causing this error?

Capturar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.