Set default user linux

Setting default user in Linux/WSL in sideloaded distro

With WSL Distros from the Microsoft store they are bundled with a utility to set the default user ubuntu config —default-user new_user_name . If i sideload a distro image that option doesn’t exist. How can I set default user without it? Windows 10 Pro Build 19033.1 As for as installing a distro I would download the tar.gz from something like here and Use wsl —import to install it.

2 Answers 2

Another method — added in build 18980 — simple, and doesn’t require registry modification:

  1. Create the /etc/wsl.conf file in the WSL distro (if it doesn’t already exist).
  2. Add the following section to it: [user]
    default=

I tried, but it did not work for me. Switching user with su username works, but the distro keeps logging in as root.

Warning: The following registry method is not documented and may change.

  • Method 1, Simple but undocumented. Open the Registry Editor. Go to this key HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss . Double click to expand it. There will be some random strings in curly braces, its called GUID. Go through each one of them until you find the distribution name that matches with DistributionName registry. Now double click on the DefaultUid DWORD registry and change the value to the user id that will be set to be default. For example, root user id is 0 (zero), normal user id is 1000 (0x3e8 in hex). Here is an example of WSL distribution entry in registry:
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\] "State"=dword:00000001 "DistributionName"="Debian" "Version"=dword:00000002 "BasePath"="F:\\Debian" "Flags"=dword:00000007 "DefaultUid"=dword:000003e8 
  • Method 2, complex but documented. This requires some programming in C language. Use the WslConfigureDistribution function to set the default user id. These WSL APIs are written in wslapi.h header file in Windows 10 SDK. For example, to set normal user (uid = 1000 ) as default in Ubuntu distribution, use this:
WslConfigureDistribution(L"Ubuntu", 1000, WSL_DISTRIBUTION_FLAGS_DEFAULT); 

This method is used in WSL distribution launcher that is bundled with every WSL distribution in Windows Store.

Источник

Change default login user for Linux from root

I’ve been working with Linux for awhile and was wondering how I could go about changing the default login user. The whole time I’ve used Ubuntu, I’ve been logging in as the root node, as bad as that is. It does it automatically upon startup. Running Ubuntu in Windows Terminal with WSL. I’d appreciate any help. Thank you!

That did the trick. Had to create/source .profile into my home user directory, because I lost my colors, but all is well now. Thank you!

2 Answers 2

Went to the above link, and just went into cmd.exe and did: ubuntu2004 config —default-user

This caused a secondary issue where I lost my colors on the terminal, but that was resolved with:

  1. sudo nano /etc/passwd
  2. Scroll down to your user and change the numbers for user id and group both to 0. Example:
Читайте также:  Init bin bash сброс пароля astra linux

Be aware as this may result to unstable OS in some distros, or it may cause that some apps stop working.

No, no, no! This changes your user account to be effectively the same as root, which removes just about all protections the system can otherwise give you from shooting yourself in both feet

You must log in to answer this question.

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

How to set default user for manually installed WSL distro?

I have cloned a WSL distro using wsl —export and wsl —import , but now, running wsl newdistro always logs me in as root. I understand that the lxrun command is deprecated and want to avoid it. The docs recommend using distroname.exe config , but that doesn’t work, since this one doesn’t have a corresponding executable.

7 Answers 7

As of the time of this writing, there are at least three (let’s call it 3.5) different methods of changing/setting the default user in an imported WSL instance. While the two that have already been mentioned still work, there is a Microsoft recommended way to do it that hasn’t been mentioned yet in this question.

Method 1 — /etc/wsl.conf

The current Microsoft recommended way of setting the username in an instance is to create a /etc/wsl.conf in the instance with the following setting:

Changing, of course, username to be your default username.

Exit your distro/instance, then issue a wsl —terminate from PowerShell or CMD. When you restart, the default user should be set.

This is safer and less error-prone than the registry-based methods.

Method 2 — Registry Key

Setting the registry key per @harrymc’s answer.

Method 3 — LxRunOffline

Using LxRunOffline to set the registry entry, as described in @Jaime’s answer. Ultimately this has the same effect as Method 2.

Semi-method 4 — Runtime user selection via wsl commandline argument

The username can be selected when starting any WSL instance by:

wsl -u username or wsl -d distroname -u username , etc.

For instance, wsl -d Ubuntu -u root .

Side Note: This question was specifically about setting the default username in an imported instance. However, for completeness, you can also set the default username for a distro that was installed from the Store (or wsl —install ) with:

For instance, if you installed «Ubuntu 20.04» from the Store, you would use:

ubuntu2004.exe config --default-user

The .exe here is an «App Execution Alias» in Windows. You can check the name by going to «Manage app execution aliases» in the Windows System Settings.

Читайте также:  Где криптопро хранит сертификаты linux

For readers who need to create a new user

@ndemou made a good point in the comments last year that I, in hindsight, dismissed improperly. Two other users have now mentioned in the comments that @ndemou’s information was helpful. My belated apologies! Here’s the additional information based on @ndemou’s advice .

