I'm trying to set up a script that I can call up easily in a WM. The idea is to establish a socks tunnel via ssh to a known-good server and then start chromium with the appropriate environment variables...Then, wait until that instance of chromium exits and then unbind the port. The last part is important, because if left open, the script will fail to run again because the tunnel is still up.

However, when I run it, it just establishes the connection, starts chromium and then closes the connection...It doesn't wait for Chromium to close before continuing.

I've tried adding &, && and the wait function, but I think Chromium returns something after successful execution, which is triggering my script to continue.

ssh -f -N -M -S ~/socket -L 4771:localhost:4771 -p 1234 foo.bar.com
chromium --proxy-server="socks://localhost:4771" &&
ssh -S socket -O exit foo.bar.com 

I'm using Arch and ZSH as my shell.

  • By default, chromium doesn't put itself in the background so you shouldn't need to worry about backgrounding and wait. Just do the simple ssh -f -N -M -S ~/socket -L 4771:localhost:4771 -p 1234 foo.bar.com ; /usr/bin/chromium --proxy-server="socks://localhost:4771" ; ssh -S socket -O exit foo.bar.com Aug 13, 2016 at 21:17
  • this results in: Created new window in existing browser session. Control socket connect(socket): No such file or directory Aug 14, 2016 at 1:23
  • Ah... you already have a copy of chromium running. There isn't a new instance of chromium in this case, and the command just instructs the existing process. If you don't need to keep the profile settings (bookmarks, etc) then the --temp-profile option will allow you to create a second chromium instance. Otherwise I'm not sure it is possible to have two instances of chromium sharing the same profile. Aug 14, 2016 at 1:38

1 Answer 1


The best I can think of is running pgrep in a loop. If you have more than one chromium running, you can isolate your script in a separate PID namespace with unshare or firejail, for instance.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .