{"id":1133,"date":"2018-08-29T11:18:34","date_gmt":"2018-08-29T05:48:34","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=1133"},"modified":"2019-04-09T16:20:45","modified_gmt":"2019-04-09T10:50:45","slug":"create-a-sudo-user-on-centos-7","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/","title":{"rendered":"Create a sudo user in centOS 7 server"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#Create_a_sudo_user_in_centOS_7_server\" >Create a sudo user in centOS 7 server<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#Steps_to_Create_a_New_Sudo_User_on_CentOS_7\" >Steps to Create a New Sudo User on CentOS 7<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#1_Connect_via_SSH\" >1. Connect via SSH<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#2_Add_New_User_in_CentOS\" >2. Add New User in CentOS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#3_Create_a_Strong_Password\" >3. Create a Strong Password<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#4_Add_User_to_the_Wheel_Group_in_CentOS\" >4. Add User to the Wheel Group in CentOS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/create-a-sudo-user-on-centos-7\/#5_Switch_to_the_sudo_User\" >5. Switch to the sudo User<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Create_a_sudo_user_in_centOS_7_server\"><\/span><span style=\"text-decoration: underline;\">Create a sudo user in centOS 7 server<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Sudo is a Linux command line program that allows you to execute commands as superuser or another system user. The configuration file offers detailed access permissions, including enabling commands only from the invoking terminal; requiring a password per user or group; requiring re-entry of a password every time or never requiring a password at all for a particular command line.<\/p>\n<p>And sudo were designed to run commands only as the superuser.<\/p>\n<p>It can also be configured to permit passing arguments or multiple commands.<\/p>\n<p>Here in this tutorial we will show you how to create a sudo user on CentOS 7.<\/p>\n<h2 id=\"steps-to-create-a-new-sudo-user\"><span class=\"ez-toc-section\" id=\"Steps_to_Create_a_New_Sudo_User_on_CentOS_7\"><\/span>Steps to Create a New Sudo User on CentOS 7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"1_Connect_via_SSH\"><\/span>1. Connect via SSH<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>First connect to your server via SSH. Once you are logged in, you need to add a new system user.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Add_New_User_in_CentOS\"><\/span>2. Add New User in CentOS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can add a new system user using the following command:<\/p>\n<pre># adduser newuser<\/pre>\n<p>You need to replace <em>new user<\/em> with the name of the user you want to add. Also, you need to set up a password for the newly added user.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Create_a_Strong_Password\"><\/span>3. Create a Strong Password<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To set up a password you can use the following command:<\/p>\n<pre># passwd newuser<\/pre>\n<p>Make sure you are using a\u00a0<em>strong password<\/em>, otherwise the password will fail against the dictionary check. You will be asked to enter the password again and once you enter it you will be notified that the authentication tokens are updated successfully:<\/p>\n<pre># passwd newuser\r\nChanging password for user newuser.\r\nNew password:\r\nRetype new password:\r\npasswd: all authentication tokens updated successfully.\r\n<\/pre>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1302\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/sudo-user.png\" alt=\"sudo\" width=\"664\" height=\"414\" srcset=\"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/sudo-user.png 664w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/sudo-user-300x187.png 300w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/sudo-user-96x60.png 96w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/h3>\n<h3><\/h3>\n<h3><span class=\"ez-toc-section\" id=\"4_Add_User_to_the_Wheel_Group_in_CentOS\"><\/span>4. Add User to the Wheel Group in CentOS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The wheel group is a special user group that allows all members in the group to run all commands.And this sepcial user group control accerss to su or sudo command which allows a user to act as another user.<\/p>\n<p>Therefore, you need to add the new user to this group so it can run commands as superuser using the following command:<\/p>\n<pre># usermod -aG wheel newuser<\/pre>\n<p>Again, make sure you are using the name of the actual user instead of newuser<br \/>\nNow, use visudo or nano to open and edit the\u00a0\/etc\/sudoers\u00a0file. Make sure that the line that starts with %wheel is not commented. It should look exactly like this:<\/p>\n<pre>## Allows people in group wheel to run all commands\r\n%wheel  ALL=(ALL)       ALL\r\n<\/pre>\n<p>Now that your new user is set up you can switch to that user and test if everything is OK.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Switch_to_the_sudo_User\"><\/span>5. Switch to the sudo User<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To switch to the new user, run the following command:<\/p>\n<pre># su - newuser\r\n<\/pre>\n<p>Now run a command that usually doesn\u2019t work for regular users like the one below:<\/p>\n<pre>$ ls -la \/root\/<\/pre>\n<p>You will get the following error message:<\/p>\n<pre>ls: cannot open directory \/root\/: Permission denied<\/pre>\n<p>Try to run the same command, now with using sudo<\/p>\n<pre>$ sudo ls -ls \/root\/<\/pre>\n<p>You will need to enter the password for the new user to proceed. If everything is OK, the command will list all the content in the \/root directory. Another way to test this is to run the following command:<\/p>\n<pre>$ sudo whoami<\/pre>\n<p>The output of the command should be similar to the one below:<\/p>\n<pre>$ sudo whoami\r\nroot<\/pre>\n<p>That is it follow the all above steps.<\/p>\n<p>Now you have a sudo user which you can use to manage your CentOS 7, operating system.<\/p>\n<p>And to know more about disabling direct SSH Root Login and Permitting through \u201csu\u201d user <a href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/disabling-direct-ssh-root-login-and-permitting-through-su-user-in-linux\/\">click here.<\/a><\/p>\n<p>To get the dedicated server <a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-in-india\/\" rel=\"nofollow noopener\" target=\"_blank\">goto.<\/a><\/p>\n<p>If you satisfy the above post share you comments that help us to improve better.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a sudo user in centOS 7 server Sudo is a Linux command line program that allows you to execute commands as superuser or another system user. The configuration file offers detailed access permissions, including enabling commands only from the invoking terminal; requiring a password per user or group; requiring [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1141,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[153],"tags":[114,115],"class_list":["post-1133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7-rhel-7","tag-new-sudo","tag-wheel-group"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/linux-wallpaper-computers-centos.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-ih","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1133"}],"version-history":[{"count":1,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1133\/revisions"}],"predecessor-version":[{"id":1946,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1133\/revisions\/1946"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1141"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}