Sudo on CenOS, Red Hat Enterprise Linux and Scientific Linux

Sudo on CentOS / Scientific Linux / RHEL

Sudo on CenOS, Red Hat Enterprise Linux and Scientific Linux

This short howto is about setting up sudo on Red Hat Entreprise Linux and its derivates CentOS and Scientific Linux. It also gives a quick introduction on using the vi text editor through visudo.

Becoming root: su & sudo

CentOS, Scientific Linux and RHEL do not use sudo as Ubuntu does. Instead, you are supposed to use su or su root to get higher permissions. su stands for super user or switch user. Type exit to exit the superuser mode. More information on su on the CentOS Wiki.

After years using Ubuntu and Linux Mint, I got used to sudo. To be able to run sudo on CentOS, one has to add the current user to the /etc/sudoers file. Editing the sudoers file is done via the visudo utility.

Editing sudoers with visudo

Visudo edits the sudoers file in a safe fashion, locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. (from the visudo man page)

You can only run visudo as root, so that we’ll need to run su:
su root

The next step is to run visudo without any parameters. It will open the /etc/sudoers file in vi (a text editor):

Using the vi text editor

There is no need to be familiar with vi, just to know the some basics. Vi has two so called “modes”:
– The insert mode allows you to insert/write text
– The command mode is for saving files, text manipulation and much more.

To edit a file, type i to enter the insert mode.
Press Esc to exit the insert mode and enter the command mode.

In command mode, use a : colon to start commands:

Press : + w + q + Enter to save your changes and exit (write and quit)

Type : + q + ! + Enter to exit without saving changes.

Add yourself to the sudoers in visudo

All you have to do now is to add the following line at the end of the file (press i to enter insert mode):
user_name ALL=(ALL) ALL

ALL must be written in capital letters. Replace user_name with your user name.

Visudo - Adding user to sudoers in CentOS, Scientific Linux and RHEL

Finally, press Esc to enter the command mode, and : + w + q + Enter to save and exit the editor. Changes are effective immediately, you may now use sudo.

N.B. If you plan to use Truecrypt, comment out the following line in /etc/sudoers by inserting a dash:
#Default requiretty

By Johannes Eva, 2012 – May 2016

  • All
  • Archive
  • Image
  • Linux
  • Linux Server
  • Smartwatches
  • Updated
  • WordPress
LibreOffice installation on Linux

How to install LibreOffice 7.4 on Linux Mint, Ubuntu, MX Linux, Debian…

Last updated on September 27, 2022 This article describes how to install LibreOffice 7.4 on Debian/Ubuntu-based Linux distributions, such as Linux Mint, MX Linux, Ubuntu …

Read More →

AVIF browser test page: AVIF support in Chrome, Firefox, Edge…

Logo: Alliance for Open Media. License: BSD Last updated on September 29, 2022 Is your browser capable of displaying AVIF images? Here comes a fast answer …

Read More →
How to remove TLSv1.0 and 1.1 and enable TLS 1.3 in Nginx on Ubuntu Server
Linux ServerUpdated

How to remove TLSv1.0 / 1.1 and enable TLS 1.3 in Nginx …

Photo: License: CC BY-SA 4.0 … on Ubuntu 18.04, 20.04 or 22.04 Last updated on September 29, 2022In January 2020, SSL Labs started to …

Read More →
How to install Mozilla Firefox on Linux (Ubuntu, Linux Mint or any Linux distribution)

How to Install Firefox 105 on Linux Mint, Ubuntu, Debian or any other Linux distribution

Photo: janeb13 / Pixabay, Pixabay License Last updated on September 27, 2022 This how-to explains how to install Firefox on Linux, with or without replacing an existing …

Read More →
DVD support (with libdvdcss) and media codecs on Linux

Install DVD support (libdvdcss) on Debian or Ubuntu

Photo: License: CC BY-SA 4.0 Last updated on September 27, 2022 On Linux, DVD support is provided through the libdvdcss or libdvdcss2 packages. Some …

Read More →
Libre Software

Twenty Fifteen WP theme: the right way to remove post dates and author

If you’re trying to remove the post dates and author in WordPress Twenty Fifteen theme, you could just add the following code to the style.css …

Read More →
Backup Scheduler, the only really free multisite-compatible plugin in the wild!

Free backup plugins for WordPress Multisite

This post is about free backup plugins for WordPress Multisite installations. The web is full of really useless “greatest backup plugins” and “best WordPress backup” …

Read More →
Libre Software

Older archived articles

Ubuntu & NVIDIA: external monitor, rotation, … (.pdf) January 2011: This how-to describes how to configure external monitors with the “NVIDIA X Server Settings” utility …

Read More →
Libre Software

How to edit image metadata on Linux

Photo: License: CC BY-SA 4.0 Last updated on September 27, 2022 Image metadata is a complex field with multiple standards, the most important among …

Read More →

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.