{"id":158,"date":"2024-06-20T15:12:09","date_gmt":"2024-06-20T08:12:09","guid":{"rendered":"http:\/\/nitirat.ddns.net\/wordpress\/?p=158"},"modified":"2024-07-15T13:45:29","modified_gmt":"2024-07-15T06:45:29","slug":"how-to-add-user-to-sudoers-or-sudo-group-on-ubuntu","status":"publish","type":"post","link":"http:\/\/nitirat.ddns.net\/wordpress\/?p=158","title":{"rendered":"How to Add User to Sudoers or Sudo Group on Ubuntu"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\" id=\"ftoc-heading-2\">Step 1: Create a New User<\/h3>\n\n\n\n<p>To create a new user:<\/p>\n\n\n\n<p>1. Use the&nbsp;<a href=\"https:\/\/phoenixnap.com\/kb\/linux-adduser\" target=\"_blank\" rel=\"noreferrer noopener\">adduser<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo adduser &#91;name-of-user]<\/code><\/pre>\n\n\n\n<p>For instance, create a user called&nbsp;<em>user1<\/em>&nbsp;with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo adduser user1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/sudo-adduser-user1-terminal-output.png\" alt=\"sudo adduser user1 terminal output\" class=\"wp-image-176584\"\/><\/figure>\n\n\n\n<p>The&nbsp;<strong><code>adduser<\/code><\/strong>&nbsp;command creates a new user with a group and&nbsp;<em>Home<\/em>&nbsp;<a href=\"https:\/\/phoenixnap.com\/glossary\/what-is-a-directory\" target=\"_blank\" rel=\"noreferrer noopener\">directory<\/a>&nbsp;for that user.<\/p>\n\n\n\n<p>2. The system prompts for a password. Enter a&nbsp;<a href=\"https:\/\/phoenixnap.com\/blog\/strong-great-password-ideas\" target=\"_blank\" rel=\"noreferrer noopener\">secure password<\/a>, then retype it to confirm.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/add-password.png\" alt=\"add password\" class=\"wp-image-176590\"\/><\/figure>\n\n\n\n<p>3. The system asks for additional information about the user, including name, phone numbers, etc. These fields are optional and can be skipped by pressing&nbsp;<strong>Enter<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/enter-additional-info.png\" alt=\"enter additional info\" class=\"wp-image-176591\"\/><\/figure>\n\n\n\n<p>4. Type y to confirm the information and complete the settings for the new user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ftoc-heading-3\">Step 2: Add User to Sudoers File or Sudo Group<\/h3>\n\n\n\n<p>The&nbsp;<em>sudoers<\/em>&nbsp;file and the sudo group are related to granting users administrative privileges via the&nbsp;<strong><code>sudo<\/code><\/strong>&nbsp;command.<\/p>\n\n\n\n<p><em>\/etc\/sudoers<\/em>&nbsp;is a configuration file that specifies which users or groups can use&nbsp;<strong><code>sudo<\/code><\/strong>&nbsp;for administrative tasks. It defines permissions, such as command execution and password requirements.<\/p>\n\n\n\n<p>On the other hand, the sudo group is created specifically to manage sudo privileges. Users added to this group gain sudo access to run commands with elevated permissions using&nbsp;<strong><code>sudo<\/code><\/strong>.<\/p>\n\n\n\n<p>To grant users sudo permission without editing the&nbsp;<em>sudoers<\/em>&nbsp;file, add them to the sudo group with the&nbsp;<a href=\"https:\/\/phoenixnap.com\/kb\/usermod-linux\" target=\"_blank\" rel=\"noreferrer noopener\">usermod<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG sudo &#91;name-of-user]<\/code><\/pre>\n\n\n\n<p>For example, grant&nbsp;<em>user1<\/em>&nbsp;sudo privileges with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG sudo user1<\/code><\/pre>\n\n\n\n<p>The command has no output, but the&nbsp;<strong><code>-aG<\/code><\/strong>&nbsp;option tells the system to append the user to the specified group.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ftoc-heading-4\">Step 3: Verify User Belongs to Sudo Group<\/h3>\n\n\n\n<p>To confirm&nbsp;<em>user1<\/em>&nbsp;belongs to the sudoers group, view the groups the user belongs to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>groups user1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/groups-user1-terminal-output.png\" alt=\"groups user1 terminal output\" class=\"wp-image-176593\"\/><\/figure>\n\n\n\n<p>The system responds by listing the username and all groups it belongs to.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ftoc-heading-5\">Step 4: Verify Sudo Access<\/h3>\n\n\n\n<p>To verify sudo access, take the following steps:<\/p>\n\n\n\n<p>1. Switch users with the&nbsp;<a href=\"https:\/\/phoenixnap.com\/kb\/su-command-linux-examples\" target=\"_blank\" rel=\"noreferrer noopener\">su command<\/a>. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>su - user1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/su-user1-terminal-output.png\" alt=\"su user1 terminal output\" class=\"wp-image-176599\"\/><\/figure>\n\n\n\n<p>Enter the password when prompted.<\/p>\n\n\n\n<p>2. Run a command that requires elevated privileges. For instance, list the&nbsp;<em>\/root<\/em>&nbsp;directory contents using the&nbsp;<strong><code>ls<\/code><\/strong>&nbsp;command with&nbsp;<strong><code>sudo<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ls \/root<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/phoenixnap.com\/kb\/wp-content\/uploads\/2024\/04\/sudo-ls-root-terminal-output.png\" alt=\"sudo ls \/root terminal output\" class=\"wp-image-176600\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Create a New User To create a new user: 1. Use the&nbsp;adduser&nbsp;command: For instance, create a user called&nbsp;user1&nbsp;with: The&nbsp;adduser&nbsp;command creates a new user with a group and&nbsp;Home&nbsp;directory&nbsp;for that user. 2. The system prompts for a password. Enter a&nbsp;secure password, then retype it to confirm. 3. The system asks for additional information about the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":119,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[6],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":1,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/119"}],"wp:attachment":[{"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nitirat.ddns.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}