Linux forgot user password

Как сбросить пароль в Linux


Давайте рассмотрим несколько способов сбрасывания системного пароля в Linux. Вы наверное знаете, что у пользователя root есть права на изменение пароля любого пользователя в системе. А что если вы забыли пароль от рута? Вот об этом и пойдет речь в статье.

При восстановления пароля (рута или любого другого пользователя) встречаются две различные ситуации, требующие разного подхода.

Когда можно использовать GRUB

    После этого вы либо увидите приглашение для рута, либо восстанавливающее меню, где нужно выбрать строку с рутом. Используйте passwd для того чтобы изменить пароль у любого пользователя

  • Выполните команду reboot для перезагрузки системы и затем авторизуйтесь с новым паролем
  • Также следует заметить что некоторые дистрибутивы создают режим восстановления во время установки. Если в вашем меню GRUB есть такой пункт, вам не нужно производить все вышеперечисленные действия, просто выберите режим восстановления, а затем приглашение для рута, в последующем диалоговом окне.

    Когда нет возможности использовать GRUB

    Если вы не используете GRUB по каким-то причинам, вы можете восстановить пароль с помощью live CD (Я буду использовать Ubuntu live CD, вы можете взять любой другой). Просто следуйте дальнейшим инструкциям:

    • Загрузитесь с live CD
    • Выберите «Попробовать Ubuntu без изменений на вашем компьютере» (Try Ubuntu without any changes to your computer)

  • Когда система будет готова, запустите окно терминала и приготовьтесь к выполнению некоторых действий в командной строке
  • Напечатайте в окне терминала sudo fdisk -l. В результате мы узнаем, в какой раздел диска установлен линукс и непосредственно имя самого жесткого диска, в представленном примере нужный нам раздел называется /dev/sda1 . Если вы точно знаете нужный раздел, этот шаг можно пропустить.

    Далее нам нужно монтировать линукс-раздел. Для этого создайте папку, в качестве точки для монтирования, используя команду: sudo mkdir /media/linx_part

    Примонтируйте линукс-раздел командой sudo mount /dev/sda1 /media/linx_part

  • Измените рута в примонтированном разделе — sudo chroot /media/sda1
  • Используйте passwd для изменения текущего пароля на новый

    Источник

    Ethical hacking and penetration testing

    InfoSec, IT, Kali Linux, BlackArch

    How to reset a forgotten login password in Linux

    If you cannot log in to the Linux system because you forgot your user account password, it is possible to solve the problem! Although this password cannot be recovered (by simple methods), but it can be reset and replaced with a new one, this guide will tell you what to do if forgot the user’s password in Linux.

    How to change a Linux user password

    Any users from the group of administrators (whose account is in the group wheel) can change the password for any other user, both for unprivileged accounts, and for other administrators, including root. Therefore, if you forgot the root password, but remember the password of the user who has the right to execute commands with sudo, then the password can be restored with the passwd command. To change the root password, run:

    To change the password of any user:

    Where instead of username you need to substitute the name of the Linux user account.

    What to do if forgot Linux login password

    If you do not have other administrative accounts and if you forgot the Linux account password, you cannot enter the operating system, then to reset the password we need a single-user mode.

    In single-user mode, credentials are not asked (login, password), while the logged user has superuser permissions. In this mode, using the familiar passwd command, it is possible to set a new password.

    The algorithm in all Linux distributions is similar:

    1. Interrupting the GRUB boot loader
    2. Add the boot option that enable single-user mode
    3. Resume booting
    4. Change password with passwd command
    5. Restart in normal mode

    Note that the changes made in the second step (changing the download options) are temporary — they affect only one subsequent booting. Therefore, when you reboot at the fifth step, you do not need to do anything — the system will operate in normal mode.

    To move to the end of the line and to the beginning of the line (in the second step), use the keyboard shortcuts Ctrl+a and Ctrl+e.

    Although the root password reset algorithm is similar, but there may be some nuances in different distributions, let us take a closer look at them.

    Note for UEFI: If you use UEFI instead of GRUB, then also see this article, it tells you how to change kernel boot parameters in this case.

    By the way: if you want to protect the system from changing the password as described in this article, see the article “How to protect GRUB bootloader with password”.

    Resetting the password in Linux Mint, Ubuntu, Debian, Kali Linux (should also work for other Debian derivatives)

    To interrupt the loading of GRUB (the first step) during startup of the computer, press and hold the SHIFT key — it works always, even on Linux Mint, where by default the GRUB menu display is disabled.

    Stop the booting by holding the SHIFT key while starting the computer, you will see:

    Press the «e» key and you will proceed to edit the boot settings:

    On the screen there is no necessary line for us, swipe the cursor keys down and find the line starting with linux:

    Go to the end of this line, type a space and add:

    It should look something like this (the kernel number may differ):

    When everything is ready, press Ctrl+x or F10 to continue booting with the set options.

    You will see a shell prompt, also note that we are logged in as root, i.e. we have superuser privileges, including the use of the passwd command:

    With the passwd command we change the password, as you can see, the passwd command failed:

    To understand the cause of the error, enter the command:

    The letters ro indicate that the file system is mounted read-only and for this reason the made changes cannot be saved. Let us remount the file system:

    As you can see, after that the password change was successful:

    To turn off your computer run:

    Or restart your computer with the command:

    How to reset the password in Arch Linux, BlackArch (and also in other Arch Linux derivatives)

    When the GRUB menu appears, press the «a» key to stop the booting:

    Then press «e» to edit the boot parameters:

    On the screen there is no interesting line for us, swipe the cursor keys down and find the line starting with linux.

    Go to the end of this line, type a space and add:

    It should look something like this:

    When everything is ready, press Ctrl+x or F10 to continue booting with the set options.

    In Arch Linux, the file system is mounted with write permissions by default. Therefore, you can immediately change the password using the command

    To turn off your computer run:

    Or restart your computer with the command:

    Reset your password in RHEL/CentOS 7

    In addition to having to mount a file system for save changes, RHEL/CentOS 7 also has a nuance related to the presence of SELinux.

    When the GRUB menu appears, press the «a» key to stop the booting:

    Then press «e» to edit the boot parameters:

    On the screen is missing the line we need, swipe the cursor keys down and find the line starting with linux16:

    Find the part of the string

    and replace with

    It should look something like this:

    When everything is ready, press Ctrl+x or F10 to continue booting with the set options.

    Let us check write permissions:

    As you can see, there are no write permissions. We will remount the file system with write permissions:

    The password has been changed, but it is not over yet. We need to relabel the SELinux context. If we do not relabel the whole SELinux context, we will not be able to use the new password. To do that:

    To turn off your computer run:

    Or restart your computer with the command:

    In GRUB 2 one cannot change the password in single user mode?

    In Red Hat official documentation, I found the statement that GRUB 2 no longer performs password reset in single-user mode, as it was in GRUB. And now for the operation in single-user mode, as well as in emergency mode, the root password is required. Perhaps this applies only to the latest versions of Red Hat Enterprise Linux, because, as you can see from this instruction and screenshots, in GRUB 2 you can change the password in single-user mode. The documentation describes two ways to reset the root password in Red Hat Enterprise Linux in case the described here method does not work.

    Источник

    How to Reset Ubuntu Password in 2 Minutes

    Last updated August 4, 2020 By Abhishek Prakash 375 Comments

    Brief: If you forgot your user password on Ubuntu, don’t worry. You can reset an Ubuntu password very easily. This guide explains an easy method for changing the root password on Ubuntu. The method should also be applicable to other Linux distributions.

    Forgot your Ubuntu login password? It happens.

    If you haven’t used Ubuntu for some time, it’s only natural to not remember the password. The good news is that you don’t need to reinstall the entire operating system because of it. You can recover Ubuntu passwords easily.

    The method mentioned here works for resetting an Ubuntu password in VMware, dual boot or single install. All you need is a little bit of patience and to run a couple of commands. You’ll reset the root password within minutes.

    Using Linux on WSL?

    It’s a bit different for WSL. You may follow the steps for resetting Linux password in WSL here.

    Reset Ubuntu password from recovery mode

    If you prefer watching videos to reading text, I’ve also made a video of this tutorial. Don’t forget to subscribe to our YouTube channel for more Linux tutorial videos.

    Step 1: Boot into recovery mode

    Switch the computer on. Go to the grub menu. Generally, it appears automatically – if not, then hold down the shift key or press Esc key until the boot menu appears.

    If you’re using Oracle VirtualBox or VMware, you have to hold down the shift key when the logo of Oracle or VMware appears.

    In the grub menu, select the “Advanced Options for Ubuntu”:

    In here, you’ll see the option to go to recovery mode:

    It will bring you to a black screen with several lines of output being displayed in a flash. Wait for a few seconds here.

    Step 2: Drop to root shell prompt

    Now you’ll be presented with different options for recovery mode. Here you need to choose “Root – Drop to root shell prompt“. Just press the enter key to select this option. Like in the picture below:

    You’ll see that when you select the root shell prompt option, an option to enter commands appears at the bottom. This is your root shell prompt and this is where you’ll use the commands to reset the password.

    Step 3: Remount the root with write access

    You need to have write access to the root partition. By default, it has read-only access.

    Use the command below to remount it with write access:

    Step 4: Reset username or password

    Here, you’ll be given root access. Use the following command to list all the users available:

    Based on this command, choose the “username” for which you want to reset or (say) hack the password. Now, use the following command to reset the password for the selected “username“:

    It prompts for a new password. Enter the new password twice:

    Voilà! There you go. You have just successfully reset the password. Now exit the root shell prompt:

    When you exit, you’ll be back at the recovery mode menu. Select the normal boot option here.

    There will be a warning about graphics mode compatibility. Don’t worry. A complete reboot will fix any issues with this.

    You should now be able to log in with the new password.

    Possible Troubleshoot:

    While entering the new password you might be prompted with Authentication token manipulation error like this:

    The reason for this error is that the file system is mounted with read access only. Change the access and remount the file system in the following manner:

    Now try to reset the password again. It should work now.

    As you can see, it is extremely easy to change Ubuntu password even if you’ve forgotten it. It will barely take a few minutes.

    Alternate method to reset Ubuntu pasword

    If for some reason you have difficulty dropping to the root shell and changing the password, you can try these steps.

    Step 1

    Reboot your computer. Hold shift to bring up the grub screen (if it doesn’t appear automatically). Press E at the grub prompt to edit the grub screen.

    Step 2

    Find the line starting with linux, change the ro to rw and append init=/bin/bash at the end of that line.

    Change ro to rw and add init=/bin/bash at the end of this line

    Step 3

    Press ctrl-x to save your changes and boot.

    Now you are booting into the Linux kernel with read and write permissions, and instead of going to a graphical user interface, you’ll use the bash shell.

    In other words, your system will boot up to a passwordless root shell.

    Step 4

    Type in the passwd command with your username. If you don’t know the username, check with ls /home command (as mentioned in method 1).

    Set your new password.

    Once you’ve set the new password, exit the terminal. Just type reboot in the terminal or use the shutdown command.

    Your password should be changed now.

    If resetting Ubuntu passwords is this easy, isn’t this a security risk?

    That’s a fair question. One of the main advantages of Linux over Windows is its security. But if “anyone” can reset the password, how come Ubuntu or other Linux distributions can be considered secure?

    Let me explain a few things here. The main security risk is if someone hacks into your account from a remote location via the internet. That’s not happening here.

    If anyone has physical access to your computer, the data in your computer is already at risk. Unless the entire disk is encrypted, anyone can “steal” your data using a live USB without even entering your installed operating system.

    By default, Ubuntu doesn’t have a root password and the root account is locked. The user account you set up while installing Ubuntu is included as an admin with sudo rights. But that doesn’t mean that you are root.

    This lack of root password is a deliberate feature The “advanced options for Ubuntu” in the boot menu allow you to perform some specific root-related tasks from the “root shell prompt”. This is why you’re able to reset the Ubuntu password through this method.

    If you want to make your system more secure, you can either encrypt the disk (to save your data) or setup a password for root user in Ubuntu.

    Bonus Tip: Handling the possible keyring issue after changing password

    There is a keyring feature in Ubuntu that is used for keeping passwords locked and safe.

    When you reset the forgotten password, the keyring remains unlocked and you may see an error message like this.

    Open the Passwords and Keys application and here, delete the Login passwords.

    When you try to use Google Chrome again in Ubuntu, it will ask you to create a new keyring. Use the new login password as the keyring password.

    Did it help you?

    I hope I made things clear about resetting forgotten passwords in Ubuntu.

    Did this quick tip help you recover your admin password? Do share in the comments below.

    Like what you read? Please share it with others.

    Источник

    Читайте также:  Как линукс с флэшки
  • Оцените статью