Have bash script wait for password

5,165

Solution 1

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

Solution 2

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

echo $password | ssh -f -N -D ....
Share:
5,165

Related videos on Youtube

student
Author by

student

Updated on September 18, 2022

Comments

  • student
    student almost 2 years

    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?

  • student
    student almost 12 years
    What's the best way to end an ssh session started this way?
  • sunnysideup
    sunnysideup almost 12 years
    @student kill it
  • student
    student almost 12 years
    Is it possible to kill it automatically when the browser window is closed?
  • Thor
    Thor almost 12 years
    Add ssh_pid=$! after ssh and add kill $ssh_pid after the browser.
  • Topera
    Topera about 4 years
    Hello world about how to get pass with read command: $ read -s -p "Password: " myPass; echo "Password informed is: $myPass"