Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have some Amazon EC2 instances that run Ubuntu 10.04.1 LTS.

Every time I connect to those instances I run a couple of simple commands, like a cd <repository>, a git status etc.

How can I add them to a script / to which script should I add them so they would be automatically ran every time, on SSH connect?

share|improve this question
up vote 4 down vote accepted

The solution is basically to run a script on login.

Since Bash looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

I did a simple ls -la ~, saw that from that hierarchy .profile was the first only one available, so I just appended my commands here.

Problem solved!

share|improve this answer

You can add all your commands in a single script and can call the script through the SSH line.

For eg. I will dump all the commands in /home/vidyadhar/ At the time of ssh i will do it as follows ssh vidyadhar@machine `/home/vidyadhar/'

share|improve this answer

Your Answer


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.