2

I want to create a full SSH tunnel between two Ubuntu 12.04 servers, (I found out about SSHuttle but because of a bug in the handling of file descriptors it will crash under high load) very much like IPSEC but because I need it only for two hosts the complexity of creating a full fledged IPSEC configuration looks to be an overkill.

What I want to achieve is that all the data going between server1 and server2 will be encrypted without needing to create thousand of SSH dynamic ports.

4
  • 1
    Man thank you , for your question I have found a very good blog for sys admins. I will post the answer too.
    – Raja G
    May 21, 2014 at 11:03
  • What do you mean by "full ssh tunnel" ?
    – Rémi
    May 21, 2014 at 11:06
  • 1
    Full SSH tunnel as in passing all the ports\connections\data\sessions and not only a single port forward like with SSH's -D options for dynamic ports
    – Ba7a7chy
    May 21, 2014 at 11:08
  • Then, I would recommend using VPN software (such as openvpn) instead of ssh. setting up openVPN between two host is really simple.
    – Rémi
    May 21, 2014 at 11:17

1 Answer 1

2

This answer belongs to brandonchecketts.

Assume You have two hosts named as Host-A and Host-B. Now we are going to create a SSH Tunnel between these two and make sure that Tunnel is up & live for all the time.

Configuration Need to be done for Host-A:

Open your terminal , turn into root and paste the code one after one

useradd -d /home/tunnel tunnel
passwd tunnel 
su - tunnel    

next step is about creating a SSH key

In the terminal paste as

ssh-keygen

and then choose default choice for all prompt and copy the key with

cat /.ssh/id_rsa.pub

Now this time we have to configuration for Host-B

Open your terminal and execute these commands

useradd -d /home/tunnel tunnel
passwd tunnel 
su - tunnel

and in terminal type as

mkdir .ssh
vi .ssh/authorized_keys

It will open a file in terminal and paste the above copied key from Host-A.

Now in the terminal type as

vi /home/tunnel/check_ssh_tunnel.sh

and paste as

createTunnel() {
    /usr/bin/ssh -f -N -L13306:hostb:3306 -L19922:hostb:22 tunnel@hostb
    if [[ $? -eq 0 ]]; then
        echo Tunnel to hostb created successfully
    else
        echo An error occurred creating a tunnel to hostb RC was $?
    fi
}
## Run the 'ls' command remotely.  If it returns non-zero, then create a new connection
/usr/bin/ssh -p 19922 tunnel@localhost ls
if [[ $? -ne 0 ]]; then
    echo Creating new tunnel connection
    createTunnel
fi

save and close and make it executable with

chmod 700 /home/tunnel/check_ssh_tunnel.sh

and then run the script, it will start a Tunnel with remote PC.

Read that above link, it is must.

5
  • But this forward only one port, no ?
    – Rémi
    May 21, 2014 at 11:19
  • you want multiple ports right ?
    – Raja G
    May 21, 2014 at 11:21
  • @Rémi check this out unix.stackexchange.com/questions/19242/…
    – Raja G
    May 21, 2014 at 11:30
  • This will only create a one port tunnel, it is cool and very elegant but not what I needed.
    – Ba7a7chy
    May 21, 2014 at 11:30
  • 1
    @Ba7a7chy its k , glad its helped you a bit
    – Raja G
    May 21, 2014 at 11:31

You must log in to answer this question.

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