{"id":27,"date":"2026-08-05T18:43:24","date_gmt":"2026-08-05T16:43:24","guid":{"rendered":"https:\/\/www.gowrishankar.me\/blog\/?p=27"},"modified":"2026-08-05T18:43:24","modified_gmt":"2026-08-05T16:43:24","slug":"linux-commands-difference-between-sudo-s-and-sudo-i","status":"publish","type":"post","link":"https:\/\/www.gowrishankar.me\/blog\/2026\/08\/05\/linux-commands-difference-between-sudo-s-and-sudo-i\/","title":{"rendered":"Linux Commands: The Difference Between sudo -s and sudo -i"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Both commands drop you into a root shell, but they set up that shell very differently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>sudo -s<\/code><\/strong> starts a shell as root, but keeps most of your original environment. It doesn&#8217;t change your working directory, doesn&#8217;t read root&#8217;s login files (<code>.bash_profile<\/code>, <code>.profile<\/code>), and often leaves <code>$HOME<\/code> pointing at your own home directory rather than <code>\/root<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -s\npwd        # unchanged\necho $HOME # often still \/home\/youruser<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>sudo -i<\/code><\/strong> simulates a full login as root. It sets <code>HOME<\/code>, <code>USER<\/code>, <code>LOGNAME<\/code>, and <code>PATH<\/code> to root&#8217;s values, drops you into <code>\/root<\/code>, and sources root&#8217;s login files as a proper login shell.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -i\npwd        # \/root\necho $HOME # \/root<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Rule of thumb:<\/strong> think of <code>sudo -s<\/code> like <code>su<\/code>, and <code>sudo -i<\/code> like <code>su -<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Use <code>sudo -i<\/code> when you want a clean, authentic root environment for installing packages, editing system configs, running scripts that expect <code>$HOME<\/code> to be <code>\/root<\/code>. <br><br>Use <code>sudo -s<\/code> when you want root privileges without disturbing your current directory or environment. And whenever possible, skip the interactive shell entirely and just run <code>sudo &lt;command><\/code> \u2014 it's easier to audit and limits the blast radius of mistakes.<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Neither command changes what you&#8217;re authorized to do; that&#8217;s controlled by <code>\/etc\/sudoers<\/code>. The difference is purely about environment setup, not security level.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Both commands drop you into a root shell, but they set up that shell very differently. sudo -s starts a shell as root, but keeps most of your original environment. It doesn&#8217;t change your working directory, doesn&#8217;t read root&#8217;s login files (.bash_profile, .profile), and often leaves $HOME pointing at your own home directory rather than [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":33,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[8,4,9,6],"class_list":["post-27","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-system-administration","tag-command-line","tag-linux","tag-sudo","tag-sysadmin"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.gowrishankar.me\/blog\/wp-content\/uploads\/2026\/08\/Linux-Commands-Difference-Between-sudo-s-and-sudo-i.png?fit=2500%2C1312&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":5,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":32,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions\/32"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/media\/33"}],"wp:attachment":[{"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gowrishankar.me\/blog\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}