This question already has an answer here:

If I want to shut down my machine programmatically or on the terminal, I must do sudo poweroff or sudo shutdown. If I want to shut down my machine through my window manager and desktop environment, I navigate to my application menu and click "shut down". This does not require my password. How is this implemented?

marked as duplicate by Anthon, Gilles, Community Apr 16 '16 at 17:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.