第一步:創建用戶並設置密碼
useradd testuser // 增加用戶名為'testuser'的用戶
passwd testpasswd //設定密碼為'testpasswd'
第二步:用戶授權
創建賬戶必須授權,不然,個人用戶的權限只可以在本home下有權限,其他的必須有授權,一般需要root的權限,sudo的命令授權一般在sudoers里面,找到sudoer文件位置,看下文件的權限
[root@iZ2ze503xw2q1fftv5rhboZ ~]# whereis sudoers sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
第三步:編輯sudoers文件並強制保存修改權限
[root@iZ2ze503xw2q1fftv5rhboZ ~]# vim /etc/sudoers [root@iZ2ze503xw2q1fftv5rhboZ ~]# chmod -v u+w /etc/sudoers //收回權限
mode of `/etc/sudoers' changed to 0640 (rw-r-----)
編輯增加內容
然后打開新的終端,登錄用戶,並切換root權限用戶測試,成功~
賦予root權限
方法一: 修改 /etc/sudoers 文件,找到%wheel一行,把前面的注釋(#)去掉
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
然后修改用戶,使其屬於root組(wheel),命令如下:
#usermod -g root testuser
修改完畢,現在可以用testuser帳號登錄,然后用命令 sudo su - ,即可獲得root權限進行操作。
方法二: 修改 /etc/sudoers 文件,找到root一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere root ALL=(ALL) ALL tommy ALL=(ALL) ALL
修改完畢,現在可以用testuser帳號登錄,然后用命令 sudo su - ,即可獲得root權限進行操作。
方法三: 修改 /etc/passwd 文件,找到如下行,把用戶ID修改為 0 ,如下所示:
testuser:x:500:500:tommy:/home/tommy:/bin/bash
修改后如下
testuser:x:0:500:tommy:/home/tommy:/bin/bash
保存,用testuser賬戶登錄后,直接獲取的就是root帳號的權限。
建議使用方法二,不要輕易使用方法三。