如何在Windows 10的Ubuntu Bash Shell中更改用户帐户

When you first install Ubuntu or another Linux distribution on Windows 10, you’re asked to create a UNIX username and password. Bash automatically signs into that user account when you launch the shell, but you can change those credentials if you need to.

在Windows 10上首次安装Ubuntu或其他Linux发行版时,系统会要求您创建UNIX用户名和密码。 Bash在启动外壳程序时自动登录到该用户帐户,但是您可以根据需要更改这些凭据。

用户帐户在Linux环境中的工作方式 (How User Accounts Work in the Linux Environment)

When you set up a new Linux distribution by launching it after installing it, you’re be asked to create a user account for the Bash shell. Windows calls this your “UNIX user account.” So, if you provide the name “bob” and the password “letmein,” your Linux user account is named “bob” and has the home folder “/home/bob.” When you need to enter your password in the shell, you have to enter “letmein.” These credentials are entirely independent from your Windows user account and password.

在通过安装新Linux发行版来启动它来设置新发行版时,系统会要求您为Bash shell创建一个用户帐户。 Windows将其称为“ UNIX用户帐户”。 因此,如果提供名称“ bob”和密码“ letmein”,则您Linux用户帐户名为“ bob”,并且具有主文件夹“ / home / bob”。 当您需要在shell中输入密码时,必须输入“ letmein”。 这些凭据完全独立于Windows用户帐户和密码。

Every Linux environment you install has its own configuration, including separate files, installed programs, and configuration settings. You’ll have to create a UNIX username and password for every Linux distribution you install.

您安装的每个Linux环境都有自己的配置,包括单独的文件,已安装的程序和配置设置。 您必须为安装的每个Linux发行版创建一个UNIX用户名和密码。

如何更改Bash的默认用户帐户 (How to Change Your Default User Account for Bash)

To change your default user account in the Ubuntu Bash shell, open a Command Prompt window or PowerShell window.

要在Ubuntu Bash Shell中更改默认用户帐户,请打开命令提示符窗口或PowerShell窗口。

To open a Command Prompt window, open the Start menu, search for “cmd”, and then press Enter. To open a PowerShell window, right-click the Start button (or press Windows+X), and then select “Windows PowerShell” from the Power User menu.

要打开命令提示符窗口,请打开“开始”菜单,搜索“ cmd”,然后按Enter。 要打开PowerShell窗口,请右键单击“开始”按钮(或按Windows + X),然后从“高级用户”菜单中选择“ Windows PowerShell”。

In the Command Prompt or PowerShell window (not a Bash shell window), run the appropriate command for your Linux distro. Replace “username” in the below command with your new username:

在“命令提示符”或“ PowerShell”窗口(不是Bash shell窗口)中,为您Linux发行版运行适当的命令。 将以下命令中的“用户名”替换为您的新用户名:

  • Ubuntu: ubuntu config --default-user username

    Ubuntu: ubuntu config --default-user username

  • openSUSE Leap 42: opensuse-42 --default-user username

    openSUSE Leap 42: opensuse-42 --default-user username

  • SUSE Linux Enterprise Server 12: sles-12 --default-user username

    SUSE Linux Enterprise Server 12: sles-12 --default-user username

You can only specify a user account that already exists in the Linux environment.

您只能指定Linux环境中已经存在的用户帐户。

For example, to set the default user as root, run the following command. This is convenient if you’ve forgotten your UNIX user account password, as the root user has full system access. You’ll be able to create new user accounts and reset your existing user account’s password from the root shell.

例如,要将默认用户设置为root,请运行以下命令。 如果您忘记了UNIX用户帐户密码,这将非常方便,因为root用户具有完全的系统访问权限。 您将能够从根shell创建新的用户帐户并重置现有用户帐户的密码。

  • Ubuntu: ubuntu config --default-user root

    Ubuntu: ubuntu config --default-user root

  • openSUSE Leap 42: opensuse-42 --default-user root

    openSUSE Leap 42: opensuse-42 --default-user root

  • SUSE Linux Enterprise Server 12: sles-12 --default-user root

    SUSE Linux Enterprise Server 12: sles-12 --default-user root

