Create sudoer user linux

How to Create Sudo User in RHEL, CentOS, Rocky & AlmaLinux

The Redhat Enterprise Linux (RHEL) ecosystem hosts several interesting Linux-based OS distributions. The OS pair AlmaLinux and Rocky Linux are exciting replacements for the discontinued CentOS distribution.

RHEL 8, AlmaLinux, and Rocky Linux systems are increasingly being sorted after by many Linux users due to the performance footprints they offer.

The main users of an operating system environment can be categorized into the root (Sudoer) users and non-root users. Root users have full control of the operating system environment and can create other users in addition to managing the OS’s applications, processes, and configurations. The non-root users have limited interactions with an operating system environment.

As the root user of your Linux system, you will at one point need to give other non-root users more OS privileges and execution power. For this step to happen, these normal OS users will need to be graduated to Sudo users.

Make sure you have Sudoer/root user access privileges on your system before proceeding with the article guide.

Creating a New Sudo/Sudoer User in Linux

The term Sudo is an abbreviation for the superuser do or substitute user do. The directory path /etc/sudoers hosts existing Sudoer users’ security policy associated with their warranted privileges.

To create a new user from scratch, execute the following command.

$ sudo adduser linuxshelltips_tutor

The above command will create a non-root user called linuxshelltips_tutor.

Create New User in Linux

Next, we need to assign this new user a login password.

$ sudo passwd linuxshelltips_tutor

Set New User Password

We now have two options of making your exiting/created Linux user a Sudoer-privileged user.

Option 1: Add User to Sudo Wheel Group

Only wheel group members are granted Sudo access and privileges. To make user linuxshelltips_tutor a member of this wheel group, we will implement the usermod command in the following manner.

$ sudo usermod -aG wheel linuxshelltips_tutor

With the above command execution, we have made linuxshelltips_tutor a Sudoer user.

Option 2: Editing /etc/sudoers File

This file lists all the users on your system and their customizable access and privileges. We can modify this file to make our newly created user a Sudoer user in the following manner.

Читайте также:  Раздача wifi через linux

First, open the file with your preferred command-line editor.

$ sudo nano /etc/sudoers file

At the bottom of this file, we will modify it in the following manner in order to make linuxshhelltips_tutor a Sudoer user.

linuxshelltips_tutor ALL=(ALL:ALL) NOPASSWD:ALL

Add User to Sudoers File

The NOPASSWD portion of the above entry will not require the linuxshelltips_tutor user to adhere to any password authentication protocol when executing sudo-associated terminal commands.

Testing Sudoer User Access in Linux

We need to confirm that we indeed created a Sudoer user. The first Sudoer user test can be performed with the following commands.

$ su linuxshelltips_tutor $ sudo whoami

Testing Sudoer User Access

You can even switch to the new user’s home directory before executing the whoami command.

As the command output suggests, we are dealing with a root user.

Alternatively, listing the contents under /root should also confirm that we are dealing with a root/sudo user. The content of the /root path cannot be displayed under a non-root user profile.

Listing Root User Files

A Sudo/Sudoer user has exclusive Linux OS privileges which are not availed for a non-Sudo user. This user has more control in their assigned OS role.

Источник

How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]

How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]

When managing a server, you’ll sometimes want to allow users to execute commands as “root,” the administrator-level user. The sudo command provides system administrators with a way to grant administrator privileges — ordinarily only available to the root user — to normal users.

In this tutorial, you’ll learn how to create a new user with sudo access on Ubuntu 20.04 without having to modify your server’s /etc/sudoers file.

Note: If you want to configure sudo for an existing user, skip to step 3.

Step 1 — Logging Into Your Server

SSH in to your server as the root user:

Step 2 — Adding a New User to the System

Use the adduser command to add a new user to your system:

Be sure to replace sammy with the username that you want to create. You will be prompted to create and verify a password for the user:

Output
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

Next, you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave this information blank:

Output
Changing the user information for sammy Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]

Step 3 — Adding the User to the sudo Group

Use the usermod command to add the user to the sudo group:

Again, be sure to replace sammy with the username you just added. By default on Ubuntu, all members of the sudo group have full sudo privileges.

Step 4 — Testing sudo Access

To test that the new sudo permissions are working, first use the su command to switch to the new user account:

As the new user, verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:

For example, you can list the contents of the /root directory, which is normally only accessible to the root user:

The first time you use sudo in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:

Output:
[sudo] password for sammy:

Note: This is not asking for the root password! Enter the password of the sudo-enabled user you just created.

Читайте также:  Log об ошибках linux

If your user is in the proper group and you entered the password correctly, the command that you issued with sudo will run with root privileges.

Conclusion

In this quickstart tutorial, we created a new user account and added it to the sudo group to enable sudo access.

For your new user to be granted external access, please follow our section on Enabling External Access for Your Regular User.

If you need more detailed information on setting up an Ubuntu 20.04 server, please read our Initial Server Setup with Ubuntu 20.04 tutorial.

