A mobile ad hoc network is a kind of wireless communication network that does not rely on a fixed infrastructure and is lack of any centralized control. These characteristics make it vulnerable to security attack, so protecting the security of the network is essential. Like many distributed systems, security in ad hoc networks widely relies on the use of key management mechanisms. However, traditional key management systems are not appropriate for them. We aim at providing a secure and distributed authentication service in ad hoc networks. We propose a secure public key authentication service based on our trust model and network model to prevent nodes from obtaining false public keys of the others when there are malicious nodes in the network. We perform an overall evaluation of our proposed approach by simulations. The experimental results indicate clear advantages of our approach in providing effective security in mobile ad hoc networks.