如何在Bash中创建新的用户帐户 (How to Create a New User Account in Bash)

You can create user accounts by running the adduser command from within the Linux environment’s Bash shell. For example, to do this on Ubuntu, just run the following command, replacing “newuser” with the name of your new user account:

您可以通过在Linux环境的Bash shell中运行adduser命令来创建用户帐户。 例如,要在Ubuntu上执行此操作,只需运行以下命令,将“ newuser”替换为新用户帐户的名称:

sudo adduser newuser

Provide your current user account’s password to authenticate, and then enter a password for the new user account. (If you don’t remember your current UNIX account’s password, use the commands we covered in the previous section to set the root user as the default user account first.)

提供您当前用户帐户的密码进行身份验证,然后输入新用户帐户的密码。 (如果您不记得当前的UNIX帐户的密码,请使用上一节中介绍的命令首先将root用户设置为默认用户帐户。)

You’ll also be asked to provide other information, like a “full name” and phone numbers for the new account. This data is all stored locally on your computer, and it isn’t important. You can just press Enter to leave these fields blank.

您还将被要求提供其他信息,例如新帐户的“全名”和电话号码。 这些数据全部存储在本地计算机上,这并不重要。 您可以按Enter键将这些字段保留为空白。

After you create a new user account, you can make it the default user account using the above command, or switch to it using the su command shown in the image below.

创建新的用户帐户后,可以使用上述命令将其设置为默认用户帐户,或者使用下图所示的su命令将其切换为默认用户帐户。

如何更改Bash用户帐户的密码 (How to Change Your Bash User Account’s Password)

To change your Bash user account’s password, you’ll need to use normal Linux commands inside the Bash environment. To change the current user account’s password, you’d launch a Bash shell and run the following command:

要更改您的Bash用户帐户的密码,您需要在Bash环境中使用普通Linux命令。 要更改当前用户帐户的密码,请启动Bash shell并运行以下命令:

passwd

Enter your user account’s current password, and then provide a new password.

输入用户帐户的当前密码,然后提供新密码。

To change another user account’s password—for example, if you forgot your password and then set the root account as the default user account—you’d run the following command, where “username” is the username of the account whose password you want to change:

要更改另一个用户帐户的密码(例如,如果您忘记了密码,然后将根帐户设置为默认用户帐户),则需要运行以下命令,其中“ username”是您要为其密码设置的帐户的用户名更改:

passwd username

This command must be run with root permissions, so you’ll need to prefix it with sudo on Ubuntu if you’re not running it as the root user:

该命令必须以root权限运行,因此,如果您没有以root用户身份运行,则需要在Ubuntu上使用sudo前缀:

sudo passwd username

如何在用户帐户之间切换 (How to Switch Between User Accounts)

The ubuntu config --default-user username (or equivalent command for your Linux distribution) controls which user account the Bash shell uses by default. However, if you’d like to use multiple user accounts with Bash, you can switch between them while inside a Bash shell.

ubuntu config --default-user username (或Linux发行版的等效命令)控制Bash shell默认使用的用户帐户。 但是,如果您想在Bash中使用多个用户帐户,则可以在Bash Shell中在它们之间切换。

To do this, run the following command in a Bash shell, replacing “username” with the username you want to use:

为此,请在Bash shell中运行以下命令,将“ username”替换为要使用的用户名:

su username

You’ll be prompted to enter the other user account’s password, and then you’ll be switched to that user account in the Bash shell.

系统将提示您输入其他用户帐户的密码,然后在Bash shell中切换到该用户帐户。

翻译自: https://www.howtogeek.com/261417/how-to-change-your-user-account-in-windows-10s-ubuntu-bash-shell/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值