2

I want to open many tunnels at once, they all have the same long password.

With -f, i.e.,

ssh -fN -p 22 usr1@gate1 -L 10001:ip1:22
ssh -fN -p 22 usr2@gate2 -L 10002:ip2:22
...
ssh -fN -p 22 usrn@gaten -L 1000n:ipn:22

I can open the tunnels in background, which allows me to run them all together and then just type consecutively the password as many times as the number of tunnels I am opening (n).

Given that what I type is the same, I would like to find a way to type it just once, but still do it in a secure way.

4
  • 4
    use password less ogin with key, then have a look at ssh-agent. or use sshpass
    – Archemar
    Jun 25, 2018 at 11:17
  • Set up public/private key based login. Jun 25, 2018 at 13:06
  • @Archemar I want to put the password explicitly, but only once. You are instead suggesting to install the keys and login without password right?
    – myradio
    Jun 29, 2018 at 12:55
  • sshpass will help you, but password will appear in ps -ef result. password can be set to keys but you must allow for login without password. That why I reply as comment, I see no way you can do that, but maybe someone will be more clever than me.
    – Archemar
    Jun 29, 2018 at 14:07

1 Answer 1

0

I found the solution using https://stackoverflow.com/a/3980904/1424395 and https://unix.stackexchange.com/a/59632/269821

I use read -s to get the password into a variable, and then I use sshpass to pass the password to the ssh.

#!/usr/bin/env bash

# Read Password
echo -n Password:
read -s password
echo

sshpass -p $password ssh -fN -p 22 usr1@gate1 -L 10001:ip1:22
sshpass -p $password ssh -fN -p 22 usr2@gate2 -L 10002:ip2:22
...
sshpass -p $password ssh -fN -p 22 usrn@gaten -L 1000n:ipn:22

You must log in to answer this question.

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