I have a simple bash script for SSH tunneling

createTunnel() {
  /usr/bin/ssh -i /home/miner/EC2.pem -f -N -R 10022:localhost:22 -L 19922:ubuntu@server.com:22 ubuntu@server.com
  if [[ $? -eq 0 ]]; then
    echo Tunnel created successfully
    echo An error occurred
/usr/bin/ssh -p 19922 localhost ls > /dev/null
if [[ $? -ne 0 ]]; then
  echo Creating new tunnel

When I run it, I get the following errors, what are the possible causes?

channel_setup_fwd_listener: cannot listen to port: 10022
channel_setup_fwd_listener_tcpip: cannot listen to port: 19922
channel 2: open failed: administratively prohibited: open failed
channel 3: open failed: administratively prohibited: open failed
  • 1
    many... try running ssh in verbose mode. – Jasen Sep 23 '16 at 5:31
  • I guess you've run your script twice but only one process can listen to a specific port. netstat -ntpl | grep "19922\|10022" – rudimeier Sep 23 '16 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.