Tutorial on how to add a non-root account with sudo permissions on CentOS system

888u

Last update at :2024-01-30,Edit by888u

In the previous article, we introduced how to create a non-root user account with sudo permissions in the Ubuntu operating system. For details, see: How to create a non-root user account with sudo permissions in the Ubuntu system. Today we will introduce how to create a non-root user account with sudo permissions in the Ubuntu system. How to create a non-root account with sudo permissions in the system. 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

Add new user account

Use the adduser command to create a new user account.

# adduser example_user

Use 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.

Add users to wheel group

Use usermod to add new users to the wheel group.

# usermod -aG wheel example_user

Edit Sudoers file

Use visudo to check the sudoers file.

#visudo

Look 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) ALL

Save 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!)

Whether the test was successful

Switch to new user

#su-example_user

Use 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: root

The 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.

Recommended plan for bricklayers

Warm reminder: If you have difficulty choosing, just choose the CN2 GIA-E plan in the middle. The quarterly payment is $49.99, and you can switch between up to 12 computer rooms at will. plan Memory CPU harddisk Traffic/month bandwidth engine room price Buy Banwagonhost Discount Code: BWH3HYATVBJW
CN2 (cheapest) 1GB 1 core 20GB 1TB 1Gbps DC3 CN2 DC8 ZNET $49.99/year Buy
CN2 2GB 1 core 40GB 2TB 1Gbps $52.99/half year $99.99/year Buy
CN2 GIA-E (Most recommended) 1GB 2 cores 20GB 1TB 2.5Gbps DC6 CN2 GIA-E DC9 CN2 GIA Japan SoftBank JPOS_1 Netherlands EUNL_9 $49.99/quarter $169.99/year Buy
CN2 GIA-E 2GB 3 core 40GB 2TB 2.5Gbps $89.99/quarter $299.99/year Buy
HK 2GB 2 cores 40GB 0.5TB 1Gbps Hong Kong, China CN2 GIA $89.99/month $899.99/year Buy
HK 4GB 4 core 80GB 1TB 1Gbps $155.99/month $1559.99/year Buy
TOKYO 2GB 2 cores 40GB 0.5TB 1.2Gbps Tokyo, Japan CN2 GIA $89.99/month $899.99/year Buy
TOKYO 4GB 4 core 80GB 1TB 1.2Gbps $155.99/month $1559.99/year Buy

Select a suggestion:

  • Getting started: Los Angeles CN2 package, currently the cheapest, optional CN2 GT computer room, the entry-level choice.
  • Recommendation: Los Angeles CN2 GIA-E package, super fast, with many optional computer rooms (DC6, DC9, Japan SoftBank, Netherlands Unicom, etc.), the most cost-effective.
  • High-end: Hong Kong CN2 GIA package, the price is higher, but impeccable. The Tokyo CN2 GIA package is also a very good high-end option.

Recommended site search: How much does it cost to rent a server for a year, free IP proxy server, US PHP space, free space, server Hong Kong, same IP site query, free domain name, domain name registration website query, foreign website space, cloud host,

Tutorial on how to add a non-root account with sudo permissions on CentOS system

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码