Try to understand that chickens use their beaks, besides eating, to communicate - with each other, and with their humans.
When they come up behind you and peck you on the back of the leg, or on your back, if you're stooping, they are trying to get your attention. It usually means they want you to pay attention to them, pick them up, cuddle them, or feed them.
They peck each other when one does something they don't approve of. Thus, if you want them to know that pecking you is not acceptable, take your finger and "peck" them on the back of the head. This is language they immediately understand. It won't take many "pecks" to let them know you don't want them to behave in that manner.