7

I have installed Ubuntu Linux under WSL on my Windows 11 PC. I established a username during the installation, perdiem. When everything was up and running, I cd'ed to ~, and the directory I ended up in was /home/ls. I'm not sure why this is; I would have thought it would be my username. It is also odd that it is actually a Linux command—sort of confusing.

This isn't a problem, but does anyone know why ls is established as the home directory rather than my username?


Output of id:

uid=1000(ls) gid=1000(ls) groups=1000(ls),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),100(users),107(netdev) 

Output of grep /home/ls /etc/passwd:

ls:x:1000:1000:,,,:/home/ls:/bin/bash 
12
  • 2
    Not having watched you do the install this is impossible to answer. ls as a username seems odd ... Commented Apr 20 at 3:11
  • Tink: There was not very much to the install to watch - because I'm doing this under Windows 11 using the Windows Subsystem for Linus a.k.a WSL. The WSL command basically does everything for you - at the end it asks you to provide a username and password, then finishes up - all without any Q&A or much in the way of alternatives. So I'm chalking this up to "convenience" verses "do-it-yourself". If you want convenience, you get what you pay for. Commented Apr 20 at 15:51
  • I thought that WSL is supposed to be used INSTEAD of Linux. So now you have available in parallel the Windows files and the Linux files, and you can execute any of them (hopefully)? Why not install in a VM? Me being a noob: is this the intended purpose of WSL, its reason for existence? Commented Apr 21 at 12:24
  • @virolino Where do you see them installing linux instead of wsl? Commented Apr 21 at 16:21
  • 2
    @virolino in my understandling, WSL is just a Microsoft sanctioned virtual machine that runs a version of Linux, providing essential hooks back into Windows. When you install it you are still responsible for picking which version of Linux you will use, although I think Ubuntu is the default. Commented Apr 21 at 19:32

2 Answers 2

14

If cd ~ places you into /home/ls, then in that session, the $HOME environment variable has been set to /home/ls somehow. That might be caused by the home directory being set to /home/ls in the user account information in /etc/passwd (or whatever plug-in mechanism is used for user account information), or by something changing the environment variable to an incorrect value, either for that specific session only, or for all login sessions.

If you don't have write access to /home/ls and the /home/perdiem directory exists and is writeable to your regular user, then I would suspect an error in a customized login script or a mistyped command causing the $HOME environment variable to get reassigned.

If /home/perdiem does not exist and /home/ls does, and the latter has the correct ownership and permissions to serve as your home directory, then it would suggest an error in script(s) responsible for creating the user account. In this case, the /etc/passwd line for your user account would also specify the home directory as /home/ls.

You could check this with getent passwd perdiem and looking at the 6th colon-separated field on the output line.

An output like

perdiem:x:1000:1000:Full Name,,,:/home/perdiem:/bin/bash 

would mean the home directory is specified correctly in user account information, and so something must have changed the $HOME variable after the login session was initiated.

A result like

perdiem:x:1000:1000:Firstname Lastname,,,:/home/ls:/bin/bash 

would mean the error is in user account information, suggesting an error at user account creation time.

Debian/Ubuntu seems to supply /usr/sbin/adduser as a wrapper script for user creation and treats /usr/sbin/useradd as a low-level tool. Errors in customization of this script (either by you, or by the WSL distribution packager) might cause the script to call the low-level useradd command with wrong parameters.

But if this was the initial user account created during the installation of the WSL environment, then the user account may have been created directly by whatever script(s) are used in the installation process, which may or may not involve the useradd command or the adduser script at all.

6
  • 1
    telcoM, Thanks for the detailed analysis! After following your suggestions (and other's) for investigating further (getent, and greps above) my conclusion is that there are errors (or features :) ) in the WSL scripts that simply ignore the username entered, or incorrectly use it, and this is what you get. WSL seems very simple and easy for someone who is not versed in the intricacies of Linux (that's me), but you get what you pay for. Again, Thanks! Commented Apr 20 at 15:59
  • TelcoM, I tried to upvote, but I am not yet allowed to do so. Commented Apr 20 at 16:01
  • I suggest that "ls" could stand for "Linux subsystem". Note that WSL is not a normal Linux system and this could be intentional. Commented Apr 21 at 13:16
  • 4
    I'm still using WSL 1, but my home directory is /home/Yay295 (\\wsl$\Ubuntu\home\Yay295). I don't think this is a WSL thing. Commented Apr 21 at 14:12
  • Re "That might be caused by the home directory being set to /home/ls in the user account information in /etc/passwd", This is the case. As shown in the question, they are running as user ls (uid=1000(ls) from id), and its home dir is set to /home/ls in passwd. Not sure why you suggest using getent passwd perdiem when they are running as ls. Commented Apr 21 at 22:23
0

On a generic Linux system, one can exit X-11 (or Wayland), log out of USER, and, in a classic command console with no X-11 or graphics running, login as root. Make sure that you are not logged in as USER in any tty and that no graphical shell is running. In other words, nothing that needs or runs in USER should be active.

Then issue the following commands:

 usermod -l NEW_USER USER # Change username from USER to NEW_USER groupmod -n NEW_USER USER # Change groupname from USER to NEW_USER usermod -d /home/NEW_HOMEDIR -m NEW_USER # Change user's directory 

Log out as root, and then try logging in (still in a command console) as NEW_USER to see if everything is OK. If everything looks good, you can run "startx" (I use X-11, and always start it manually using "startx" after logging in) to start up the GUI. You may need do do some re-configuration to X-11, to your chosen desktop manager, etc.

Another way to change your username and directory is to simply create a new user! You can then copy/move all your non-system stuff from your current user directory to your new user directory. When everything is running well and configured, you can remove the old user and directory. Simple and it always works.

Without further info, I cannot determine why the username got set to "ls". I generally use Debian and always start with a command console, which makes it easier to track problems -- e.g., if X-11 needs to be reconfigured, I can just kill it, and make the changes (e.g., to xorg.conf) in console mode, and use startx to restart the X-11 display. No rebooting or graphical login managers. I am very old-school!

5
  • 5
    The question is "why?", not "how can I change it?". Commented Apr 20 at 8:36
  • Kamil, THANKS, you are correct - I was wondering why it ended up that way, rather than how to change / correct it. However, Sci-Con's response is adjacent to the problem and does contain useful information - So, while not on point, thanks to Sic-Con for the information. Commented Apr 20 at 15:35
  • Sci-Cons, Thanks for taking the time to provide this information. It's a bit complicated and, as a simple user, a bit hard to understand completely - but it seems like creating a new user should be easy enough and not too risky. Thanks! Commented Apr 20 at 15:37
  • Sci-Cons, I tried to up vote, but I am not yet allowed to do so. Commented Apr 20 at 16:00
  • The why is hard to determine, but here are some possibilities: 1) an error in some scripts used for installation/setup, as mentioned earlier; 2) an entry error (e.g., "ls" command was issued, not at the command prompt, but at a prompt for a username); 3) a glitch occurred during setup as various processes were being initialized. Given the difficulty in tracking the cause, I thought it was best to provide some solutions to fix the problem. Commented Apr 21 at 5:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.