Created
May 10, 2023 08:07
-
-
Save jin-zhe/ab5e8724b9b65abe153ff62c0edd53c3 to your computer and use it in GitHub Desktop.
Custom ssh command with port range forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# STEP 1: `$ mkdir ~/bin` | |
# STEP 2: `$ touch ~/bin/sshfr` | |
# STEP 3: `$ chmod +x ~/bin/sshfr` | |
# STEP 4: Copy the following contents into `~/bin/sshfr` | |
# STEP 5: Update .profile or .bash_profle: `$ export PATH=$PATH":$HOME/bin"` | |
# STEP 6: Reload .profile or .bash_profle E.g. `$ . ~/.bash_profile` | |
# The contents of sshfr is as follows | |
ADDRESS=$1 | |
PORT_START=${2-49151} | |
RANGE_LEN=${3-10} | |
PORT_END=$((PORT_START + RANGE_LEN)) | |
ssh $ADDRESS $(for i in `seq $PORT_START $PORT_END` ;do echo -L $i:localhost:$i ;done) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment