{"id":4438,"date":"2022-05-11T14:01:15","date_gmt":"2022-05-11T19:01:15","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=4438"},"modified":"2022-05-11T14:01:15","modified_gmt":"2022-05-11T19:01:15","slug":"bob-lost-sudo-access-on-fedora","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/bob-lost-sudo-access-on-fedora\/","title":{"rendered":"Bob lost sudo access on Fedora"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bob has a computer running Fedora.  When he installed Fedora he didn&#8217;t setup the root password and locked the root account.  That is best practice.  Right?  Then one day he goes to upgrade to the latest version of Fedora and types in <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo dnf update<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and is greeted with <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"124\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4.png\" alt=\"\" class=\"wp-image-4442\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4.png 785w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4-300x47.png 300w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4-768x121.png 768w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-4-500x79.png 500w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><\/a><figcaption>sudoers.  This incident will be reported.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">What happened?  I had access before?  Bob thinks to himself.  Seems like I am not in the wheel group anymore.  Bob being a smart person decides to attempt recovery mode.  He&#8217;ll boot up and just readd his user to the wheel group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Recovery mode starts up and then fails due to the root account being locked.  What?!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bob then starts talking to himself as he is in need of some expert advice.  What other options do I have.  I know!  He runs to find his handy dandy Live Fedora pen drive.  Plugs it in and boots up into a live version of Fedora.  Now I can mount and access the main drive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But wait, I can&#8217;t run &#8220;usermod -G wheel bob&#8221; because that will only affect the Live System.  I could chroot into the drive.  That would require mounting some extra mount points.  Is there a faster way?  We could maybe edit the \/etc\/group and add &#8220;wheel:x:10:bob&#8221;.  That should add bob back to the wheel group.  Right?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wait, what about the sudoers file.  We are normally supposed to use &#8220;sudo visudo&#8221; command to modify the file.  Let&#8217;s check the file and see if we can just manually edit it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ stat -c \"%n %a\" \/etc\/sudoers\n\/etc\/sudoers 440\n$<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"763\" height=\"113\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-3.png\" alt=\"\" class=\"wp-image-4440\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-3.png 763w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-3-300x44.png 300w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2022\/05\/image-3-500x74.png 500w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><figcaption>Permissions on \/etc\/sudoers file<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Hmm, okay I am going to need to change permissions to save the file.  Let&#8217;s chmod that to 644 temporarily <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo chmod 644 \/etc\/sudoers <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Alright now I should be able to edit it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo vi \/etc\/sudoers<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, now I need to explicitly give myself permission to use sudo.  Where is that line. Ah-ha!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root \u00a0\u00a0\u00a0ALL=(ALL) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALL<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lets duplicate that with yy and p, replace root with my username.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root \u00a0\u00a0\u00a0ALL=(ALL) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALL\n<strong>bob \u00a0\u00a0\u00a0\u00a0ALL=(ALL) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALL<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save that with esc then :wq enter<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now change the file permissions back<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chmod 400 \/etc\/sudoers<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reboot the system and now lets login and test sudo.  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo whoami \nroot<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Success!  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bob, satisfied that the problem is resolved, rewards himself by getting a sandwich.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo make me a sandwich<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.fedoraproject.org\/en-US\/quick-docs\/root-account-locked\/\">https:\/\/docs.fedoraproject.org\/en-US\/quick-docs\/root-account-locked\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bob has a computer running Fedora. When he installed Fedora he didn&#8217;t setup the root password and locked the root account. That is best practice. Right? Then one day he goes to upgrade to the latest version of Fedora and &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/bob-lost-sudo-access-on-fedora\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[19,535],"class_list":["post-4438","post","type-post","status-publish","format-standard","hentry","category-command-line","category-linux","tag-fedora","tag-sudo"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=4438"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4438\/revisions"}],"predecessor-version":[{"id":4444,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4438\/revisions\/4444"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=4438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=4438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=4438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}