ssh command execution doesn't consider .bashrc | .bash_login | .ssh/rc? [duplicate]

I am trying to execute a command remotely over ssh, example:

ssh <user>@<host> <command>

The command which needs to be executed is an alias, which is defined in .bashrc, e.g.

alias ll='ls -al'

So what in the end the following command should get executed:

ssh user@host "ll"

I already found out that .bashrc only gets sourced with interactive shell, so in .bash_login I put:

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

and I also tried to define the alias directly in .bash_login.

I also tried to put the alias definition / sourcing of .bashrc in .bash_profile and also in .ssh/rc. But nothing of this works. Note that I am not able to change how the ssh command is invoked since this is a part of some binary installation script. The only thing I can modify is the environment. Is there any other possibility to get this alias sourced when the ssh command is executed? Is there some ssh configuration which has to be adapted?


From the man pages of bash:

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt

There are a couple ways to do this, but the simplest is to just add the following line to your .bashrc file:

shopt -s expand_aliases

Instead of:

ssh user@host "bash -c ll"

try:

ssh user@host "bash -ic ll"

to force bash to use an "interactive shell".