如何在CentOS 8上创建启用了Sudo的新用户[快速入门]

news/2024/7/4 13:23:40

介绍 (Introduction)

The sudo command provides a mechanism for granting administrator privileges — ordinarily only available to the root user — to normal users. This guide will show you how to create a new user with sudo access on CentOS 8, without having to modify your server’s /etc/sudoers file.

sudo命令提供了一种向普通用户授予管理员特权(通常仅对root用户可用)的机制。 本指南将向您展示如何在CentOS 8上创建具有sudo访问权限的新用户,而无需修改服务器的/etc/sudoers文件。

Note: If you want to configure sudo for an existing CentOS user, skip to step 3.

注意:如果要为现有的CentOS用户配置sudo ,请跳至步骤3。

第1步-登录到服务器 (Step 1 — Logging Into Your Server)

SSH in to your server as the root user:

root用户身份登录到服务器:

  • ssh root@your_server_ip_address

    ssh root @ your_server_ip_address

Use your server’s IP address or hostname in place of your_server_ip_address above.

使用服务器的IP地址或主机名代替上面的your_server_ip_address

第2步-将新用户添加到系统 (Step 2 — Adding a New User to the System)

Use the adduser command to add a new user to your system:

使用adduser命令将新用户添加到您的系统:

  • adduser sammy

    adduser sammy

Be sure to replace sammy with the username you’d like to create.

确保将sammy替换为您要创建的用户名。

Use the passwd command to update the new user’s password:

使用passwd命令更新新用户的密码:

  • passwd sammy

    密码萨米

Remember to replace sammy with the user that you just created. You will be prompted twice for a new password:

请记住用刚创建的用户替换sammy 。 系统将提示您两次输入新密码:


   
Output
Changing password for user sammy. New password: Retype new password: passwd: all authentication tokens updated successfully.

步骤3 —将用户添加到wheel(Step 3 — Adding the User to the wheel Group)

Use the usermod command to add the user to the wheel group:

使用usermod命令将用户添加到Wheel组:

  • usermod -aG wheel sammy

    usermod -aG车轮萨米

Once again, be sure to replace sammy with the username you’d like to give sudo priveleges to. By default, on CentOS, all members of the wheel group have full sudo access.

再次确保将sammy替换为您要赋予sudo特权的用户名。 默认情况下,在CentOS上, wheel组的所有成员都具有完全的sudo访问权限。

步骤4 —测试sudo访问 (Step 4 — Testing sudo Access)

To test that the new sudo permissions are working, first use the su command to switch from the root user to the new user account:

要测试新的sudo权限是否正常运行,请首先使用su命令从root用户切换到新用户帐户:

  • su - sammy

    苏- 萨米

As the new user, verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:

作为新用户,验证您可以使用sudo通过预先sudo到您想要拥有超级用户权限运行以下命令:

  • sudo command_to_run

    须藤command_to_run

For example, you can list the contents of the /root directory, which is normally only accessible to the root user:

例如,您可以列出/root目录的内容,该目录通常只能由root用户访问:

  • sudo ls -la /root

    须藤ls -la / root

The first time you use sudo in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:

第一次在会话中使用sudo时,系统将提示您输入该用户帐户的密码。 输入密码以继续:


   
Output
[sudo] password for sammy:

Note: This is not asking for the root password! Enter the password of the sudo-enabled user, not the root password.

注意:不是要求输入root密码! 输入启用了sudo的用户的密码,而不是root密码。

If your user is in the proper group and you entered the password correctly, the command that you issued with sudo will run with root privileges.

如果您的用户在适当的组中,并且您输入的密码正确,那么使用sudo发出的sudo将以root特权运行。

结论 (Conclusion)

In this quickstart tutorial we created a new user account and added it to the wheel group to enable sudo access. For more detailed information on setting up a CentOS 8 server, please read our Initial Server Setup with CentOS 8 tutorial.

在本快速入门教程中,我们创建了一个新的用户帐户,并将其添加到wheel组中以启用sudo访问。 有关设置CentOS 8服务器的更多详细信息,请阅读我们的CentOS 8初始服务器设置教程。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-sudo-enabled-user-on-centos-8-quickstart


http://www.niftyadmin.cn/n/3648611.html

相关文章

实现开启和关闭android移动网络(做AppWidget开发的收获)

之前在做Android AppWidget这方面的开发,本人菜鸟一个,刚接触android不久。所以在开发的过程中不免遇到诸多难处,不过在解决问题中收获知识是一种非常刺激的体验。接下来是本人在开发开关android系统移动网络的过程所收获的知识,希…

在VB中实现PickList功能

在VB中实现PickList功能前言使用Delphi编程的人都知道,在Delphi中数据库控件DbGrid具有PickList功能,即编辑所在列时,只要用鼠标点击时,该列所在行便会出现组合框,列出所有内容供用户选择,这很方便数据录入…

如何在Ubuntu 18.04上打包和发布Snap应用程序

The author selected the Electronic Frontier Foundation to receive a donation as part of the Write for DOnations program. 作者选择了电子前沿基金会来接受捐款,这是Write for DOnations计划的一部分。 介绍 (Introduction) One of the largest challenges …

··· Socks Online - 在内部网也能使用QQ ···

Socks Online - 在内部网也能使用QQ(1)互联在线 一、背景现在许多人常用QQ(OICQ)上网聊天,但有时候在办公室或公司内部无法使用。原来的QQ不支持Http Proxy,新的QQ要求会员方能使用,给用户带来许多不便。有没有一个简单的方法在内部网也可以使…

Android网络开启、关闭整理

Android网络开启、关闭整理 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211…

.nsh 怎么样运行_如何在Ubuntu 18.04上使用nsh运行安全的远程命令

.nsh 怎么样运行介绍 (Introduction) It can often be difficult to manage multiple machines on a daily basis. While Secure Shell (SSH) is a good choice for remote access, the protocol itself has some drawbacks in both convenience and security. 每天通常很难管理…

WINAMP SDK 常见问题回答(FAQ)

WINAMP SDK 常见问题回答(FAQ) 这里有一些收集的问题,我们不想每个人重蹈覆辙,希望这里变成知识仓库,能够帮助大家。1、我不知道怎样用sdk,你可以帮助我写一个插件吗?一个好的方法就是去下载sdks,然后去察看或修改代…

EventBus的手写

在上一篇文章我讲了EventBus源码,现在我们来手写一下EventBus 使用 MainActiviity public class MainActivity extends AppCompatActivity {private TextView mTv;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceSta…