The formation of adhesive surface structures called pili or fimbriae (‘bacterial hair’) is an important contributor towards bacterial pathogenicity and persistence. To fight often chronic or recurrent bacterial infections such as urinary tract infections, it is necessary to understand the molecular mechanism of the nanomachines assembling such pili. Here, we focus on the so far best-known pilus assembly machinery: the chaperone–usher pathway producing the type 1 and P pili, and highlight the most recently acquired structural knowledge. First, we describe the subunits' structure and the molecular role of the periplasmic chaperone. Second, we focus on the outer-membrane usher structure and the catalytic mechanism of usher-mediated pilus biogenesis. Finally, we describe how the detailed understanding of the chaperone–usher pathway at a molecular level has paved the way for the design of a new generation of bacterial inhibitors called ‘pilicides’.