Using "chroot" to reset a password of a linux machine

本文介绍如何利用chroot技术在Linux系统中重置忘记的root密码。通过引导进入安装介质并创建临时文件系统,之后通过chroot切换根目录环境来修改密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I tried to explain what "chrooting" is to a group of starting Linux gurus. It seemed rather difficult to explain. So, maybe an illustrated article will explain what chroot is.

From chroot's manpage:

chroot - run command or interactive shell with special root directory

And in my own words:

chroot starts a process in a directory which looks like the root directory to that process.

Here is an example of how chroot can be used to reset a root password on an existing system. (Even works when the bootloader (grub) has a password set.)

  1. Insert a linux boot or install CD/DVD and make the computer boot from that cd.
  2. When the CD boots and starts the installer, hit [CTRL]+[ALT]+[F2] to go to a shell.
  3. Now that you have a shell available, you must mount the / (maybe /usr too) directory. Mostly you don't know what directory was the / directory, so you will end up mounting an unmounting a few times. mkdir /mnt/a && mount /dev/sda5 /mnt/a && mount /dev/sda3 /mnt/a/usr
  4. When you have the required mountpoints mounted, execute a chroot, like this: chroot /mnt/a /bin/sh
  5. Now you can execute passwd, which is actually /mnt/a/usr/bin/passwd. The password will be updated in /etc/shadow, which is actually /mnt/a/etc/shadow
http://meinit.nl/an-example-of-using-chroot-to-reset-a-password-of-a-linux-machine




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值