How to automatically run commands on SSH connection?
Solution 1
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!
Solution 2
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/commands.sh At the time of ssh i will do it as follows ssh vidyadhar@machine `/home/vidyadhar/commands.sh'
Related videos on Youtube
Ryan
Ruby & Rails aficionado keen on big data, cloud computing, usable web & photography.
Updated on September 18, 2022Comments
-
Ryan over 1 year
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>
, agit 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?