I have noticed that when a brown person enters public transport, people often react somehow. Sometimes people for example pull their bags into their laps more tightly. They have some prejudices. One time I saw a woman immediately grimace and change seats when a woman wearing a headscarf was going to sit next to her.
One time a down and out person started yelling the n-word at me. My friends stood up for me immediately. It felt good, even though I minimized the situation. As a woman I have often heard sexually toned yelling, so called “cat calling”. It happens for instance on the escalator on the metro. The most recent example was when a guy was looking at me on the metro. When I was about to get off, he came close to me and tried to kiss me. I instinctively pushed him off and said that hey, that definitely isn’t ok! I don’t think anybody else noticed or at least they didn’t react. That left me feeling awful.
The most important thing is that someone notices the situation, and somehow lets the target of the harassment know that I noticed and I am here. You can go sit next to them and tell them to let you know if they need help.
You don’t necessarily have to say anything to the harasser, but try to create a safe feeling for that moment. The most important thing is that the person being harassed knows that they are not alone in that situation.