Privilege escalation in Linux is typically accomplished via sudo
, which stands for “superuser do”. This command allows regular users to execute commands as a superuser or another user.
However, disabling the use of sudo
entirely is generally not a good idea, because some tasks require administrative privileges to run. What you can do is control which users have sudo
access.
To modify sudo
access, you edit the sudoers
file. Here’s how:
- Open a terminal.
- Type
sudo visudo
to edit the sudoers file. This command uses the default text editor, which is usuallynano
orvi
. Note:visudo
locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. If the sudoers file is currently being edited you will receive a message to try again later. - In the sudoers file, you’ll see a line that looks something like this:
#username ALL=(ALL:ALL) ALL or #%sudo ALL=(ALL:ALL) ALL
The first line gives the user username
permission to run sudo
for any command. The second line gives any user in the sudo
group the same permission.
- To remove
sudo
privileges, you can either remove the appropriate line entirely, or comment it out by adding a#
at the beginning of the line:#username ALL=(ALL:ALL) ALL
or#%sudo ALL=(ALL:ALL) ALL
- Once you’ve made your changes, save and exit the file. In
nano
, you do this by pressingCtrl+O
to save, thenCtrl+X
to exit. Invi
, press:wq
and thenEnter
. - The changes will take effect immediately.
This way, you can disable privilege escalation for specific users or groups.
Warning: Be very careful while editing the sudoers file. A wrong entry can lock you out of your system or give users more privileges than intended.