Get the App
SLTechnology News&Howtos  ›  Development  › 

How to authorize and remove sudo permissions to users in Linux

Shulou Source: shulou.com Published: 2022-06-01 15:13:43 10月06日 Update

Xiaobian to share with you how to authorize users and remove sudo permissions in Linux, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

As you know, users can perform any administrative task with sudo privileges on Ubuntu systems. When creating new users on Linux machines, they cannot perform any administrative tasks until you add them to the sudo group.

Granting sudo privileges to ordinary users on Linux

Typically, we create new users using the adduser command, as shown below.

$ sudo adduser ostechnix

If you want your newly created user to perform administrative tasks using sudo, simply add it to the sudo group using the following command:

$ sudo usermod -a -G sudo hduser

The above command will make a user named ostechnix a member of the sudo group.

You can also use this command to add users to sudo groups.

$ sudo adduser ostechnix sudo

Now log out and log in as the new user for this change to take effect. The user has become an administrative user.

To verify it, simply prefix any command with sudo.

$ sudo mkdir /test[sudo] password for ostechnix: remove sudo privileges from user

Sometimes, you may want to remove sudo privileges for a particular user without removing it in Linux. To make any user normal, simply remove them from the sudo group.

For example, if you want to remove a user named ostechnix from the sudo group, you simply run:

$ sudo deluser ostechnix sudo

Example output:

Removing user `ostechnix' from group `sudo' ... Done.

This command only removes user ostechnix from the sudo group, but does not permanently remove the user from the system. Now, it's a regular user, unable to perform any administrative tasks like sudo users.

In addition, you can revoke sudo access from users using the following command:

$ sudo gpasswd -d ostechnix sudo

Be careful when deleting users from sudo groups. Do not remove real administrators from sudo groups.

Verify that user ostechnix has been removed from the sudo group with the command:

$ sudo -l -U ostechnixUser ostechnix is not allowed to run sudo on ubuntuserver.

Yes, user ostechnix has been removed from the sudo group and he cannot perform any administrative tasks.

Be careful when deleting users from sudo groups. If you have only one sudo user on your system and you remove him from the sudo group, you cannot perform any administrative operations, such as installing, removing, and updating programs on your system. So be careful. In our next tutorial, we will explain how to restore sudo permissions to users.

The above is "How to authorize and remove sudo permissions for users in Linux" all the content of this article, thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Users permissions commands management tasks just system ordinary article content member authentication not much not prefix only can make most of know tutorial Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei Microsoft MariaDB vpn