Sometime you need to restart your macOS machine with keyboard.

You can done by press shortcut

Command + Shift + Q: Press this key combination to log out of the current user account. Logout will happen after confirmation.

Command + Shift + Option + Q: When you combine with Option key, you will not be asked to confirm, and log out will occur right away.