{"id":7522,"date":"2023-02-16T14:33:55","date_gmt":"2023-02-16T14:33:55","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=7522"},"modified":"2023-02-16T14:33:55","modified_gmt":"2023-02-16T14:33:55","slug":"reset-root-password-on-linux","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2023\/02\/16\/reset-root-password-on-linux\/","title":{"rendered":"How to Reset a Root Password on Linux (Ubuntu, Debian and CentOS 7)"},"content":{"rendered":"\n<p>If you need to recover the root password or a user password in Linux, this article describes how to do the recovery in Ubuntu, Debian and CentOS Linux distributions.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Ubuntu<\/h2>\n\n\n\n<p>Restart your system. Then hold down the shift key. The system should come up with a GRUB, or boot menu, with options displayed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-23-50.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-23-50.png\" alt=\"\" class=\"wp-image-7523\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-23-50.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-23-50-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Select &#8220;Advanced Options for Ubuntu.&#8221; <\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-25-05.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-25-05.png\" alt=\"\" class=\"wp-image-7524\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-25-05.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-25-05-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Now select the the highest revision, followed by (recovery mode). Press Enter.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-29-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-29-33.png\" alt=\"\" class=\"wp-image-7525\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-29-33.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-29-33-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The system should display a menu with different boot options. Use the arrow keys to navigate to the option labeled root and press Enter.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-35-36.png\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"457\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-35-36.png\" alt=\"\" class=\"wp-image-7527\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-35-36.png 722w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_08-35-36-300x190.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The system should respond by giving you 2 options.<\/p>\n\n\n\n<p>Press Enter for Maintenance (or press Ctrl-D to continue):<\/p>\n\n\n\n<p>Press &#8220;Enter.&#8221;<\/p>\n\n\n\n<p>This will give you command-line interface with a prompt. Now, we need to remount the drive with the appropriate permissions.<\/p>\n\n\n\n<p>At the prompt, type:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmount \u2013o rw,remount \/\n<\/pre><\/div>\n\n\n<p>Press Enter. This should allow you to make changes to the data on the hard drive.<\/p>\n\n\n\n<p>Change the Password<\/p>\n\n\n\n<p>At the prompt, type:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npasswd username\n<\/pre><\/div>\n\n\n<p>Substitute the name of the user for username, then press Enter. The system asks you to type a new UNIX password and then to retype it.<\/p>\n\n\n\n<p>Once you\u2019ve entered and confirmed the new password, reboot the system by entering the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nshutdown \u2013r now\n<\/pre><\/div>\n\n\n<p>Hit Enter, and your system should restart. Let the system come up to the login screen, and test to make sure the new password works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Debian<\/h2>\n\n\n\n<p>Boot the system. You will see a menu. Press &#8220;e&#8221; on the keyboard. This will drop you into the Grub menu.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-23-02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-23-02.png\" alt=\"\" class=\"wp-image-7533\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-23-02.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-23-02-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>On the Grub editing screen, use your arrow key and move to the end of the line starting with \u201clinux\u201c. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-25-55.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-25-55.png\" alt=\"\" class=\"wp-image-7534\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-25-55.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-25-55-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>There at end of this line type, type the following:<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nrw init=\/bin\/bash\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-28-48.png\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"537\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-28-48.png\" alt=\"\" class=\"wp-image-7535\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-28-48.png 642w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-28-48-300x251.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, re-boot your system with Ctrl+X or F10.<\/p>\n\n\n\n<p>Now we will have Debian 11\u2019s shell with root access. Let\u2019s check if we have read and write access to the file system where the OS has been installed.<\/p>\n\n\n\n<p>For that use the command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmount | grep -w \/\n<\/pre><\/div>\n\n\n<p>If the output is: (rw,realtime)., then it means you have real-time- read and write access to the file system.<\/p>\n\n\n\n<p>Let\u2019s change the password as we do normally on a Linux system using the command terminal.<\/p>\n\n\n\n<p>Type:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npasswd\n<\/pre><\/div>\n\n\n<p>If a different user, type:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npasswd user\n<\/pre><\/div>\n\n\n<p>Replace &#8220;user&#8221; with the user you are changing the password for. Enter the password 2 times.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-36-41.png\"><img loading=\"lazy\" decoding=\"async\" width=\"715\" height=\"186\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-36-41.png\" alt=\"\" class=\"wp-image-7537\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-36-41.png 715w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_09-36-41-300x78.png 300w\" sizes=\"auto, (max-width: 715px) 100vw, 715px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Once you are done resetting your Linux password then restart your system to log in with the changed password. For rebooting, type:<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nexec \/sbin\/init\n<\/pre><\/div>\n\n\n<p>Hit &#8220;Enter.&#8221;<\/p>\n\n\n\n<p>The password should be changed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CentOS<\/h2>\n\n\n\n<p>Power on your CentOS 8 system. Select the kernel you want to boot into. Next, press \u2018e\u2019 on the keyboard to interrupt the boot process and make changes.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-33-56.png\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"457\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-33-56.png\" alt=\"\" class=\"wp-image-7542\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-33-56.png 722w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-33-56-300x190.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Locate the ro (read-only) kernel parameter as highlighted below.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-49-19.png\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"457\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-49-19.png\" alt=\"\" class=\"wp-image-7544\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-49-19.png 722w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-49-19-300x190.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Scroll down till you find the line starting with &#8220;linux16.&#8221; Here change the &#8220;ro with rw init=\/sysroot\/bin\/sh.&#8221;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-51-19.png\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"457\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-51-19.png\" alt=\"\" class=\"wp-image-7545\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-51-19.png 722w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-51-19-300x190.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>To access the system, enter the following command:<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nchroot \/sysroot\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-59-00.png\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"531\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-59-00.png\" alt=\"\" class=\"wp-image-7546\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-59-00.png 785w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-59-00-300x203.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2023\/02\/2023-02-16_10-59-00-768x520.png 768w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Reset the password by the following command:<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npasswd root\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>Update the SELinux information using this command:<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ntouch \/.autorelabel\n<\/pre><\/div>\n\n\n<p>Exit the chroot and reboot your system.<\/p>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nexit\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nreboot\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>You may see the system reboot twice. The password should be changed.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to recover the root password or a user password in Linux, this article describes how to do the recovery in Ubuntu, Debian and CentOS Linux distributions.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,117],"tags":[],"class_list":["post-7522","post","type-post","status-publish","format-standard","hentry","category-administration","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=7522"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/7522\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=7522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=7522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=7522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}