{"id":19638,"date":"2023-06-15T04:37:03","date_gmt":"2023-06-15T04:37:03","guid":{"rendered":"https:\/\/linuxways.net\/?p=19638"},"modified":"2023-06-15T04:37:03","modified_gmt":"2023-06-15T04:37:03","slug":"sudo-command-on-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/sudo-command-on-linux\/","title":{"rendered":"sudo command on Linux"},"content":{"rendered":"<p>The mastery of Linux has become not just a skill but a necessity for IT professionals, developers, and even the savvy user. Among the numerous commands and tools at your disposal in Linux, there is one command that rules in its utility and power \u2013 the &#8216;sudo&#8217; command.<\/p>\n<p>However, are you aware of its capabilities? No worries, this article will be your roadmap, enlightening you about what the <strong>sudo<\/strong> command is, why it&#8217;s such a crucial part of the Linux ecosystem, and how you, as a Linux user, can wield this power responsibly and effectively.<\/p>\n<h2><strong>What is sudo Command on Linux?<\/strong><\/h2>\n<p>If you have tried your hand with Linux, you might have stumbled upon the term &#8216;sudo.&#8217; Sudo stands for &#8220;SuperUser Do,&#8221; and it&#8217;s like having superpowers in the Linux world. Consider yourself as a superhero; with sudo, you can break the chains that restrict ordinary users and unleash the full potential of your Linux system.<\/p>\n<p>In other words, we can say that with <strong>sudo<\/strong>, you can run commands and access files that normally only the root user can. All that&#8217;s needed is to type &#8216;<strong>sudo<\/strong>&#8216; before the command you intend to run.<\/p>\n<p>It allows an authorized user to carry out a command as the superuser or as a different user. It\u2019s vital for security because it limits the damage that can happen if things go out of order.<\/p>\n<h3><strong>The sudo command syntax<\/strong><\/h3>\n<p>The basic syntax of <strong>sudo<\/strong> is quite simple:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"br0\">&#91;<\/span>OPTION<span class=\"br0\">&#93;<\/span> COMMAND <span class=\"br0\">&#91;<\/span>ARGUMENTS...<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>Here, <strong>[OPTION]<\/strong> lets you customize how <strong>sudo<\/strong> behaves, <strong>COMMAND<\/strong> is what you want to execute, and <strong>[ARGUMENTS&#8230;]<\/strong> is where you can pass additional inputs to the command.<\/p>\n<h2><strong>Common sudo command options<\/strong><\/h2>\n<p>sudo comes packed with a treasure of possibilities. It is a utility that can be used for nearly every scenario. Check out some of these options below.<\/p>\n<h3><strong>1: Simulate Initial Login with -i<\/strong><\/h3>\n<p>Want to experience what it is like logging in as another user, complete with their environment settings? Reach for the <strong>-i<\/strong> option.<\/p>\n<p>By typing <strong>sudo -i -u &lt;username&gt;<\/strong>, you will start a shell as if you initially logged in as that user.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"98\" class=\"wp-image-19639\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-1.png 722w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-1-300x41.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/p>\n<h3><strong>2: Retain Certain Environment Variables with -E<\/strong><\/h3>\n<p>Have some environment variables that you prefer not to leave behind? The <strong>-E<\/strong> option is your trusty route. By using <strong>sudo -E &lt;command&gt;<\/strong>, you will execute the command while retaining your user\u2019s environment variables.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"90\" class=\"wp-image-19640\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-2.png 721w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-2-300x37.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/p>\n<h3><strong>3: Run Shell Commands with -s<\/strong><\/h3>\n<p>The <strong>-s<\/strong> option is for those times when you need to execute a shell command. Use <strong>sudo -s &lt;command&gt;<\/strong> to invoke a shell and execute the command. This option is handy when a command needs to be run in a particular shell.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"63\" class=\"wp-image-19641\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-3.png 721w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-3-300x26.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/p>\n<h3><strong>4: Prompt for Password with -k and -K<\/strong><\/h3>\n<p>When you use <strong>sudo -k<\/strong>, it resets the timestamp, prompting for the password the next time sudo is run. On the other hand, <strong>sudo -K<\/strong> ensures that you will have to enter your password every single time you use sudo.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"24\" class=\"wp-image-19642\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-4.png 716w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-4-300x10.png 300w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/p>\n<h2><strong>Configuring and usage of Sudo<\/strong><\/h2>\n<h3><strong>1: The \/etc\/sudoers File<\/strong><\/h3>\n<p>Dive into the mysterious depths of the <strong>\/etc\/sudoers<\/strong> file! This file is like the control room for sudo. You define who gets the superpowers and what they can do with them.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"18\" class=\"wp-image-19643\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-5.png 705w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-5-300x8.png 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/p>\n<h3><strong>2: Setting Permissions<\/strong><\/h3>\n<p>You don\u2019t want everyone to run amok with superpowers, right? That\u2019s where permissions come in. With a simple command like <strong>usermod. -aG sudo username<\/strong>, you grant the user access to the mighty sudo.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"56\" class=\"wp-image-19644\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-6.png 713w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-6-300x24.png 300w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/p>\n<h3><strong>3: Executing Commands<\/strong><\/h3>\n<p>So, you have got superpowers. What now? For starters, type <strong>sudo<\/strong> followed by the command you want to execute with superuser privileges. It\u2019s like adding a cape to your command!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"116\" class=\"wp-image-19645\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-7.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19638-7-300x47.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Sudo is an invaluable tool for Linux users. It&#8217;s your key to unlocking the true potential of your system while keeping it secure. Using &#8216;sudo&#8217;, you are able to execute actions that are not accessible to regular users. However, remember that it\u2019s not only about having the power but knowing when and how to use it effectively that matters.<\/p>","protected":false},"excerpt":{"rendered":"<p>sudo stands for &#8220;SuperUser Do.&#8221; You can run commands and access files that normally only the root user can. Just type sudo before the command you want to run.<\/p>","protected":false},"author":110,"featured_media":19646,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-19638","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=19638"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19638\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/19646"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=19638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=19638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=19638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}