Yes it is illegal and also dangerous to walk along the side of
railroad tracks. Many people walking to close to the tracks have
been hit and killed by oncoming trains.
Further it is considered trespassing to walk anywhere on the
railroad right of way outside of crossing the tracks at an
established grade crossing.