Autostart SSH tunnels on load (Ubuntu)

2

1

Every time I login into my computer I start a SSH connection to a remote computer for database work. How can I automate this in Ubuntu so that I don't have to type this in each time I login to my computer?

ssh -L 3333:dbserver:3306 user@othersite.com

Xeoncross

Posted 2010-02-24T18:26:06.343

Reputation: 3 274

Answers

3

You can alias it in you ~/.bashrc.

Add that line alias db_connect="ssh -L 3333:dbserver:3306 user@othersite.com" And reload the bashrc file with source ~/.bashrc

And now you only have to type db_connect to ssh to your database server.

Loïc Wolff

Posted 2010-02-24T18:26:06.343

Reputation: 1 947

Hmm.. this isn't working now that I have logged out and tested it. Do you need to type anything else before "db_connect" in the prompt? It just says "command not found". – Xeoncross – 2010-02-25T18:54:32.340

Never mind. I put the command in single quotes and it worked. – Xeoncross – 2010-02-25T18:56:33.527

You have to either relaunch your prompt or reload your bashrc with source ~/.bashrc – Loïc Wolff – 2010-02-25T19:04:48.377

1Behold! Ye Shall Worship The Almight Aliasing! :D – dag729 – 2010-02-25T19:13:19.687

0

You can modify your shell configuration to execute commands on startup. For a bash shell, simply edit ~/.bashrc and add your connection line.

sgtFloyd

Posted 2010-02-24T18:26:06.343

Reputation: 175