I have a bash script where I configure my proxy settings automatically. I have created some aliases in the .bash_aliases file. Now there is one command where I ssh into my remote server and do some dynamic port forwarding and essentially create a socks proxy. So I need to configure my proxy settings accordingly.

The command looks like:

proxy off && ssh -D <port> <username>@<hostaddress>

I have aliased the above command and when I type the alias in the terminal, I am connected to my remote server successfully. However after this is done, I need to run another command in a new terminal window to configure my newly created socks proxy. Basically I just need to run:

proxy socks #It configures my laptop to use the socks proxy

I can't do it in the same terminal window and just && it after the ssh command because that would mean I am trying to execute the command on the remote server. I want to run this command on my laptop.

Is there any way I can run the second command in a new terminal window in a single line like we pipe or and different commands? It's really inefficient to open a new tab in the terminal every time I ssh into my remote server, just so that I can type a single command to configure my proxy and then close that tab because I don't need it anymore.

  • Why not exit after the first command? – jobin Feb 15 '14 at 8:26
  • If i exit after the first command, would it not terminate the ssh session? – Vivek Pradhan Feb 15 '14 at 9:11
  • My bad, I misunderstood the question; ignore the comment, please. – jobin Feb 15 '14 at 9:14

Try like this instead:

proxy off && ssh -fND $port $remote && proxy socks

The -f flag tells ssh to go into the background and the -N tells to not execute commands, just forward ports. This way you can continue working in your current terminal.

| 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.