0

I am using tcprelay.py from usbmuxd to forward local port 2222 to remote port 22 so that I can SSH into my iPhone over USB. If I run

python ~/Downloads/usbmuxd-1.0.8/python-client/tcprelay.py -t 22:2222

It successfully forwards the port, and in another terminal window, I can run

ssh -l root -p 2222 127.0.0.1

and successfully use SSH over USB. However, I am trying to combine this into one command, and

python ~/Downloads/usbmuxd-1.0.8/python-client/tcprelay.py -t 22:2222
ssh -l root -p 2222 127.0.0.1

does not work. After running the python command, I cannot run any other commands in that window. How would I go about putting these two commands together?

Thank you

2

An adaptation of MadMike's answer, you can use the following commands:

python ~/Downloads/usbmuxd-1.0.8/python-client/tcprelay.py -t 22:2222 &

while ! (: < /dev/tcp/127.0.0.1/2222) 2>/dev/null; do
    sleep 1
done

ssh -l root -p 2222 127.0.0.1

This will execute the python program in the background, then wait (checking once a second) until internal port 2222 is open. It will then run the ssh program.

Source for checking if a port is open

| improve this answer | |
2

You need to let the first command run in the background and start the second one after the first has been initiated. I'm sure there is a more elegant way (of sorts) but this should do the trick.

python ~/Downloads/usbmuxd-1.0.8/python-client/tcprelay.py -t 22:2222 &
ssh -l root -p 2222 127.0.0.1

The ampersand at the end tells bash to run the python command in the background.

In the event you need to run the script a second time you might need to find the running python command and kill it, before you can run it a second time. Else it will complain that the port is already blocked.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.