关于通过文件系统修改Windows用户名及修复登录故障的技术咨询
Hey there, sorry to hear you hit this frustrating roadblock after changing your Windows username. Since you’ve got Linux dual boot access to your Windows filesystem, we can get you back in without too much hassle—let’s walk through the options step by step.
First: Mount your Windows system partition
Before making any changes, you need to properly mount your Windows NTFS partition in Linux:
- Open a terminal and create a mount point:
sudo mkdir -p /mnt/windows - Identify your Windows system partition (it’s usually the largest NTFS partition). List all partitions to find it:
Look for a partition labeledlsblkWindowsor with aTYPEofntfs(common examples:/dev/sda2or/dev/nvme0n1p2). - Mount the partition (replace
/dev/sdXnwith your actual partition path):sudo mount -t ntfs-3g /dev/sdXn /mnt/windows
Option 1: Reset the user password (quickest fix)
The easiest way to regain access is to clear the password for the account showing up on the login screen. We’ll use chntpw—a tool for editing Windows registry and password databases (most Linux distros have it pre-installed; if not, install it with your package manager, e.g., sudo apt install chntpw for Debian/Ubuntu):
- Navigate to the Windows config directory:
cd /mnt/windows/Windows/System32/config/ - List all user accounts to confirm the one you need (the old username showing at login):
You’ll see a list of users with their unique RIDs and display names.sudo chntpw -l SAM - Select the target user to edit (replace
OldUsernamewith the name from the login screen):sudo chntpw -u "OldUsername" SAM - A menu will appear—choose option
1to clear the user’s password (set it to blank). - Press
qto exit the editor, then typeyto save your changes.
Now reboot into Windows, and you’ll be able to log in without entering a password. Once inside, you can safely adjust the username back to your preferred setting through Windows’ built-in user account settings.
Option 2: Change the username back directly via the filesystem
If you want to revert the username before logging back into Windows, you’ll need to update both the user account database and the profile path registry entry:
- Follow the steps above to mount the Windows partition and list users with
chntpw -l SAM. - Edit the target user’s name in the SAM database (replace
CurrentUsernamewith the new username you tried to set):
In the menu, choose optionsudo chntpw -u "CurrentUsername" SAM3to change the user name, then enter the old username that appears on the login screen. Save and exit as before. - Next, update the profile path to match the old username:
- Navigate to the ProfileList registry section:
cd /mnt/windows/Windows/System32/config/ sudo chntpw -e SOFTWARE - Use the
cdcommand in the chntpw editor to navigate to:Microsoft\Windows NT\CurrentVersion\ProfileList - List the subfolders here (these are user SIDs) with
ls. Find the SID corresponding to your user (cross-reference with the RID from the SAM list—the RID is the last part of the SID). - Enter that SID folder with
cd <SID>, then useed ProfileImagePathto edit the path. Change it fromC:\Users\CurrentUsernametoC:\Users\OldUsername. - Save and exit the editor.
- Navigate to the ProfileList registry section:
After these changes, reboot into Windows, and you should be able to log in with your old username and original password.
备注:内容来源于stack exchange,提问作者Shalom Alecheim

