PurposeUnauthorised file sharing (UFS) in online communities (OCs) is a major intellectual property concern. Researchers have traditionally viewed UFS as digital piracy and have suggested that deterrents, such as legal actions, should be in place. However, previous research has not considered the OC context and cannot explain why OC members share unauthorised files even when there is legislation against this in place. In OCs, UFS exhibits features of public goods contribution. Therefore, the authors claim that public goods contribution motivations can provide a compelling explanation for UFS in OCs.Design/methodology/approachThe authors propose a theoretical model in which two egoistic public goods contribution motivations (namely, warm-glow giving and demand for resources) are tested alongside motivations informed by the sanctions described by deterrence theory, a theory widely used within the digital piracy perspective.FindingsThe authors find that warm glow and demand for resources are positively related to UFS in OCs; the effect of warm glow is moderated by users' attachment to OCs. Importantly, the results suggest that although sanctions significantly predict UFS, the effect of sanctions on UFS becomes insignificant in the presence of warm glow, demand for resources and attachment.Originality/valueThe study offers new insights into why users engage in UFS and highlights that public goods contribution should be taken into account in developing anti-piracy policies and practices.