I have a feeling this is quite easy to do but every solution found on google has to do with adding a script to be run whenever someone logs into the machine.

What I am looking for is a way to run a script when only I log into the machine. I ssh into a shared computer and need to have it load a couple modules for me and I imagined the easiest way to do this would to just run a script on login. Is there a simple way?

  • Do you want to stay logged into an interactive session? Or have it also automatically disconnect after the script is run?
    – Keith
    Sep 3, 2012 at 20:38

1 Answer 1


Adding it to your users .bashrc file in /home/USER/.bashrc should do the trick. If the script is in bash, just add the code to the file directly. If it is not bash, (python, perl, whatever), call it from your bashrc as you would from the command line (python myscript.py).

Here is an example bashrc file.

  • Perfect adding it to the .bashrc is exactly what I was looking for.
    – user912447
    Sep 3, 2012 at 21:06
  • You might want to add it to .bash_profile instead. Depending on how you use the machine, you may start other non-login interactive shells, which would also execute your .bashrc file. (True, it's possible to start additional login shells once you are logged in, so really this is just FYI in case you ever observe your "login" script being executed again after you've logged in.)
    – chepner
    Sep 3, 2012 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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