天天看點

CentOS 7中添加一個新使用者并授權

建立新使用者

建立一個使用者名為:hadoop

為這個使用者初始化密碼,linux會判斷密碼複雜度,不過可以強行忽略:

[[email protected] ~]# passwd hadoop
Changing password for user hadoop.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
           

授權

新建立的使用者并不能使用sudo指令,需要給他添加授權。

sudo指令的授權管理是在sudoers檔案裡的。可以看看sudoers:

[[email protected] ~]# whereis sudoers
sudoers: /etc/sudoers.d /etc/sudoers /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.gz
           

找到這個檔案位置之後再檢視權限:

[[email protected] ~]# ls -l /etc/sudoers
-r--r-----. 1 root root 4002 Mar  1  2012 /etc/sudoers
           

是的,隻有隻讀的權限,如果想要修改的話,需要先添加w權限:

[[email protected] ~]# chmod -v u+w /etc/sudoers
mode of `/etc/sudoers' changed to 0640 (rw-r-----)
           

然後就可以添加内容了,在下面的一行下追加新增的使用者:

[[email protected] ~]# vim /etc/sudoers

## Allow root to run any commands anywher  
root    ALL=(ALL)       ALL  
linuxidc  ALL=(ALL)       ALL  #這個是新增的使用者
           

wq儲存退出,這時候要記得将寫權限收回:

[[email protected] ~]# chmod -v u-w /etc/sudoers
mode of `/etc/sudoers' changed to 0440 (r--r-----)
           

這時候使用新使用者登入了,并且可以是用sudo