Bacteria use surface-exposed, proteinaceous fibers called pili for diverse behaviors, including horizontal gene transfer, surface sensing, motility, and pathogenicity. Visualization of these filamentous nanomachines and their activity in live cells has proven challenging, largely due to their small size. Here, we describe a broadly applicable method for labeling and imaging pili and other surface-exposed nanomachines in live cells. This technique uses a combination of genetics and maleimide-based click chemistry in which a cysteine substitution is made in the major pilin subunit for subsequent labeling with thiol-reactive maleimide dyes. Large maleimide-conjugated molecules can also be used to physically interfere with the dynamic activity of filamentous nanomachines. We describe parameters for selecting cysteine substitution positions, optimized labeling conditions for epifluorescence imaging of pilus fibers, and methods for impeding pilus activity. After cysteine knock-in strains have been generated, this protocol can be completed within 30 min to a few hours, depending on the species and the experiment of choice. Visualization of extracellular nanomachines such as pili using this approach can provide a more comprehensive understanding of the role played by these structures in distinct bacterial behaviors.