bash – Running a script automatically when logging in via ssh – Education Career Blog

I would like to know if there is a (simple) solution to the following issue:

When I log in with ssh to a specific host, I would like to automatically execute a (bash)script on that host. This way I could -for example- load my aliases on that host.

Definitively the bashrc script is not executed; The ssh configuration files do not seem to help in this issue either.

Any suggestions?

Thanks in advance!

BTW: The host is running on Gentoo

,

If .bashrc isn’t being run, try .profile, which has a similar function. Different shells use different startup scripts at different times, so knowing when to run things is useful.

,

On many systems where you have a choice of which shell to use, you are put through ~/.profile only. This way there is no need to find out (and no probably wrong guessing) which shell you’re running in and which profile to actually load (.bashrc, .cshrc, .kshrc etc.) and which ones to avoid loading.

The easiest solution in your case would be to create a link (a symbolic one if you prefer visibility) to your favourite shell’s startup script as in ln -s ~/.bashrc ~/.profile. If you don’t intend to ever using anything other than bash, you’re set.

Leave a Comment