I recently found the path to my Ubuntu files in Windows. I renamed my user's home folder through Windows
Let's start with, don't do that! ;-)
While the normal WSL permissions shouldn't allow you to do that in the first place, apparently you were able to somehow. I'm not sure how, but it doesn't really matter. Simply renaming a Linux user's home folder will never work, even in "normal" (non-WSL) Ubuntu. For that matter, renaming your Windows user's folder would have a similar (perhaps worse) effect.
While I can't rename my user's home directory through Windows, I can still reproduce your same error by starting Ubuntu as root with:
wsl ~ -d Ubuntu -u root
Then:
mv /home/ntd /home/xyz
After that, when I attempt to login as my ntd user, yes, I see that message.
The problem is that Ubuntu still thinks the home directory for my user is /home/ntd
(and for yours, /home/useradd
apparently). For instance:
# echo $HOME
/home/ntd
# cd ~
-bash: cd: /home/ntd: No such file or directory
Also, certain items in the default startup files reference $HOME
. For instance, in /etc/profile.d/update-motd.sh
you'll find:
if [ ! -e "$HOME/.hushlogin" ] && [ -z "$MOTD_SHOWN" ] && ! find $stamp -newermt 'today 0:00' 2> /dev/null | grep -q -m 1 '.'; then
[ $(id -u) -eq 0 ] || SHOW="--show-only"
update-motd $SHOW
echo ""
eval_gettext "This message is shown once a day. To disable it please create the"
echo -n "$HOME/.hushlogin "
...
I don't really know what to do and how to fix it.
At this point, the easiest way to fix that particular issue is to tell Ubuntu where the user's new home directory is. You can do this by:
Exiting Ubuntu
Start PowerShell and:
wsl ~ -u root
This starts Ubuntu as the root user. Then start the "safe editor" for the passwd file with:
vipw
Look for the line that starts with your normal username (which sounds like it is useradd
). It will probably look something like:
useradd:x:1000:1000:,,,:/home/useradd:/bin/bash
Change the /home/useradd
to the new directory name.
Save and exit
Exit Ubuntu and restart it as your normal user. Hopefully, the error will be fixed.
Note that the proper way to change the directory name is (as mentioned in this question) to use usermod -d
. This is quite a bit easier in WSL than normal, since you can easily start as root and make sure that your normal user isn't in use.
Exit Ubuntu and from PowerShell:
wsl -l -v
# Confirm the name of the distribution being used
# and replace "Ubuntu" below with the correct name if
# it is different
wsl --terminate Ubuntu
wsl ~ -u root
In Ubuntu:
usermod -d /home/<new_directory> -m <username>
The -d
specifies the new directory, and the -m
specifies that the existing user files should be moved to that directory.