Centos7新增使用者和使用者組的方法
阿新 • • 發佈:2019-01-08
在使用 Centos 之前用的更多是Ubuntu,所以在 useradd 和 adduser 兩條命令出現歧義,在Ubuntu系統上這是兩條命令,而在Centos上則是同一條命令,adduser 是連結的形式存在
?123 | # ll /usr/sbin/ | grep user lrwxrwxrwx. 1 root root 7 10月 30 17:09 adduser -> useradd -rwxr-x---. 1 root root 114064 6月 10 09:16 useradd |
1、新增使用者,Centos 沒有任何互動動作!建立使用者完畢後,必須修改密碼否則無法登陸
?123456 | # useradd dev #建立使用者 # passwd dev #修改密碼 更改使用者 dev 的密碼 。 新的 密碼: 重新輸入新的 密碼: passwd:所有的身份驗證令牌已經成功更新。 |
2、為新建使用者新增 sudo 許可權,否則啥事都要請教 root 老大不合適,你懂得!
1)sudoers 檔案新增可寫許可權
?12 | # chmod -v u+w /etc/sudoers "/etc/sudoers" 的許可權模式保留為0640 (rw-r-----) |
2)在 sudoers 檔案新增新使用者資訊到 ## Allow root to run any commands anywher 下,修改後的效果為
?123 | ## Allow root to run any commands anywher root ALL=(ALL) ALL dev ALL=(ALL) ALL #新增使用者資訊 |
3)取消 sudoers 檔案可寫許可權
?12 | # chmod -v u-w /etc/sudoers mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----) |
建工作組
1 | groupadd test // 新建 test 工作組 |
新建使用者同時增加工作組
1 | useradd -g test phpq // 新建phpq使用者並增加到 test 工作組 |
注::-g 所屬組 -d 家目錄 -s 所用的SHELL
給已有的使用者增加工作組
1 | usermod -G groupname username 或者:gpasswd -a user group |
補充:檢視使用者和使用者組的方法
使用者列表檔案:/etc/passwd
使用者組列表檔案:/etc/group
檢視系統中有哪些使用者:cut -d : -f 1 /etc/passwd
檢視可以登入系統的使用者:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
檢視某一使用者:w 使用者名稱
檢視登入使用者:who
檢視使用者登入歷史記錄:last