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 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. Generate a public key: ssh-keygen -t dsa; 2. Use ssh-copy-id -i $HOME/.ssh/ 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 -R - 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 -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 ( that will be forwarded to 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:". On hostB you run program that listens When you connect program to at host A, it gets forwarded thought the SSH tunnel to host B, to the program that listens 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 .