做为非root用户执行服务器管理是安全方面的最佳实践。启动Vultr VPS以后,做为root用户的第一个任务应该是设置一个具备sudo访问权的非root用户。安全
本文适用于如下版本:
Ubuntu 20.04 LTS
Ubuntu 19.10
Ubuntu 18.04 LTS
Ubuntu 16.04 LTS服务器
步骤1:添加一个新用户账户测试
使用adduser命令建立一个新的用户账户。为新用户使用强密码。您能够为用户信息输入值,或者按enter将这些字段留空。code
# adduser example_user
Adding user `example_user' ...
Adding new group `example_user' (1001) ...
Adding new user `example_user' (1001) with group `example_user' ...
Creating home directory `/home/example_user' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for example_user
Enter the new value, or press ENTER for the default
Full Name []: Example User
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
步骤2:将用户添加到Sudo组orm
使用usermod将新用户添加到sudo组。it
# usermod -aG sudo example_user
步骤3:测试io
切换到新用户。form
# su - example_user
验证您是使用whoami的新用户,而后使用sudo whoami测试sudo访问,它应该返回root。date
$ whoamiexample_user$ sudo whoami[sudo] password for example_user:root
结论file
新的用户账户能够使用了。做为一种最佳实践,使用这个sudo用户进行服务器管理。您应该避免使用root执行维护任务。