I found what caused the problem.
$ ssh MY_IP 'bash -l -c "echo TERM=$TERM"' setterm: $TERM is not defined. BASH_PROFILE BASHRC TERM=dumb
setterm was only used in /etc/profile.d/disable-beep.sh: $ cat /etc/profile.d/disable-beep.sh setterm -blength 0
I removed that and it now works.
Maciej Sitarz