This project provides a Docker-based solution to manage SSH tunnels using autossh
and a YAML configuration file. The setup allows you to easily map remote ports to local ports, making it convenient to access services on remote machines behind firewalls.
- Dockerized: Uses Docker to encapsulate the environment, making it easy to deploy and manage.
- Non-Root User: Runs the container as a non-root user for enhanced security.
- YAML Configuration: Uses a
config.yaml
file to define multiple SSH tunnel mappings. - Autossh: Automatically maintains SSH connections, ensuring tunnels stay active.
- Docker and Docker Compose installed on your local machine.
- SSH keys set up for accessing remote hosts.
I have released the first version to Docker Hub. You can access the version via the following link:
Feel free to use it and provide feedback!
Clone this repository to your local machine:
git clone https://github.com/yourusername/ssh-tunnel-manager.git
cd ssh-tunnel-manager
Ensure your SSH keys are located in the ~/.ssh
directory. The directory should contain your private key files (e.g., id_ed25519
) and any necessary SSH configuration files.
Edit the config.yaml
file to define your SSH tunnel mappings. Each entry should specify the remote host, remote port, and local port.
Example config.yaml.sample
(copy it to config.yaml
and make necessary changes) :
tunnels:
- remote_host: "user@remote-host1"
remote_port: 8000
local_port: 8001
- remote_host: "user@remote-host2"
remote_port: 9000
local_port: 9001
# Add more tunnels as needed
docker-compose up -d
# build
docker compose build -f compose.dev.yaml
# run
docker compose up -f compose.dev.yaml -d
Once the container is running, you can access the services on your local machine using the specified local ports. For example, if you mapped remote-host1:8000
to localhost:8001
, you can access the service at http://localhost:8001
.
To add more SSH tunnels, simply update the config.yaml
file with additional entries. Each entry should follow the format:
- remote_host: "user@remote-host"
remote_port: <remote_port>
local_port: <local_port>
If you need to customize the Docker environment, you can modify the Dockerfile
. For example, you can install additional packages or change the base image.
The entrypoint.sh
script is responsible for reading the config.yaml
file and starting the SSH tunnels. You can modify this script if you need to add additional functionality or change how the tunnels are managed.
Ensure that the .ssh
directory and its contents have the appropriate permissions:
chmod 700 .ssh
chmod 600 .ssh/*
If you encounter permission issues when running Docker commands, ensure your user is in the docker
group:
sudo usermod -aG docker $USER
Check the Docker container logs for any errors:
docker-compose logs -f
This project is licensed under the MIT License. See the LICENSE file for details.
- autossh for maintaining SSH connections.
- yq for parsing YAML configuration files.
- Docker for containerization.
Feel free to contribute to this project by submitting issues or pull requests. Happy tunneling!