|
1 | 1 | --- |
2 | | -title: Linux User Account and Permissions |
| 2 | +title: Create and update user accounts for WSL distributions |
3 | 3 | description: Reference for user accounts and permission management with the Windows Subsystem for Linux. |
4 | 4 | keywords: BashOnWindows, bash, wsl, windows, windows subsystem for linux, windowssubsystem, ubuntu, user accounts |
5 | | -ms.date: 09/11/2017 |
| 5 | +ms.date: 01/20/2020 |
6 | 6 | ms.topic: article |
7 | 7 | ms.assetid: f70e685f-24c6-4908-9546-bf4f0291d8fd |
8 | 8 | ms.custom: seodec18 |
9 | 9 | ms.localizationpriority: high |
10 | 10 | --- |
11 | 11 |
|
12 | | -# User Accounts and Permissions for Windows Subsystem for Linux |
| 12 | +# Create and update user accounts for WSL distributions |
13 | 13 |
|
14 | | -Creating your Linux user is the first step in setting up a new Linux distribution on WSL. The first user account you create is automatically configured with a few special attributes: |
| 14 | +Once you have enabled WSL and installed a Linux distribution from the Microsoft Store, the first step you will be asked to complete when opening your newly installed Linux distribution is to create an account, including a **User Name** and **Password**. |
15 | 15 |
|
16 | | -1. It is your default user -- it signs-in automatically on launch. |
17 | | -1. It is Linux administrator (a member of the sudo group) by default. |
| 16 | +- This **User Name** and **Password** is specific to your Linux distribution and has no bearing on your Windows user name. |
18 | 17 |
|
19 | | -Each Linux distribution running on the Windows Subsystem for Linux has its own Linux user accounts and passwords. You will have to configure a Linux user account any time you add a distribution, reinstall, or reset. Linux user accounts are not only independent per distribution, they are also independent from your Windows user account. |
| 18 | +- Once you create this **User Name** and **Password**, the account will be your default user for the distribution and automatically sign-in on launch. |
20 | 19 |
|
21 | | -## Resetting your Linux password |
| 20 | +- This account will be considered the Linux administrator, with the ability to run `sudu` (Super User Do) administrative commands. |
22 | 21 |
|
23 | | -If you have access to your Linux user account and know your current password, change it using Linux password reset tools of that distribution -- most likely `passwd`. |
| 22 | +- Each Linux distribution running on the Windows Subsystem for Linux has its own Linux user accounts and passwords. You will have to configure a Linux user account every time you add a distribution, reinstall, or reset. |
24 | 23 |
|
25 | | -If that's not an option, depending on the distribution, you may be able to reset your password by resetting the default user. |
| 24 | +## Reset your Linux password |
26 | 25 |
|
27 | | -WSL offers a default user tag to identify which user account automatically logs in when you start a WSL. Since many distributions include commands to set the default user to root and also a root user with no password set, changing the default user to root is a handy tool for things like password reset. |
| 26 | +To change your password, open your Linux distribution (Ubuntu for example) and enter the command: `passwd` |
28 | 27 |
|
29 | | -### For Creators Update and earlier |
30 | | -If you're running Windows 10 Creators update or earlier, you can change the default Bash user by running the following commands: |
| 28 | +You will be asked to enter your current password, then asked to enter your new password, and then to confirm your new password. |
31 | 29 |
|
32 | | -1. Change the default user to `root`: |
| 30 | +### Forgot your password |
33 | 31 |
|
34 | | - ```console |
35 | | - C:\> lxrun /setdefaultuser root |
36 | | - ``` |
| 32 | +If you forgot the password for your Linux distribution, try this: |
37 | 33 |
|
38 | | -1. Run `bash.exe` to now login as `root`: |
| 34 | +For Ubuntu: |
| 35 | +1. Open PowerShell and use it to change the default user name of your Ubuntu distribution to root with: `ubuntu config --default-user root` |
39 | 36 |
|
40 | | - ```console |
41 | | - C:\> bash.exe |
42 | | - ``` |
| 37 | +2. Open your distribution (Ubuntu) and you should see that the prompt now lists `root@computername` rather than the user name you entered. Enter the command: `passwd <username>` (replacing the username you created for your account and forgot the password for). |
43 | 38 |
|
44 | | -1. Reset your password using the distribution's password command, and close the Linux Console: |
| 39 | +3. You will be prompted to enter a new UNIX password and then confirm that password. Once you're told that the password has updated successfully, close the Linux distribution (Ubuntu). |
45 | 40 |
|
46 | | - ```BASH |
47 | | - $ passwd username |
48 | | - $ exit |
49 | | - ``` |
| 41 | +4. Open PowerShell and use it to change the default user name of your Ubuntu distribution back to your username with: `ubuntu config --default-user <your username>` |
50 | 42 |
|
51 | | -1. From Windows CMD, reset your default user back to your normal Linux user account: |
| 43 | +5. Now re-open your Ubuntu distribution and you should see your username displayed as the prompt, rather than `root`. Now you can confirm that your password was correctly updated. |
52 | 44 |
|
53 | | - ```console |
54 | | - C:\> lxrun.exe /setdefaultuser username |
55 | | - ``` |
| 45 | +For other Linux distributions, follow the same instructions, but in Powershell, change the command to align with the correct distribution name: |
56 | 46 |
|
57 | | -### For Fall Creators Update and later |
58 | | -To see what commands are available for a particular distribution, run `[distro.exe] /?`. |
59 | | - |
60 | | -For example, with Ubuntu installed: |
| 47 | +- openSUSE Leap 42: `openSUSE-42 config --default-user root` |
| 48 | +- SUSE Linux: `SLES-12 config --default-user root` |
| 49 | +- Debian: `debian config --default-user root` |
| 50 | +- Kali Linux: `kali config --default-user root` |
61 | 51 |
|
62 | | -```console |
63 | | -C:\> ubuntu.exe /? |
64 | | - |
65 | | -Launches or configures a linux distribution. |
66 | | - |
67 | | -Usage: |
68 | | - <no args> |
69 | | - - Launches the distro's default behavior. By default, this launches your default shell. |
70 | | - |
71 | | - run <command line> |
72 | | - - Run the given command line in that distro, using the default configuration. |
73 | | - - Everything after `run ` is passed to the linux LaunchProcess cal |
74 | | - |
75 | | - config [setting [value]] |
76 | | - - Configure certain settings for this distro. |
77 | | - - Settings are any of the following (by default) |
78 | | - - `--default-user <username>`: Set the default user for this distro to <username> |
79 | | - |
80 | | - clean |
81 | | - - Uninstalls the distro. The appx remains on your machine. This can be |
82 | | - useful for "factory resetting" your instance. This removes the linux |
83 | | - filesystem from the disk, but not the app from your PC, so you don't |
84 | | - need to redownload the entire tar.gz again. |
85 | | - |
86 | | - help |
87 | | - - Print this usage message. |
88 | | -``` |
89 | | - |
90 | | -Step by step instructions using Ubuntu: |
91 | | - |
92 | | -1. Open CMD |
93 | | -1. Set the default Linux user to `root`: |
94 | | - |
95 | | - ```console |
96 | | - C:\> ubuntu config --default-user root |
97 | | - ``` |
98 | | - |
99 | | -1. Launch your Linux distribution (`ubuntu`). You will automatically login as `root`: |
100 | | - |
101 | | -1. Reset your password using the `passwd` command: |
102 | | - |
103 | | - ```BASH |
104 | | - $ passwd username |
105 | | - ``` |
106 | | - |
107 | | -1. From Windows CMD, reset your default user back to your normal Linux user account. |
108 | | - |
109 | | - ```console |
110 | | - C:\> ubuntu config --default-user username |
111 | | - ``` |
112 | | - |
113 | | -## Permissions |
114 | | - |
115 | | -There are two important concepts to keep in mind when it comes to permissions in WSL: |
116 | | - |
117 | | -1. The Windows permission model governs a process' rights to Windows resources |
118 | | -2. The Linux permission model controls a process' rights to Linux resources |
119 | | - |
120 | | -When running Linux on WSL, Linux will have the same Windows permissions as the process that launches it. Linux can be launched in one of two permission levels: |
121 | | - |
122 | | -* Normal (non-elevated): Linux runs with the permissions of the logged-in user |
123 | | -* Elevated/admin: Linux runs with elevated/admin Windows permissions |
124 | | - |
125 | | -> Because elevated processes can access/modify (and therefore damage) system-wide settings and system-wide/protected data, **AVOID** launching elevated processes unless you absolutely have to - whether they're Windows or Linux applications/tools/shells! |
126 | | - |
127 | | -The above Windows permissions are independent of the permissions within a Linux instance: Linux "Root privileges" only impact the user’s rights within the Linux environment & filesystem; they have no impact on the Windows privileges granted. Thus, running a Linux process as root (e.g. via `sudo`) only grants that process admin rights within the Linux environment. |
128 | | - |
129 | | -**Example:** |
130 | | -A Bash session with Windows admin privileges may access `cd /mnt/c/Users/Administrator` while a Bash session without admin privileges would see a "Permission Denied" error. |
131 | | - |
132 | | -In Linux, typing `sudo cd /mnt/c/Users/Administrator` will not grant access to the Administrator’s directory since permissions within Windows are managed by Windows. |
133 | | - |
134 | | -The Linux permission model is important when inside the Linux environment where the user has permissions based on the current Linux user. |
135 | | - |
136 | | -**Example:** |
137 | | -A user in the sudo group may run `sudo apt update`. |
| 52 | +> [!NOTE] |
| 53 | +> If you are running an early version of Windows operating system, like 1703 (Creators Update) or 1709 (Fall Creators Update), see the [archived version of this user account update doc](../user-support-archived.md). |
0 commit comments