Some users who find this answer may be starting up as root not because they —import ‘d a distribution, but possibly because the default user was never created during installation in the first place. This can happen when the distribution installation is stopped prematurely, and likely for other reasons as well.

Under Ubuntu, the default distribution for WSL, you can create your user by starting with:

If you need to, add the -d option.

NEWUSER= useradd --create-home --shell /usr/bin/bash --user-group --groups adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev --password $(read -sp Password: pw ; echo $pw | openssl passwd -1 -stdin) $NEWUSER 

Then set the user as the default using the /etc/wsl.conf as mentioned above.

If you’ve already created the user, or are using a different distribution, as @ndemou points out, make sure to also add the user either to a group that is in sudoers or directly to sudoers via visudo . See the answers to this question for additional details.

Источник

How to change default user in WSL Ubuntu bash on Windows 10

I installed the WSL Bash on Windows 10 and set my user to e.g. ‘abc’ but now I want to change it to something else. How can I change the user name of the user I’m logged in as? When I open bash it automatically logs me in with my current user.

As of now, Ubuntu 20.04 is current. After its installed using WSL 2, the ubuntu2004 command becomes available for use: ubuntu2004 config —default-user robert

For those who didn’t installed via store (e.g via export/import): github.com/microsoft/WSL/issues/3974#issuecomment-576782860. Default user can be changed by creating a /etc/wsl.conf file

Thanks so much @SebastianHoffmann, this comment is what made me realise that it was all due to the import. Thought when I exported that everything would be an exact copy, but I guess not.

9 Answers 9

Now that LxRun.exe is deprecated, if you install Ubuntu from the Windows store the command you will need to run at a windows command prompt is

ubuntu config --default-user

(Note: depending on which version you installed this could be ubuntu1804.exe or ubuntu2004.exe )

If you’re using WSL2, you’re done.

For WSL1, you’ll need to also restart LxssManager service

sc stop LxssManager sc start LxssManager 

ubuntu might NOT be your default, it depends which version you installed so check the answers below, as mine is «ubuntu1804 config . «

instead of setting the default user it opened bash for me. It does not seem to be working for some reason. I am on the latest release of Windows as of today

With WSL 2 in use, it was not required to restart the LxSSManager service for the container to use the change

The top answer ( ubuntu config —default-user root ) is currently correct for the default instance. But if you have multiple instances, you need to work slightly harder:

Читайте также:  Использование zip в linux

Inside the instance, as root, create/edit /etc/wsl.conf and add these lines:

Then close it, run wsl —terminate in PowerShell, and restart it.

That’s from an issue in the WSL repo. The registry hack answer is also in there, but /etc/wsl.conf is now officially the supported solution.

All other answers were helpful, but can be other scenarios too, follow here as per yours. Mine was Ubuntu 16.04, so I used the following:

ubuntu1604 config --default-user

If you installed Ubuntu 18.04:

ubuntu1804 config --default-user

If you used the default one, then:

ubuntu config --default-user

Should this not change the current username to the username I provide in ? When I try this it just tells me the username I am providing does not exist. This is on 18.0.4

If you’re running Ubuntu 18.04 from the Microsoft Store, the command (powershell or cmd) will be:

ubuntu1804 config --default-user

You can change the default user for bash by running the following command in a normal command prompt (cmd.exe):

Old question that got bumped today, but the answers need updating and consolidating to be current (and correct).

There are two parts to the question, and every answer here so far just covers one or the other.

How can I change the user name of the user I’m logged in as?

As @PJ127 correctly pointed out, the first step is to actually change the username within Ubuntu. This can most easily be done (now, in 2021) by exiting WSL and starting PowerShell, then:

wsl -l -v wsl --terminate # from the previous command wsl -u root -d # "-d " is only needed for non-default instances # Now from in WSL usermod -l newname oldname # Optionally change the home directory name to match usermod -d /home/doug -m doug # Optionally change the group name to match groupmod -n newname oldname 

Then there’s the second part of the question, which is what most of the answers here attempt to cover:

When I open bash it automatically logs me in with my current user

There are multiple ways of doing this, but the Microsoft recommended/documented method in 2021 is as @Jacktose answered:

    In your WSL instance, sudo editor /etc/wsl.conf with the following contents:

While the ubuntu.exe —config method will work, there are two problems:

  • It’s not always «ubuntu.exe». The name of the executable (technically «app execution alias») depends on which version you installed from the Store. Ubuntu has come in multiple Store packages over the years. There’s a package for each supported release (e.g. ubuntu2004.exe , etc.) and one for the «current» version ( ubuntu.exe ). And while this is Ask Ubuntu, it also could be alpine.exe , etc. if you are using a different distribution.
  • It also, as has been pointed out in other answers, does not work if you have more than one instance installed (which is a great feature of WSL). It will only work for the first, store-installed instance.

Then, of course, there are registry-based methods of changing the default name, but since we have safer, supported methods let’s not even cover those here. 🙂

Источник

Оцените статью
Adblock
detector