Using this plugin you can modify config on the fly so there is no need to rerun the ssh tunneling command every single time.
In this plugin there are two way of interacting with the SSH,
-
Run SSH like usual and forward the specified port. You still can interact with the remote machine like you usually do when SSH-ing.
-
Only run the tunneling process. SSH intances going to run in the background and you cannot interact with the remote machine.
To install this plugin, you first need to clone this repository by,
git clone https://github.com/afikrim/zsh-ssh-tunnel.git
After cloning the repository, you can just source the plugin script from your zsh shell
source path/to/zsh-ssh-tunnel/ssh-tunnel.plugin.zsh
To run the ssh-tunnel command you can just specify the user, host, and forwarding rules This command going to take you to the remote machine's shell.
ssh-tunnel -u user -h host 8080:localhost:8080 9090:localhost:9090
If you want to add more port or remove any existing port forwarding, you'll need to exit first from the remote machin shell
exit
After that you can type the forwarding rules to the terminal and hit Enter
# Use ! as prefix to the local port if you want to remove the forwarding rule, e.g.
!8080 8081:localhost:8081
In the input above we remove forwarding rule for port 8080 and add a new rule to forward remote 8081 to local 8081
Example video:
Screen.Recording.2023-12-17.at.21.03.01.mov
To run the ssh-tunnel command you can just specify the user, host, and forwarding rules This command going to take you to the remote machine's shell.
ssh-tunnel -N -u user -h host 8080:localhost:8080 9090:localhost:9090
If you want to add more port or remove any existing port forwarding, you can just type the forwarding rules to the terminal and hit Enter
# Use ! as prefix to the local port if you want to remove the forwarding rule, e.g.
!8080 8081:localhost:8081
In the input above we remove forwarding rule for port 8080 and add a new rule to forward remote 8081 to local 8081
Example video