You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SSH Tunnel Swarm is a powerful shell script tool for managing multiple SSH tunnels concurrently. It simplifies the process of creating and managing both forward and reverse SSH tunnels by applying a predefined set of rules for each tunnel.
5
+
ssh-tunnel-swarm is a powerful shell script tool for managing multiple SSH tunnels concurrently. It simplifies the process of creating and managing both forward and reverse SSH tunnels by applying a predefined set of rules for each tunnel.
6
6
7
7
The script supports the configuration of multiple SSH connections and can establish tunnels based on defined rules.
8
8
9
9
## Table of Contents
10
10
11
-
-[SSH Tunnel Swarm](#ssh-tunnel-swarm)
12
-
-[Features](#features)
13
-
-[Prerequisites](#prerequisites)
14
-
-[Installation](#installation)
15
-
-[Installing for the current user](#installing-for-the-current-user)
16
-
-[Installing for all users](#installing-for-all-users)
17
-
-[Configuration](#configuration)
18
-
-[Environment Variables](#environment-variables)
19
-
-[Tunnel Rules](#tunnel-rules)
20
-
-[Usage](#usage)
21
-
-[Logging](#logging)
11
+
-[Features](#features)
12
+
-[Prerequisites](#prerequisites)
13
+
-[Installation](#installation)
14
+
-[Installing for all users](#installing-for-all-users)
15
+
-[Installing for the current user](#installing-for-the-current-user)
16
+
-[Configuration](#configuration)
17
+
-[Environment Variables](#environment-variables)
22
18
-[Supported Log Levels](#supported-log-levels)
23
-
-[Important Notes](#important-notes)
24
-
-[Contributing](#contributing)
25
-
-[License](#license)
26
-
-[TODO](#todo)
27
-
-[Glossary](#glossary)
19
+
-[Tunnel Rules](#tunnel-rules)
20
+
-[Example](#example)
21
+
-[Usage](#usage)
22
+
-[Important Notes](#important-notes)
23
+
-[License](#license)
24
+
-[TODO](#todo)
28
25
29
26
## Features
30
27
@@ -45,76 +42,24 @@ This script is designed to be run in a Unix-like environment.
45
42
46
43
## Installation
47
44
48
-
To install `ssh-tunnel-swarm`, the first step is to check if `wget` is installed on your system by running `wget --version`.
45
+
Execute the following command to download `ssh-tunnel-swarm`:
49
46
50
-
If it is installed, the output should be similar to this:
If `wget` is not installed, you can easily install it using the package manager for your operating system. Here are the installation commands for some known operating systems:
- macOS with Homebrew installed: `brew install wget`
102
-
- Tiny Core Linux: `tce-load -wi wget`
103
-
104
-
If your operating system is not listed above, you can visit the `wget` website at https://www.gnu.org/software/wget/ and download it from there.
51
+
After the download is complete, you can use `ssh-tunnel-swarm` from the current location by executing `./ssh-tunnel-swarm` but a true installation allows you to use it from any directory.
105
52
106
-
Once `wget` is installed, execute the following command to download `ssh-tunnel-swarm`:
After the download is complete, you can use `ssh-tunnel-swarm` from the current location by executing `./ssh-tunnel-swarm` but a true installation allows you to use it from any directory.
113
-
114
59
### Installing for the current user
115
60
116
61
```shell
117
-
mkdir ~/bin
62
+
mkdir -p ~/bin
118
63
mv ssh-tunnel-swarm ~/bin/
119
64
```
120
65
@@ -128,7 +73,7 @@ echo $PATH | grep -q "$HOME/bin" && echo "The $HOME/bin directory is already in
128
73
129
74
This command will output a message indicating whether `$HOME/bin` is already in your path.
130
75
131
-
If it is not, execute the following command for either `bash` or `zsh`:
-**LOG_FILE**: This determines the output destination of the log messages. If set, log messages will be written to the specified file. If not set, logs will be printed to stdout.
162
101
163
-
-**LOG_LEVEL**: This determines the severity level of the messages to be logged. Messages with a severity level less than this will not be logged. For example, if `LOG_LEVEL` is set to `INFO`, then `DEBUG` messages won't be logged. Default value if not set is `DEBUG`. You can find all of the [supported log levels here](#supported-log-levels).
102
+
-**LOG_LEVEL**: This determines the severity level of the messages to be logged. Messages with a severity level less than this will not be logged. For example, if `LOG_LEVEL` is set to `INFO`, then `DEBUG` messages won't be logged. Default value if not set is `INFO`.
103
+
104
+
#### Supported Log Levels
105
+
106
+
The logger recognizes four levels of logging:
107
+
108
+
-**DEBUG**: These are verbose-level messages and are usually useful during development or debugging sessions. They provide deep insights about what's going on.
109
+
110
+
-**INFO**: These messages provide general feedback about the application processes and state. They are used to confirm that things are working as expected.
111
+
112
+
-**ERROR**: These are messages that indicate a problem that prevented a function or process from completing successfully.
113
+
114
+
-**FATAL**: These messages indicate a severe problem that has caused the application to stop. They require immediate attention.
164
115
165
116
### Tunnel Rules
166
117
167
-
SSH Tunnel Swarm reads the tunnel rules for each host from a file specified by the `RULES_FILE` environment variable. Each entry within the file should include the username, hostname, port, and the tunnels to establish. For instance:
118
+
ssh-tunnel-swarm reads the tunnel rules for each host from a file specified by the `RULES_FILE` environment variable. Each entry within the file should include the username, hostname, port, SSH private key and the tunnels to establish. For instance:
@@ -188,7 +141,7 @@ Each block represents an SSH connection where:
188
141
**Set up a reverse tunnel from your local machine to a VPS having SSH listening on port 22**
189
142
190
143
```
191
-
user@myvps.com:22
144
+
user@myvps.com:22=/path/to/ssh/private/key
192
145
reverse localhost:8080:0.0.0.0:80
193
146
```
194
147
@@ -197,10 +150,10 @@ Now when you access http://myvps.com/ you'll access your local service.
197
150
**Set up a reverse tunnel from your local machine to 2 VPSs having SSH listening on port 22**
198
151
199
152
```
200
-
user@myvps.com:22
153
+
user@myvps.com:22=/path/to/ssh/private/key
201
154
reverse localhost:8080:0.0.0.0:80
202
155
203
-
user@myothervps.com:22
156
+
user@myothervps.com:22=/path/to/ssh/private/key
204
157
reverse localhost:8080:0.0.0.0:80
205
158
```
206
159
@@ -209,7 +162,7 @@ Now when you access both http://myvps.com/ and http://myothervps.com/ you'll acc
209
162
**Set up a forward tunnel from a remote machine to your computer**
210
163
211
164
```
212
-
user@enterprise.com:22
165
+
user@enterprise.com:22=/path/to/ssh/private/key
213
166
forward localhost:6366:10.137.82.201:636
214
167
```
215
168
@@ -225,49 +178,19 @@ LOG_LEVEL=DEBUG \
225
178
ssh-tunnel-swarm
226
179
```
227
180
228
-
## Logging
229
-
230
-
SSH Tunnel Swarm includes a logging functionality that provides visibility into the operations and state of your SSH connections.
231
-
232
-
It is designed to enable configurable log levels and output destinations and provides different levels of logging based on the severity of the log message. This is particularly useful in complex scripts or systems where detailed logging is beneficial for development, debugging, or ongoing system maintenance.
233
-
234
-
### Supported Log Levels
235
-
236
-
The logger recognizes four levels of logging:
237
-
238
-
-**DEBUG**: These are verbose-level messages and are usually useful during development or debugging sessions. They provide deep insights about what's going on.
239
-
240
-
-**INFO**: These messages provide general feedback about the application processes and state. They are used to confirm that things are working as expected.
241
-
242
-
-**ERROR**: These are messages that indicate a problem that prevented a function or process from completing successfully.
243
-
244
-
-**FATAL**: These messages indicate a severe problem that has caused the application to stop. They require immediate attention.
245
-
246
181
## Important Notes
247
182
248
-
-SSH Tunnel Swarm does not handle SSH authentication(yet). Please ensure that the necessary SSH key is available(currently only the default one is used).
183
+
-ssh-tunnel-swarm does not handle SSH password authentication.
249
184
250
-
-Make sure you have the required permissions on your local and remote systems to establish SSH connections and tunnels.
185
+
-Always use this script responsibly make sure you have the required permissions on your local and remote systems to establish SSH connections and tunnels.
251
186
252
-
- All SSH connections are established with -o StrictHostKeyChecking=no for convenience. However, this option may expose you to potential security risks.
187
+
- All SSH connections are established with `-o StrictHostKeyChecking=yes`.
253
188
254
-
- Always use this script responsibly and ensure you have the permissions to establish tunnels with your target hosts.
255
-
256
-
## Contributing
257
-
258
-
I welcome your contributions. Please submit a pull request with your improvements. Make sure to adhere to the existing coding style and ensure all tests pass before submitting your PR.
- With `StrictHostKeyChecking=yes`, the client will refuse to connect to servers whose host key is not known or has changed since it was last recorded. This may lead to initial connection failure if the host key is not already in the known_hosts file.
267
190
268
-
If all tests run you're ready do go
191
+
It is your responsibility to ensure that the `known_hosts` file is up to date with the public keys of the remote hosts you wish to connect to. You can manually add a host's public key to your `known_hosts` file, or you can retrieve it using SSH on a trusted network before running ssh-tunnel-swarm.
269
192
270
-
To execute the script in development you can either just run `bash main.sh` or execute `make build` and run the compiled script `./build/ssh-tunnel-swarm`
193
+
Note that in some cases, you might have to manually remove outdated or changed host keys from your `known_hosts` file. This situation can arise if you're connecting to a server that has had its SSH keys regenerated.
271
194
272
195
## License
273
196
@@ -277,20 +200,6 @@ By using this software, you agree to abide by the terms of the **WTFPL**. If you
277
200
278
201
## TODO
279
202
280
-
- add support for specifying keys for each host
281
-
- add more tests
282
-
283
-
## Glossary
284
-
285
-
-**SSH**: Secure Shell is a protocol used to securely connect to a remote server/system.
286
-
-**Tunnel**: In the context of SSH, a tunnel is a route through which the entirety of your data is going to pass.
287
-
-**Forward Tunnel (Local Port Forwarding)**: Forwarding calls for a specific IP and port from the client system to an IP and port on the server system.
288
-
-**Reverse Tunnel (Remote Port Forwarding)**: Allows the server to receive a connection as a client from the client system.
289
-
-**SSH Key**: A way of logging into an SSH/SFTP account using a cryptographic pair of keys, hence providing an alternative way to password-based logins.
290
-
-**Bash**: A shell, or command language interpreter, for the GNU operating system.
291
-
-**Shell Script**: A computer program designed to be run by the Unix shell, a command-line interpreter.
292
-
-**wget**: A free utility for non-interactive download of files from the web. It supports HTTP, HTTPS, and FTP protocols and can retrieve files through HTTP proxies.
293
-
-**PATH**: An environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located.
294
-
-**$HOME**: An environment variable that displays the path of the home directory of the current user.
295
-
-**WTFPL**: Do What The Fuck You Want To Public License, a very permissive license for software and other scientific or artistic works that offers a huge degree of freedom.
296
-
-**GNU**: Stands for GNU's Not Unix, an extensive collection of free software, which includes the GNU Project, the GNU Operating System, and the GNU General Public License.
0 commit comments