Last update at :2024-02-05,Edit by888u
The previous article "Ubuntu User Creation Tutorial: Adding a Non-root Account with Sudo Permissions" introduced how to create a non-root user account with sudo permissions in the Ubuntu operating system. Today we will introduce how to create it under the CentOS system. A non-root account with sudo privileges. It is a best practice to perform server administration as a non-root user. For security reasons, when deploying a CentOS system on a VPS, the first priority is to create a non-root user with sudo access. This tutorial applies to the following system versions, with or without SELinux enabled.
- CentOS 8
- CentOS 7
- CentOS 6
1. Add new user account
Use the adduser command to create a new user account.
# adduser example_userUse the passwd command to set a strong password:
# passwd example_user Changing password for user example_user. New password: Retype new password: passwd: all authentication tokens updated successfully.2. Add the user to the wheel group
Use usermod to add new users to the wheel group.
# usermod -aG wheel example_user3. Edit the Sudoers file
Use visudo to check the sudoers file.
#visudoLook for the wheel group and remove the comment if the line is disabled. When you're ready to save your file, it should look something like this.
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALLSave and exit vi, press ESC, then :WQ, then ENTER.
Note: The visudo utility performs syntax checking before committing your edits to the file. A malformed sudoers file can corrupt your system. Never edit /etc/sudoers directly. For example, if you make a mistake, you'll see this when exiting visudo.
visudo: >>> /etc/sudoers: syntax error near line 64 <<< What now? Options are: (e)dit sudoers file again e(x)it without saving changes to sudoers file (Q)uit and save changes to sudoers file (DANGER!)4. Whether the test is successful
Switch to new user
#su-example_userUse whoami to verify you are the new user, then test sudo access using sudo whoami , which should return root.
$ whoami example_user $ sudo whoami [sudo] password for example_user: rootThe new user account is ready for use. As a best practice, use this sudo user for server administration. You should avoid using root to perform maintenance tasks.
At this point, we have fully introduced how to create a new non-root account with sudo permissions on Ubuntu and CentOS systems. Next, you can share more tutorials.
Finally, we recommend the Brickworker VPS solution: Our blog provides a full solution for the Banwagonhost mover and real-time inventory detection (laoliublog.cn)
Recommended site search: Wanwang domain name registration official website, virtual host application, free virtual host application, website registration system, registration number, Hong Kong virtual host, mainland China permanent free cloud server, Korean cn2 server US domain name website, domain name free registration 0 yuan registration,
发表评论