jarmare bernsteyn darshen

0 views
Skip to first unread message

Kum Dana

unread,
Aug 3, 2024, 1:04:51 AM8/3/24
to quifiguchor

If you (or someone you know) ever forget your Windows password, you'll be glad to know about chntpw, a neat Linux utility that you can use to reset a Windows password. For this how-to, I created a Windows virtual machine and set the password to pass123 on my user account, Archit-PC. I also created a Live USB with Fedora 27 using the Fedora Media Writer application.

Spotted a small glitch. Looks like the screenshot that supposed to illustrate the execution of a mounting command, sudo mount /dev/sda2 /mnt/Microsoft/, is wrong. For me it shows the result of the execution of a chntpw command, sudo chntpw -i SAM.

This only works if your Windows drive is not encrypted. If you have encrypted it using the storage option of Windows, you won't even be able to mount the volume correctly and edit its content from an external tool to clear the password stored in the SAM registry file, you first need the password.
It may also not work if the encryption password comes from the TPE module which won't allow you to boot from the external drive which was not first allowed to run as it was not signed.
But anyway it's good to signal users that their Windwos password is not a real protection for their data, and that it can be easily cleared in most cases: suppose your PC is stolen (or seized by the police/justice...), they know what they can do easily to enter your drive and get access to all the contents.
Also clearing a password this way may invalidate all access tokens that allow you to use some remote sites or storage that will need a new authorization, because the SAM database will no longer have the necessary access tokens.Your PC will then be "disconnected" from a secure corporate domain and you'll need to contact the domain admin to reauthorize your PC (and fbefore they accept to reconnect you they'll want to inspect your PC, and may force you to resintall it completely).
So don't do that to bypass the protections that have been set in a corporate domain against such personal use of a PC you don't really own and have no right to adminsiter yourself.

Opensource.com aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. Red Hat and the Red Hat logo are trademarks of Red Hat, Inc., registered in the United States and other countries.

Have you ever forgotten your root password and needed to reset it? I have a very good memory. I remember most of my client'spasswords (there are a few I forget regularly for no reason that Ican understand, but I really do know most), I remember telephonenumbers, and of course I know my own passwords. That last isn't aseasy as it might sound, because I have quite a few differentsystems and each has its own password, but though I might use thewrong one now and then, I'll get it on the second or third try.

Well, not this time. A while back I installed Fedora on asystem here, and today I wanted to look at something and .. whatwas the root password? Hmm, not that.. how about? .. nope, well itmust be.. darn!

Twice I have been at customer sites with a lost root paswordand found that root was already logged in on one of the Alt screens. It is worth checking.. check "w" too. It's a long shot,but somebody might be in a long forgotten window.

But let's try it the easy way first. The next thing to try is to boot to single user mode. This MIGHT not work for you, because your system might be configured to still ask for a root password to get to single user mode. If that's the case, we'll use another trick that replaces init with /bin/bash.

If you don't see either a LILO or GRUB boot screen, try hitting CTRL-X to get one. Once you have that, if it's LILO, just type "linux single" and that should do it (assuming that "linux" is the lilo label, which it probably is). If GRUB, hit 'e", then select the "kernel" line, hit "e" again, and add " single" (or just " 1") to the end of the line. Press ENTER, and then "b" to boot. (More modern grub uses "a" to append to the boot line)

You should get a fairly normal looking boot sequence except that it terminates a little early at a bash prompt. If you get a "Give root password for system maintenance", this isn't going to work, so try the "init" version below.

Another trick is to add "init=/bin/bash" (LILO "linux init=/bin/bash" or add it to the Grub "kernel" line). This will dump you to a bash prompt much earlier than single user mode, and a lot less has been initialized, mounted, etc. Note that other filesystems aren't mounted at all, so you may need to mount them manually if you need them. Look in /etc/fstab for the device names or use "fdisk -l" to list available partitions.

However, some systems are protected with boot loader passwords that won't let you do that without THAT password. If the boot loader is password protected, you need to boot from other media - for newer systems, the install CD probably has the recovery tools for that ("linux rescue" for example). You could use your install disks or download something like Tom's Root and Boot Disk.

If using something like "linux rescue" or other boot media, if the recovery disk doesn't automatically mount your disk, you need to do it manually. This shouldn't be difficult unless you have an unusual disk controller. For example, a Compaq raid controller will probably be /dev/ida/c0d0. Find the partitions by using fdisk /dev/ida/c0d0 (just "p" and quit) and then mount what you need.

You might "mount /dev/hda2 /mnt". Once you have your filesystem mounted, you might try "chroot" and then use "passwd" to fix things up. Say you have the old drive at "/mnt" - type "chroot /mnt" and then use "passwd".

Or just edit /mnt/etc/shadow to remove the password field: move to just beyond the first ":" and remove everything up to the next ":". With vi, that would be "/:" to move to the first ":", space bar once, then "d/:" and ENTER. You'll get a warning about changing a read-only file; that's normal. Before you do this, /mnt/etc/shadow might look like:

You'll need to force the write: with vi, ":wq!". (If that stilldoesn't work, you needed to do the -o remount,rw, see above). If it does work, you have reset root to not have a password. You'll want to change that soon, of course.

Keep this in mind if you have a Linux machine in a publically accessible place : without more protection, it's not usually hard to recover a lost root password, which means it's just as easy for someone to CHANGE it, or access root without your knowlege. The only difference between "break root" and this is intent. Hacking root's password can be accomplished with these same methods, so if you want to protect your machine, you may want to close these off.

I remembered posting an alternative using systemd.unit=rescue.target when editing the grub entry temporarily like you do with rd.break. so another way around it: Autorelabel and SELinux Question - #5 by iwalker

Just tested it with Rocky 9, selecting rescue kernel, adding rd.break. Booted, still get the password option, but just pressed enter without putting a password, and it bypasses and allows you to continue at this point. So, this will allow you to reset the root password with the remaining steps.

The second solution given in the link that iwalker pasted is simpler and also works. Probably works on older versions too. To save people time.
Boot, hit e for edit (you can use normal kernel). In the line beginning with linux, change the ro to rw and add at the end init=/bin/bash
This will boot into a root prompt no pass needed. Use the passwd command to change root password.
Then

@iwalker , I have never had much understanding of the Bugzilla reports. But if this issue existed for both the RHEL9 as well as RHEL8 kernels, how would that be displayed? In a single Bugzilla report or two independent reports?

actually i have gone through a problematic situation ,where esm admin password got expired ,and i have to reset the password through linux console ,so could you guide me ,the steps how to reset the ESM admin password through linux console.

This article provides three methods to reset local Linux Virtual Machine (VM) passwords. If the user account is expired or you want to create a new account, you can use the following methods to create a new local admin account and regain access to the VM.

If SElinux is in enforcing mode, make sure that SElinux allows the file changes made with the passwd command. After the password is changed, you can run the following command to relabel the file system to facilitate the loading of the alteration.

If you're experiencing problems that affect an Azure network virtual appliance, this method doesn't apply to your situation. Instead, you must contact the vendor of the network virtual appliance to get instructions about how to do a password reset safely.

You can run the vm repair commands to create a repair VM that has a copy of the affected VM's OS disk attached. Then, mount the copy of the OS file systems on the repair VM via the chroot environment.

c01484d022
Reply all
Reply to author
Forward
0 new messages