1

如何在Ubuntu创建sudo用户

 1 year ago
source link: https://www.myfreax.com/how-to-create-a-sudo-user-on-ubuntu/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何在Ubuntu创建sudo用户

sudo命令旨在允许用户以其它用户运行命令,默认是root用户

Updated At 27 Oct 2022 3 min read
By myfreax
如何在Ubuntu创建sudo用户

如何在Ubuntu创建sudo用户

sudo命令旨在允许用户以其它用户运行命令,默认是root用户。在Ubuntu发行版sudo组的成员被授予sudo访问权限。

在本教程中,我们将说明如何在Ubuntu创建具有sudo访问权限的用户。请按照以下步骤创建用户帐户并授予sudo访问权限。

如果要为现有用户添加sudo访问权限,请跳至添加用户到sudo组。

你当前登录到系统的用户必须具有sudo权限或者以root登录。否则你遇到权限拒绝的错误。

myfreax is not in the sudoers file.  This incident will be reported将提示你用户在sudoers文件中。

如果你忘记root密码可以进入单用户模式进行重置密码。你可在Grub启动的选项选择Advanced Options > Recovery进入单用户模式。

要创建用户请运行adduser命令sudo adduser username创建用户。adduser命令将会创建用户与用户的家目录。不要忘记将username替换为您要创建的用户名。

系统将提示您设置并确认用户密码。请确保新帐户的密码尽可能是强密码。

设置密码后,adduser命令将为用户创建一个家目录并从/etc/skel目录中复制配置文件到家目录中。

创建过程还将提示您设置新用户的信息。如果您想将所有这些信息留空,请按ENTER接受默认设置。

adduser username
Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n]

添加用户到sudo组

默认情况下,在Ubuntu系统,sudo组的成员被授予sudo访问权限。如果将用户添加到sudo组,那么用户就可以授予sudo的访问权限。

修改用户所属组的命令是usermod命令,我们不建议直接修改用户主要组。这可能导致某些权限问题。最好的方式将用户追加到wheel组。

因此你将使用usermod命令的-aG选项,添加用户到wheel组中,-a表示追加用户到指定组,-G选项表示不要将用户从其它组中移除。

至此。您已在Ubuntu成功创建sudo用户。您现在可以使用此用户在服务器上执行管理任务。

usermod -aG sudo username

要验证新用户是否具有sudo权限,只需要运行命令sudo whoami即可。如果用户具有sudo访问权限,命令将会打印root。

首次在使用sudo时,系统会提示您输入用户密码,注意这是是你当前用户的密码,不是root密码。

sudo whoami
root

您已经学习了如何创建具有sudo权限的用户。您现在可以使用该用户帐户登录到Ubuntu服务器,并使用sudo运行管理命令。如有任何疑问,请随时发表评论。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK