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
link|improve this question

70% accept rate
feedback

2 Answers

up vote 3 down vote accepted

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.

link|improve this answer
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 Feb 25 '10 at 18:54
Never mind. I put the command in single quotes and it worked. – Xeoncross Feb 25 '10 at 18:56
You have to either relaunch your prompt or reload your bashrc with ` source ~/.bashrc` – Loïc Wolff Feb 25 '10 at 19:04
1  
Behold! Ye Shall Worship The Almight Aliasing! :D – dag729 Feb 25 '10 at 19:13
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.