Configure your Fedora system to use sudo

The sudo command makes it easier to manage your Fedora system. Certain commands in Fedora expect to be run only by a privileged user or administrator. The sudo command lets you run a command as if you’re the administrator, known as root.

Unlike some other methods, it also offers some key features:

  • Keeps a log when someone uses sudo to run a command
  • Supports automatic command line completion
  • Allows sharing of privileges without sharing the root password

Set up during installation

If you are installing Fedora, you can configure this function in advance. In the installer, when you set up a normal user account, check the option for Make this user administrator:

User administrator (sudo) option enabled in installer

Behind the scenes, this option sets up the user so they can use sudo when they login. This is a time saver for installations like laptops. They typically have a single user who owns the system.

Set up after installation

If you’ve already installed your system, don’t worry. You can still configure this option. First, open a terminal if needed. Use this command to verify your user account name:

$ id
uid=1000(john) gid=1000(john) groups=1000(john) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

In this example, your account name is john. Next, use this command to assume privileges of root, the system administrator. Enter the password for root at the prompt.

su -

Next run this command to add your username to the special wheel group. This group is already set up to provide sudo access:

usermod -a -G wheel john

You can check the results using the id command:

# id
uid=1000(john) gid=1000(john) groups=1000(john),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

Using sudo

You must logout, and then login, to inherit the group membership change. Once you do, you can issue a command like this:

sudo <command>

You are asked for your account password, not the password for root. The command then runs, as if you were the system administrator. If you want to start an interactive root shell, use this command:

sudo -i

 

Using Software

5 Comments

  1. Philipp

    ..and I have read the title as “Configuring your Fedora system to sudo [suit you]”

  2. michael

    I had to Reboot, not just Log out/in. Then it worked fine.

  3. Sebastian

    Whoa! Don’t do this for just any user. By adding a user to the wheel group they are able to use sudo to anything they want on the box. It is better to restrict what a user can do with sudo through the use of Command Aliases. Also if you have multiple Linux systems adding everyone to the wheel group becomes a pain if someone’s role change and they no longer need sudo. My suggestion would be to create separate groups for users based on roles and then use Command Aliases to restrict what they can do. this way if you are using something like LDAP for group management you only need to remove the user from the group in one location and then there ability to sudo goes away. Also don’t mess with /etc/sudoers, for individual users/groups. Save that file for global changes. Put your new sudo config files in /etc/sudoers.d. And above all, use the visudo command (visudo -f /etc/sudoers.d/).

  4. Jimbo

    This would be more appropriately titled, ‘How to give a user SUDO privilege”. There is much more to configuring sudo such as allowing certain users or groups very specific individual privileges that are reserved for the super user.

  5. Xarchus

    Same as @michael: I had to reboot for the change to take effect (also I am curious if the log in/out method worked for anyone, including the guide author …)

    I’ve seen some comments elsewhere that Gnome might be the culprit here (hanging on/caching the group ids and needing something more drastic than a simple logout to reset that).

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions