2

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.

Vivek Pradhan
  • 861
  • 5
  • 13
  • 25

1 Answers1

1

Try like this instead:

port=1234
remote=username@host
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.

janos
  • 4,888