i have 10+ ssh server needs to do port forwarding when i start to work, but i'm tired to start those ssh connections one by one. i know in linux the powerful bash script can handle this problem. here is my bash script example
#!/bin/bash
ssh -L 10001:somehost:3306 user@host1 -N
ssh -L 10002:somehost:3306 user@host2 -N
ssh -L 10003:somehost:3306 user@host3 -N
....
i found out that if the first ssh connection started, it just stopped at that line and wait it to close.
could any one tell me how to fix it?
Use the -f
option:
ssh -f -N -L 10001:somehost:3306 user@host1
From man ssh
:
-f Requests ssh to go to background just before command execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With