Get Ubuntu on a hosted virtual machine in seconds with DigitalOcean Droplets! Simple enough for any user, powerful enough for fast-growing applications or businesses.

Источник

The Ultimate Guide to Linux — Creating a Sudo User

The Ultimate Guide to Linux - Creating a Sudo User

sudo stands for either «superuser do» or «switch user do», and sudo users can execute commands with root/administrative permissions, even malicious ones. Be careful who you grant sudo permissions to – you are quite literally handing them the key your house.

Before creating a new sudo user, you must first create a new user.

How to Create a New User

Use adduser or useradd to add a new user

Be sure to replace username with the user that you want to create. Also, note that to create a new user, you must also be a sudo user yourself.

Use passwd to update the new user’s password

A strong password is highly recommended!

Give the New User Sudo Permissions

After creating a new user, add them to the appropriate group using the usermod command.

On Debian systems (Ubuntu / Linux Mint / ElementryOS), add users to the sudo group

sudo usermod -aG sudo username

On RHEL based systems (Fedora / CentOS), add users to the wheel group

sudo usermod -aG wheel username

How to Delete a User

To delete a user, use the following commands.

Debian based systems (Ubuntu / Linux Mint / ElementryOS)

RHEL based systems (Fedora / CentOS)

That’s all you need to know about creating a new sudo user in Linux. And remember, «With great power comes great responsibility.»

If this article was helpful, tweet it .

Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

freeCodeCamp is a donor-supported tax-exempt 501(c)(3) charity organization (United States Federal Tax Identification Number: 82-0779546)

Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons — all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.

Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.

Источник

How To Add User To Sudoers & Add User To Sudo Group on Ubuntu

The sudo command is the preferred means to handle elevated permissions. In supported versions of Ubuntu, using the sudo command will grant elevated permissions for 15 minutes.

Standard user accounts are restricted from performing sensitive tasks, such as viewing the contents of the /root directory. This prevents the accidental use of commands with massive consequences. It also makes it more difficult for intruders to compromise a system. However, sometimes you need to run an administrative command. Sudo – or Super User Do – grants you privileges to run sensitive tasks.

Читайте также:  What is linux cloud server

This simple tutorial will show you how to add a new user on Ubuntu and provide sudo access.

creating a sudo user on ubuntu tutorial header

  • A system running a supported version of Ubuntu
  • Access to a root user account or another account with sudo privileges
  • Access to a terminal window/command line (CtrlAltT)

Note: Linux Sudo Command tutorials also available for CentOS and Debian.

Steps to Add Sudo User on Ubuntu

Step 1: Create New User

1. Log into the system with a root user or an account with sudo privileges.

2. Open a terminal window and add a new user with the command:

The adduser command creates a new user, plus a group and home directory for that user.

You may get an error message that you have insufficient privileges. (This typically only happens for non-root users.) Get around it by entering:

3. You can replace newuser with any username you wish. The system will add the new user; then prompt you to enter a password. Enter a great secure password, then retype it to confirm.

4. The system will prompt you to enter additional information about the user. This includes a name, phone numbers, etc. – these fields are optional, and can be skipped by pressing Enter.

Creating a sudo user in Ubuntu

Step 2: Add User to Sudo Group

Most Linux systems, including Ubuntu, have a user group for sudo users. To grant the new user elevated privileges, add them to the sudo group.

In a terminal, enter the command:

Replace newuser with the username that you entered in Step 1.

Again, if you get an error, run the command with sudo as follows:

sudo usermod -aG sudo newuser

The -aG option tells the system to append the user to the specified group. (The -a option is only used with G .)

Add user to sudo group ubuntu

Note: Usermod command is a useful tool for user management. To learn more about its options, refer to our guide How To Use The Usermod Command In Linux.

Step 3: Verify User Belongs to Sudo Group

Enter the following to view the groups a user belongs to:

The system will respond by listing the username and all groups it belongs to, for example: newuser : newuser sudo

Step 4: Verify Sudo Access

Replace newuser with the username you entered in Step 1. Enter your password when prompted. You can run commands as normal, just by typing them.

However, some commands or locations require elevated privileges. If you try to list the contents of the /root directory, you’ll get an access denied error: ls /root

The command can be executed with:

The system will prompt for your password. Use the same password you set in Step 1. You should now see the contents of the /root directory.

verify sudo access in ubuntu

Now you know how to add and create a user with sudo privileges on Ubuntu.

Before sudo, users would log in to their systems with full permissions over the entire system with the su command. This was risky as users could be exploited by tricking them into entering malicious commands. These vulnerabilities were solved by limiting account privileges. However, administrators still had to log out of their account and into an admin account to perform routine tasks.

The sudo command in Ubuntu strikes a balance – protecting user accounts from malicious or inadvertent damage while allowing a privileged user to run administrative tasks. To learn more about the difference between these commands, check out Sudo vs. Su.

Источник

Оцените статью
Adblock
detector