Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to write a little script which sets up a socks proxy via ssh and then starts a browser using that proxy.

#!/bin/bash
ssh -D 1234 user@host #&
chromium-browser --proxy-server="socks5://127.0.0.1:1234"

If I add the &-sign at the end of the first line the script just asks for my password and then opens an ssh terminal. The browser is started not before the ssh terminal is closed which is pretty useless. If I add the &-sign the script doesn't wait until I typed in the password and I don't know how I can cleanly end the ssh session.

I don't want to use automatic ssh login via rsa-keys.

Any suggestions how I could circumvent the problems described above?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You might be interested in the -f option to ssh which makes it go to the background once the password has been obtained.

share|improve this answer
    
Thanks, but this gives me a Cannot fork into background without a command to execute error. –  student Aug 27 '12 at 13:06
    
Using -f -N worked. –  student Aug 27 '12 at 13:08
    
What's the best way to end an ssh session started this way? –  student Aug 27 '12 at 13:11
    
@student kill it –  Ulrich Dangel Aug 27 '12 at 14:06
4  
Add ssh_pid=$! after ssh and add kill $ssh_pid after the browser. –  Thor Aug 27 '12 at 14:20

I would read the password from the terminal (with read -s) and

echo $password | ssh -f -N -D ....
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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