DC microgrids (MGs) are complex systems connecting a number of renewable energy sources to different types of loads based on distributed networks. However, the strong reliance on communication networks makes DC MGs vulnerable to intentional cyber-attacks. In this paper, a distributed attack detection scheme is presented for the DC MG system by proposing an observer. The proposed detector is able to detect attacks with only local knowledge of the overall DC microgrid system. By eigenvalue assignment method, the designed residual is decoupled from both load and neighbor voltage changes. Furthermore, an optimization problem is provided to increase the attack detectability of the proposed observer. The presented method is easy to design with less computation complexity. The performances of the proposed scheme are validated by numerical simulations and experiments.