{"id":13334,"date":"2022-03-07T06:39:50","date_gmt":"2022-03-07T05:39:50","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=13334"},"modified":"2023-08-07T03:48:56","modified_gmt":"2023-08-07T01:48:56","slug":"a-practical-guide-to-superuser-accounts-sudo-root","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/a-practical-guide-to-superuser-accounts-sudo-root\/","title":{"rendered":"A Practical Guide to Superuser Accounts, sudo &#038; root"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg\" alt=\"sudo guide cover picture\" class=\"wp-image-13335\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user-600x315.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user-768x403.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>User rights is one of the first concepts you have to understand when dealing with Linux. This guide is ideal for users who just installed their first Linux on the computer, or for users who are starting out with their first Linux server. We wrote this article in mind to help our customers as well as any other Linux newcomers. <\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-video\">Video<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container \" style=\"height: 100%;\"><iframe loading=\"lazy\" title=\"Linux Basics: Linux User Management (Root, Superuser &amp; more)\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/DY_W513qeuI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-root-user-regular-users-and-system-users\">The Root User, Regular Users and System Users<\/h2>\n\n\n\n<p>Let\u2019s start by explaining the basic admin structure in Linux. There are three basic types of users in Linux \u2013 the powerful root user, system users and regular users. Root is the super user role created to manage all other users and perform critical actions, such as deleting folders, updating system, connecting to other computers and myriad of others. Root can also assign rights on various levels to all other users.<\/p>\n\n\n\n<p>If you are logged in as \u201croot\u201d, you have the right to perform virtually any action on your Linux. Log in to your system as root is useful in certain situations when you want to perform important system changes.<\/p>\n\n\n\n<p>If your username is not \u201croot\u201d, then you\u2019re by default restricted from executing important actions. If you try to execute such command without the necessary rights, Linux will just refuse your command.<\/p>\n\n\n\n<p>Your default user in Linux depends on your installation. For example, most Contabo <a href=\"https:\/\/contabo.com\/de\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS<\/a>, <a href=\"https:\/\/contabo.com\/de\/vds\/\" target=\"_blank\" rel=\"noreferrer noopener\">VDS<\/a> or <a href=\"https:\/\/contabo.com\/en\/dedicated-servers\/\">Dedicated Servers <\/a>running Linux use \u201croot\u201d as default user.<\/p>\n\n\n\n<p>Besides regular users and the root user, there are many system users who were added by the operating system. System users are necessary for Linux to work properly on the background. This type of users are processes, not real users and you can\u2019t use the username to log in.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-are-you-the-root\">Are You the Root?<\/h2>\n\n\n\n<p>To quickly double-check if you\u2019re login in as a root or not, simply take a look at the command prompt. The first word before the at (\u201c@\u201d) sign is the name of your user. In this example it\u2019s \u201cTom\u201d:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"326\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/CLI-intro.png\" alt=\"Command line Contabo server\" class=\"wp-image-13337\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/CLI-intro.png 745w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/CLI-intro-600x263.png 600w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/figure>\n\n\n\n<p>And in this case, we\u2019re logged to the same server as a root:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/root-CLI-prompt.png\" alt=\"Logged in as &quot;root&quot; user command line\" class=\"wp-image-13340\" width=\"750\" height=\"48\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/root-CLI-prompt.png 805w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/root-CLI-prompt-600x39.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/root-CLI-prompt-768x50.png 768w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n\n\n\n<p>Alternatively, you can use this command to print the current user\u2019s username on a new line. The command is a compound of the question \u201cWho am I?\u201d in the following syntax:<br><code>whoami<\/code><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-central-user-database\">Central User Database<\/h2>\n\n\n\n<p>Linux saves information on all users in the form of a text file.<\/p>\n\n\n\n<p>The list of users is located in a file named <strong>passwd<\/strong>, in your <strong>\/etc<\/strong> folder. We will use the \u201ccat\u201d command to browse the file. The cat command is somewhat comparable to a double-click in Windows:<br><code>cat \/etc\/passwd<\/code><\/p>\n\n\n\n<p>You will see a long list of users, similar to this picture:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1036\" height=\"471\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/passwd-file.png\" alt=\"\/etc\/passwd file\" class=\"wp-image-13343\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/passwd-file.png 1036w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/passwd-file-600x273.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/passwd-file-768x349.png 768w\" sizes=\"auto, (max-width: 1036px) 100vw, 1036px\" \/><\/figure>\n\n\n\n<p>You may wonder, why there are so many users on your system unbeknown to you. That\u2019s because most of the users in this file are system users automatically created to run background processes.<br>Let\u2019s take a closer look at the format of this document. The third column of every user contains so called user ID. <\/p>\n\n\n\n<p>The user ID for root is by default <strong>0<\/strong>.<\/p>\n\n\n\n<p>Values <strong>1<\/strong> to <strong>500<\/strong> are reserved for system users.<\/p>\n\n\n\n<p>Values starting from <strong>1000<\/strong> are reserved for regular users. If Linux won\u2019t receive any other instructions, new users will be added consequently with ID numbers <strong>1000<\/strong>, <strong>1001<\/strong>, <strong>1002<\/strong>, <strong>1003<\/strong> and so forth.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-becoming-a-superuser\">Becoming a Superuser<\/h2>\n\n\n\n<p><em>Note that the commands in this guide are optimized for Debian-based distributions, such as Ubuntu or Linux Mint. In case you&#8217;re using another Linux family, such as Oracle Linux or Fedora, you have to install or modify some of the commands.<\/em><\/p>\n\n\n\n<p>To become a super user, you have to log in as \u201croot\u201d.<\/p>\n\n\n\n<p>But even if you\u2019re not currently logged in as \u201croot\u201d, you can elevate your rights temporarily. The feature to assume superuser rights is called sudo and allows you to perform the same actions as if you are the administrator.<\/p>\n\n\n\n<p>All you have to do is to type \u201csudo\u201d before the command that requires super user privileges. For instance, this command will update the system:<br><code>sudo apt-get update<\/code><\/p>\n\n\n\n<p>If you try to run this command without sudo, Linux will return the command as \u201cAccess Denied\u201d.<\/p>\n\n\n\n<p>But writing the sudo command at the beginning of each command can be repetitive. To get super user rights for the whole session, try the command:<\/p>\n\n\n\n<p><code>sudo -i<\/code><\/p>\n\n\n\n<p>There is no need to type sudo before every command anymore. Note that even your command line will change to root:<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"88\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Tom-to-root.png\" alt=\"Tom to elevate the rights to root\" class=\"wp-image-13348\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Tom-to-root.png 716w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Tom-to-root-600x74.png 600w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/figure>\n\n\n\n<p>By becoming a superuser, your ID will just change from your original value to <strong>0<\/strong>, as described in the previous section. You can check your current user ID by prompting the command:<br><code>id<\/code><\/p>\n\n\n\n<p>In this particular example, the user Tom has become a super user and his user ID changed from <strong>1001 <\/strong>to <strong>0<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"807\" height=\"220\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/ID-from-Tom-to-root-1.png\" alt=\"ID for regular users and root\" class=\"wp-image-13351\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/ID-from-Tom-to-root-1.png 807w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/ID-from-Tom-to-root-1-600x164.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/ID-from-Tom-to-root-1-768x209.png 768w\" sizes=\"auto, (max-width: 807px) 100vw, 807px\" \/><\/figure>\n\n\n\n<p>The sudo -i feature will last until you logout from your system. If you want to become a regular user again during your session, just execute the command:<br><code>exit<\/code><\/p>\n\n\n\n<p>But not every user is allowed to use sudo to elevate their privileges. In the next chapter we will discuss how to manage the superuser rights.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-managing-sudo-permissions\">Managing Sudo Permissions<\/h2>\n\n\n\n<p>Not every user is allowed to use sudo. Here\u2019s an example of a perfectly fine command that was rejected because the user is \u201c<em>not allowed to run sudo<\/em>\u201d:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1003\" height=\"127\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Cordelia-sudo-denied.png\" alt=\"Sudo is denied\" class=\"wp-image-13353\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Cordelia-sudo-denied.png 1003w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Cordelia-sudo-denied-600x76.png 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Cordelia-sudo-denied-768x97.png 768w\" sizes=\"auto, (max-width: 1003px) 100vw, 1003px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-give-users-permission-to-use-sudo\">How to Give Users Permission to Use Sudo<\/h3>\n\n\n\n<p>In order to turn on the sudo function, the respective user has to be added to a list of users who have permission to do so. Only users who already have access to using sudo can add other users to this list.<\/p>\n\n\n\n<p>Let\u2019s give \u201cCordelia\u201d the permission to use sudo by prompting:<br><code>sudo usermod -aG sudo Cordelia<\/code><\/p>\n\n\n\n<p>Now the user Cordelia can use sudo for any command.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-remove-the-permission-to-use-sudo\">How to Remove the Permission to Use Sudo<\/h3>\n\n\n\n<p>If we no longer wish to permit Cordelia to become a superuser, we can remove the access by prompting:<br><code>sudo gpasswd -d Cordelia sudo<\/code><\/p>\n\n\n\n<p>The user will remain active, but without the ability to perform actions as root<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-where-to-next\">Where to Next?<\/h2>\n\n\n\n<p>In this tutorial, you learned a few essential skills to manage the root and sudo rights. We encourage you to dig deeper and learn how to fine-tune user\u2019s rights on a <a href=\"https:\/\/linuxhint.com\/linux_file_permissions\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">more granular level<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>User rights is one of the first concepts you have to understand when dealing with Linux. This guide is ideal for users who just installed their first Linux on the computer, or for users who are starting out with their first Linux server. We wrote this article in mind to help our customers as well [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":13335,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[1481],"class_list":["post-13334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user-150x150.jpg",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user-600x315.jpg",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user-768x403.jpg",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/03\/Blog-Head_1200x630_linux-user.jpg",1200,630,false]},"uagb_author_info":{"display_name":"Petr","author_link":"https:\/\/contabo.com\/blog\/author\/petr\/"},"uagb_comment_info":0,"uagb_excerpt":"User rights is one of the first concepts you have to understand when dealing with Linux. This guide is ideal for users who just installed their first Linux on the computer, or for users who are starting out with their first Linux server. We wrote this article in mind to help our customers as well&hellip;","authors":[{"term_id":1481,"user_id":49,"is_guest":0,"slug":"petr","display_name":"Petr","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/3a3991d3f2f2e482436c374c378ac5dec17a1e02bd60ef356744005bc37a02e7?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=13334"}],"version-history":[{"count":1,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13334\/revisions"}],"predecessor-version":[{"id":17230,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13334\/revisions\/17230"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/13335"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=13334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=13334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=13334"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}