Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 professional system and network administrators.

3 Answers 3

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

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 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

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.