Menu
User

DropVPS Team

Writer: Cooper Reagan

How to view sudoers file in Linux?

How to view sudoers file in Linux?

Publication Date

06/12/2025

Category

Articles

Reading Time

2 Min

Table of Contents

To view the sudoers file in Linux, you need elevated privileges. The sudoers file defines which users and groups have administrative rights, and it’s located at:

/etc/sudoers

However, you should never edit or even view this file directly with a regular text editor like nano or vim, as it can break your sudo access if something goes wrong.

Instead, use the following methods to safely view it:

Using visudo in read-only mode

The visudo command is the safest way to handle the sudoers file because it performs syntax checks and avoids conflicts with simultaneous edits. To view it (without editing), do this:

sudo visudo -c

This checks for syntax errors and shows you whether the file is valid. To view the actual content:

sudo visudo

Now press:

  • Ctrl + X right away to exit without editing, or

  • Use arrow keys to navigate if you’re curious.

This opens the file in the default editor set for visudo (usually vi or nano).

Using cat or less (read-only, but riskier)

If you’re sure you just want to look without editing, and you’re confident nothing will break:

sudo cat /etc/sudoers

Or, for a scrollable view:

sudo less /etc/sudoers

You can navigate with arrow keys or press q to quit less.

Viewing drop-in configuration files

Modern Linux distributions (especially Ubuntu and Debian) often split sudoers configuration into multiple files under /etc/sudoers.d/.

To view them:

sudo ls /etc/sudoers.d/

Then open individual ones like:

sudo cat /etc/sudoers.d/90-cloud-init-users

Again, always use cat, less, or visudo to avoid accidentally changing anything.

Safer alternative: view via visudo with specified file

If you want to check a drop-in file via visudo, you can do:

sudo visudo -f /etc/sudoers.d/filename

Replace filename with the actual file. This ensures syntax checking, even for additional config files.

Linux VPS
U
Loading...

Related Posts