CentOS 7中添加一個新用戶並受權

CentOS 7中添加一個新用戶並受權

[日期:2016-11-26] 來源:Linux社區  做者:woshimrf [字體:  ]

 

 

前言

筆記本安裝了一個CentOS,想要讓別人也能夠登陸訪問,用本身的帳號確實不太好,因而準備新建一個用戶給他。linux

建立新用戶

建立一個用戶名爲:linuxidcvim

[root@localhost ~]# adduser linuxidc

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

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

受權

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

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

sudo命令的受權管理是在sudoers文件裏的。能夠看看sudoers:code

[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

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

[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月  25 15:08 /etc/sudoers

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

[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

而後就能夠添加內容了,在下面的一行下追加新增的用戶:get

[root@localhost ~]# vim /etc/sudoers


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

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

[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

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

[linuxidc@localhost ~]$ sudo cat /etc/passwd
[sudo] password for linuxidc: 

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

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新連接地址http://www.linuxidc.com/Linux/2016-11/137549.htm

相關文章
相關標籤/搜索