1.創建一個 xiaoyang 用戶
[root@VM_81_181_centos ~]# adduser xiaoyang
2.為創建的用戶設置密碼
[root@VM_81_181_centos ~]# passwd xiaoyang Changing password for user xiaoyang. New password: BAD PASSWORD: The password contains the user name in some form Retype new password: Sorry, passwords do not match. New password: Retype new password: passwd: all authentication tokens updated successfully.
3.對創建的新用戶進行sudo操作的授權
說明:sudo 命令是在sudoers文件中的
[root@VM_81_181_centos ~]# whereis sudoers sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
4.查看文件權限
[root@VM_81_181_centos ~]# ls -l /etc/sudoers -r--r-----. 1 root root 3938 Jun 7 2017 /etc/sudoers
可以看到只有只讀的權限,這個時候我們需要加入一個可寫(w)的權限
5.加入可寫的權限
[root@VM_81_181_centos ~]# chmod -v u+w /etc/sudoers mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
6.將xiaoyang用戶添加至sudoers文件中
[root@VM_81_181_centos ~]# vi /etc/sudoers ## Allow root to run any commands anywher root ALL=(ALL) ALL admin ALL=(ALL) ALL
7.將sudoers文件權限改回去
[root@VM_81_181_centos ~]# chmod -v u-w /etc/sudoers
8.測試新用戶xiaoyang進行登陸,使用su xiaoyang操作:
[root@VM_81_181_centos ~]# su xiaoyang [xiaoyang@VM_81_181_centos root]$