Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I create a ssh tunnel in Ubuntu that is persistent? I have tried a lot of ways but I haven't gotten it to work.

share|improve this question

migrated from serverfault.com Dec 16 '11 at 18:06

This question came from our site for system and network administrators.

apt-get install autossh, then use autossh instead of ssh in the tunnel creation command line. If you set up public key auth it will be very persistent.

share|improve this answer
    
How do i set up public key authentication?:D – Stanciu Alexandru-Marian Dec 16 '11 at 18:33
1  
1. Generate a public key: ssh-keygen -t dsa; 2. Use ssh-copy-id -i $HOME/.ssh/id_dsa.pub user@host – Vi. Dec 16 '11 at 18:38

You need to be more specific in your question. Anyway, you can look at the this link for more information about SSH tunnels in ubuntu.

share|improve this answer
    
I have two routers and i have to create a ssh tunnel between them. And the settings must remain after a reboot. I work with lxc containers, so my routers are actually lxc containers. – Stanciu Alexandru-Marian Dec 16 '11 at 18:01

Something like ssh -N user@host -L 0.0.0.0:5555:127.0.0.1:5555 -R 0.0.0.0:5556:127.0.0.1:5556 - will forward port 5555 from us to them and port 5556 from them to us.

share|improve this answer
    
The command ssh -N user@host -L 0.0.0.0:5555:127.0.0.1:5555 -R i give in every container? And user@host is the name and ip of the end of the tunnel in wich i give this command? – Stanciu Alexandru-Marian Dec 16 '11 at 18:31
    
Don't understand the question. What is a container here? – Vi. Dec 16 '11 at 18:38
    
If you use that command (except of "-R"), ssh will open TCP port at your host (0.0.0.0:5555) that will be forwarded to 127.0.0.1:5555 on the remote host. – Vi. Dec 16 '11 at 18:40
    
I have to create a tunnel between A and B. Where i give that command? In A and B changing what? A and B have IP addresses, and are connected directly. I have to create a ssh tunnel between them. Thats what i have to do. – Stanciu Alexandru-Marian Dec 16 '11 at 18:45
    
Example: on host A you do "ssh user@hostB -L 6666:127.0.0.1:5555". On hostB you run program that listens 127.0.0.1:5555. When you connect program to 127.0.0.1:6666 at host A, it gets forwarded thought the SSH tunnel to host B, to the program that listens 127.0.0.1:555 at hostB. – Vi. Dec 16 '11 at 19:07

You must log in to answer this question.

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