centos新增用戶以及賦權

新增用戶命令如下:

#adduser test //添加一個名爲test的新用戶
#passwd test //修改密碼

Changing password for user test //提示你更改修改密碼
New password: //輸入密碼

輸入密碼後,要是密碼太短或者太簡單的話會提示:

BAD PASSWORD : The password is shorter than 8 characters

Retype new password: //重新輸入密碼

passwd: all authentication tokens updated successfully //新增用戶成功

授權命令如下:

首選進入 /etc 目錄找到sudoers這個文件,如果沒看到的話直接輸入:
#whereis sudoers //查找sudoers文件位置

然後查看該文件的權限,若是隻讀權限的話我們是無法對其進行更改的。
# ls -l /etc/sudoers //查看sudoers權限
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers //該文件只有讀取權限,需更改

# chmod -v u+w /etc/sudoers //添加sudoers文件修改權限
/etc/sudoers" 的權限模式保留爲0640 (rw-r-----) //添加成功

#vim /etc/sudoers //編輯sudoers文件

輸入 i 進入編輯模式,在

 ## Allow root to run any commands anywher  
    root    ALL=(ALL)        ALL 

下面添加:

test    ALL=(ALL)        ALL 

然後esc退出編輯模式,輸入::wq!進行保存退出

但不要忘記撤銷sudoers的寫權限:

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

然後用test賬號登陸,用命令:sudo就可以獲取root權限進行操作

用戶組操作

#groupadd testgroup //新建testgroup工作組

#useradd -g testgroup testuser //新建testuser用戶並增加到#testgroup工作組

#usermod -G groupname username //給現有的用戶增加工作組

#userdel testuser //刪除用戶
#groupdel testgroup // 刪除用戶組

文件地址:

#/etc/passwd    //用戶列表文件
#/etc/group      //用戶組列表文件

其他命令:

#cut -d : -f 1 /etc/passwd  //查看系統中所有用戶

#cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1  //查看可以登錄系統的用戶

#w 命令   //查看用戶操作(需要root權限)  

#w  username   //查看某一用戶

#who   // 查看登錄用戶

#last //查看用戶登錄歷史記錄
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章