{"id":3305,"date":"2021-03-10T06:59:37","date_gmt":"2021-03-10T01:29:37","guid":{"rendered":"https:\/\/www.24x7serversupport.com\/blog\/?p=3305"},"modified":"2021-03-10T07:00:01","modified_gmt":"2021-03-10T01:30:01","slug":"how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/","title":{"rendered":"How To Add User To Sudoers &#038; Add User To Sudo Group On CentOS 7"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Step 1: Login as Administrator<\/h3>\n\n\n\n<p>If you\u2019re working on a local machine, log in to the system with administrator credentials.<\/p>\n\n\n\n<p>If you\u2019re connecting to a remote machine (over a network), open a terminal window and enter the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh root@server_ip_address<\/pre>\n\n\n\n<p>The <strong>server_ip_address<\/strong> is the network IP address of the server you\u2019re logging into. Enter your credentials when prompted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create a New Sudo User<\/h3>\n\n\n\n<p>To add a new sudo user, open the terminal window and enter the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">adduser UserName<\/pre>\n\n\n\n<p>Use the actual username for your new user in place of <strong><em>UserName<\/em><\/strong>.<\/p>\n\n\n\n<p>Next, create a password for the new user by entering the following in your terminal window:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">passwd UserName<\/pre>\n\n\n\n<p>The system should display a prompt in which you can set and confirm a password for your new user account. If successful, the system should respond with \u201call authentication tokens updated successfully.\u201d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Add Users to Sudo Group<\/h2>\n\n\n\n<p>By default, CentOS 7 has a user group called the \u201cwheel\u201d group. Members of the wheel group are automatically granted sudo privileges. Adding a user to this group is a quick and easy way to grant sudo privileges to a user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Verify the Wheel Group is Enabled<\/h3>\n\n\n\n<p>Your CentOS 7 installation may or may not have the wheel group enabled.<\/p>\n\n\n\n<p>Open the configuration file by entering the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">visudo<\/pre>\n\n\n\n<p>Scroll through the configuration file until you see the following entry:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## Allows people in group wheel to run all commands<br><br># %wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL<\/pre>\n\n\n\n<p>If the second line begins with the # sign, it has been disabled and marked as a comment. Just delete the # sign at the beginning of the second line so it looks like the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">%wheel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL=(ALL)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ALL<\/pre>\n\n\n\n<p>Then save the file and exit the editor.<\/p>\n\n\n\n<p><strong>Note:<\/strong> If this line didn\u2019t start with a # sign, you don\u2019t need to make any changes. The wheel group is already enabled, and you can close the editor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add User to Group<\/h3>\n\n\n\n<p>To add a user to the wheel group, use the command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">usermod -aG wheel UserName<\/pre>\n\n\n\n<p>As usual, replace <strong><em>UserName<\/em><\/strong> with&nbsp;the name of the user receiving sudo privileges.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step: 3 Switch to the Sudo User<\/h3>\n\n\n\n<p>Switch to the new (or newly-elevated) user account with the <strong>su<\/strong> (substitute user) command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">su - UserName<\/pre>\n\n\n\n<p>Enter the password if prompted. The terminal prompt should change to include the UserName.<\/p>\n\n\n\n<p>Enter the following command to list the contents of the \/root directory:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ls -la \/root<\/pre>\n\n\n\n<p>The terminal should request the password for <strong>UserName<\/strong>. Enter it, and you should see a display of the list of directories. Since listing the contents of \/root requires sudo privileges, this works as a quick way to prove that <strong>UserName<\/strong> can use the sudo command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u00a0Alternative: Add User to Sudoers Configuration File<\/h2>\n\n\n\n<p>If there\u2019s a problem with the wheel group, or administrative policy prevents you from creating or modifying groups, you can add a user directly to the <strong>sudoers configuration file<\/strong> to grant sudo privileges.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Open the Sudoers File in an Editor<\/h4>\n\n\n\n<p>In the terminal, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">visudo<\/pre>\n\n\n\n<p>This will open the <strong>\/etc\/sudoers<\/strong> file in a text editor.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Add the New User to file<\/h4>\n\n\n\n<p>Scroll down to find the following section:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## Allow root to run any commands anywhere<br><br>root ALL=(ALL) ALL<\/pre>\n\n\n\n<p>Right after this entry, add the following text:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UserName ALL=(ALL) ALL<\/pre>\n\n\n\n<p>Replace <strong><em>UserName<\/em><\/strong> with the username you created in Step 2. This section should look like the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## Allow root to run any commands anywhere<br><br>root ALL=(ALL) ALL<br><br>UserName ALL=(ALL) ALL<\/pre>\n\n\n\n<p>Save the file and exit.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Test Sudo Privileges for the User Account<\/h4>\n\n\n\n<p>Switch user accounts with the <strong>su<\/strong> (substitute user) command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">su - UserName<\/pre>\n\n\n\n<p>Enter the password for the account, if prompted. The terminal prompt should change to include <strong>UserName<\/strong>.<\/p>\n\n\n\n<p>List the contents of the <strong>\/root<\/strong> directory:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ls -la \/root<\/pre>\n\n\n\n<p>Enter the password for this user when prompted. The terminal should display a list of all the directories in the <strong>\/root<\/strong> directory.<\/p>\n\n\n\n<p>This guide showed you how to <strong>add a user to sudoers in CentOS<\/strong> <strong>or modify the privileges of an existing sudo user<\/strong><em>.<\/em> The Linux <strong>sudo<\/strong> command is critical for running advanced and administrative tasks on a Linux system. While this could be done using a root user (or administrator account) using the su command, system administrators advise against operating permanently in a root account. Not only can it be a security risk, but it can also allow changes to a Linux system that can break functionality.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Login as Administrator If you\u2019re working on a local machine, log in to the system with administrator credentials. If you\u2019re connecting to a remote machine (over a network), open a terminal window and enter the command: ssh root@server_ip_address The server_ip_address is the network IP address of the server you\u2019re logging into. Enter your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[30,34,210],"tags":[],"class_list":["post-3305","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-security"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Add User To Sudoers &amp; Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Add User To Sudoers &amp; Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog\" \/>\n<meta property=\"og:description\" content=\"Step 1: Login as Administrator If you\u2019re working on a local machine, log in to the system with administrator credentials. If you\u2019re connecting to a remote machine (over a network), open a terminal window and enter the command: ssh root@server_ip_address The server_ip_address is the network IP address of the server you\u2019re logging into. Enter your [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"24x7serversupport Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-10T01:29:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-10T01:30:01+00:00\" \/>\n<meta name=\"author\" content=\"24x7support\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:site\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"24x7support\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/\",\"name\":\"How To Add User To Sudoers & Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\"},\"datePublished\":\"2021-03-10T01:29:37+00:00\",\"dateModified\":\"2021-03-10T01:30:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.24x7serversupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Add User To Sudoers &#038; Add User To Sudo Group On CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/\",\"name\":\"24x7serversupport Blog\",\"description\":\"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\",\"name\":\"24x7support\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Add User To Sudoers & Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How To Add User To Sudoers & Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog","og_description":"Step 1: Login as Administrator If you\u2019re working on a local machine, log in to the system with administrator credentials. If you\u2019re connecting to a remote machine (over a network), open a terminal window and enter the command: ssh root@server_ip_address The server_ip_address is the network IP address of the server you\u2019re logging into. Enter your [&hellip;]","og_url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/","og_site_name":"24x7serversupport Blog","article_published_time":"2021-03-10T01:29:37+00:00","article_modified_time":"2021-03-10T01:30:01+00:00","author":"24x7support","twitter_card":"summary_large_image","twitter_creator":"@24x7serversuppo","twitter_site":"@24x7serversuppo","twitter_misc":{"Written by":"24x7support","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/","url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/","name":"How To Add User To Sudoers & Add User To Sudo Group On CentOS 7 | 24x7serversupport Blog","isPartOf":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#website"},"datePublished":"2021-03-10T01:29:37+00:00","dateModified":"2021-03-10T01:30:01+00:00","author":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401"},"breadcrumb":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-add-user-to-sudoers-add-user-to-sudo-group-on-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.24x7serversupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Add User To Sudoers &#038; Add User To Sudo Group On CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.24x7serversupport.com\/blog\/#website","url":"https:\/\/www.24x7serversupport.com\/blog\/","name":"24x7serversupport Blog","description":"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401","name":"24x7support","url":"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/3305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/comments?post=3305"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/3305\/revisions"}],"predecessor-version":[{"id":3306,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/3305\/revisions\/3306"}],"wp:attachment":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/media?parent=3305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/categories?post=3305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/tags?post=3305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}