centos 7中添加一個新用戶並受權的步驟詳解

1.建立新用戶:


建立一個用戶名爲:zhangbiao

  1 adduser zhangbiao 

爲這個用戶初始化密碼,linux會判斷密碼複雜度,不過能夠強行忽略:

   1 passwd zhangbiao  更改用戶 zhangbiao 的密碼 。 新的 密碼: 無效的密碼: 密碼未經過字典檢查 - 過於簡單化/系統化 從新輸入新的 密碼: passwd:全部的身份驗證令牌已經成功更新。

2.受權:


我的用戶的權限只能夠在本home下有完整權限,其餘目錄要看別人受權。而常常須要root用戶的權限,這時候sudo能夠化身爲root來操做。我記得我曾經sudo建立了文件,而後發現本身並無讀寫權限,由於查看權限是root建立的。

新建立的用戶並不能使用sudo命令,須要給他添加受權。

sudo命令的受權管理是在sudoers文件裏的。

能夠看看sudoers:

  1 whereis sudoers sudoers :
 
 /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

找到這個文件位置以後再查看權限:

  1 ls -l /etc/sudoers  
 
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers

是的,只有只讀的權限,若是想要修改的話,須要先添加w權限:

   1 chmod -v u+w /etc/sudoers 
 
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

而後就能夠添加內容了,在下面的一行下追加新增的用戶:
 
1 vim /etc/sudoers 
2 ## Allow root to run any commands anywher 
3 root ALL=(ALL) ALL
4 zhangbiao ALL=(ALL) ALL #這個是新增的用戶

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

  1 chmod -v u-w 
 
 /etc/sudoers mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

這時候使用新用戶登陸,使用sudo:

  1 sudo cat /etc/passwd [sudo] password for zhangbiao: 
 
 We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.

第一次使用會提示你,你已經化身超人,身負責任。並且須要輸入密碼才能夠下一步。若是不想須要輸入密碼怎麼辦,將最後一個 ALL 修改爲 NOPASSWD: ALL 。
原文連接:https://m.jb51.net/article/120366.htm
相關文章
相關標籤/搜索