Reset Root Password Debian

28/12/2020
Chưa phân loại

How to Reset the Root Password on Debian 9 Stretch

In this article, I will show you how to configure sudo, set root password, disable root login and reset root password. This can be done even if you don’t have sudo enabled and you don’t remember the password.  Let’s get started.

Installing and Configuring sudo

If you have set up a root password while installing Debian 9 Stretch on your machine, then there’s a chance sudo won’t be configured. So you won’t be able to run any commands as root user if you’re logged in as an ordinary user.

In this section, I am going to show you how to install and configure sudo to run commands as root user without login in as user root.

First log in as root with the following command:

$ su

Now type in your root password and press <Enter>.

You should be logged in as root user.

Now update the apt package repository cache with the following command:

# apt-get update

The apt package repository cache should be updated.

Now install sudo with the following command:

# apt-get install sudo

It should be installed. In my case it is already installed.

Now to add your ordinary user, let’s say shovon to the sudoers file, run the following command:

# usermod -aG sudo shovon

NOTE: Here shovon is an ordinary user account on my Debian 9 Stretch system.

Now exit out of the root user with the following command:

# exit

Now the ordinary user shovon can run any command as root using sudo as follows:

$ sudo ls /var/log

Enter the login password of user shovon and press <Enter>.

The command should run as root as you can see from the screenshot below.

Setting Root Password

If you haven’t set a root password while installing Debian 9 Stretch, then root password by default won’t be set. But sudo should be configured for your ordinary user.

To set a root password then, run the following command:

$ sudo passwd

Now type in the password for your logged in user and press <Enter> to continue.

Now type in your desired root password and press <Enter>.

Now retype the root password and press <Enter>.

The root password should be set. Now you can login as root using your root password.

Changing Root Password

If you want to change the root password, all you have to do is run the following command again:

$ sudo passwd

Now do the same things as you did on the Setting Root Password section of this article.

Disabling Root Login

If you don’t want to allow root login, then you can lock the root account with the following command:

$ sudo passwd -l root

To allow root login again, just set a root password again. For more information, take a look at the Setting Root Password section of this article.

Recovering Lost Root Password

If you happen to forget the root password and you don’t have sudo configured, then don’t give up just yet and think about reinstalling the operating system again. There is a way to reset the root password.

First reboot your computer. You should see the GRUB menu when your computer boots as shown in the screenshot below. Select Debian GNU/Linux and press e.

You should see the following window. Now go to the end of the line as marked in the screenshot below.

Now remove ‘ro quiet’ part from the end of the line and append ‘init=/bin/bash’ to the end of the line as marked in the screenshot below. Once you’re done, press F10.

You should see the following window.

Now run the following command to remount the root (/) partition as readable and writable:

$ mount -o remount,rw /

Now run the following command to remount the /proc filesystem:

$ mount -o remount,rw /proc

Now to reset the root password, run the following command:

$ passwd

Now type in your new root password and press <Enter> to continue.

Now re-type your new root password and press <Enter> to continue.

You root password should be changed.

Now press <Ctrl> + <Alt> + <Delete> and your Debian 9 Stretch machine should reboot.

Now you can login as root with your new root password as you can see in the screenshot below.

Before Login:

After Login:

This is how you reset your root password on Debian 9 Stretch. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Faenza Icons – Change Your GNOME Theme To Have A Chromatic Look

Faenza Icons developed by Titeum, is an icon theme for Gnome that provides you with monochromatic icons for panels, toolbars...
28/12/2020

How to Set a New Hostname for your Linux System

We all know that computers over a local area network are identified by IP addressed. Instead of expecting others to remember...
Chưa phân loại
29/12/2020

Thiết lập và thay đổi MariaDB 10.4.x Root Password

Khác với những version trước đây, MariaDB 10.4 bản ổn định có thêm nhiều cải tiến. Một trong...
30/12/2020