在使用 Centos 之前用的更多是Ubuntu,所以在 useradd 和 adduser 兩條命令出現歧義,在Ubuntu系統上這是兩條命令,而在Centos上則是同一條命令,adduser 是鏈接的形式存在
1
2
3
|
# 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 沒有任何交互動作!創建用戶完畢后,必須修改密碼否則無法登陸
1
2
3
4
5
6
|
# useradd dev #創建用戶 # passwd dev #修改密碼 更改用戶 dev 的密碼 。 新的 密碼: 重新輸入新的 密碼: passwd:所有的身份驗證令牌已經成功更新。 |
2、為新建用戶添加 sudo 權限,否則啥事都要請教 root 老大不合適,你懂得!
1)sudoers 文件添加可寫權限
1
2
|
# chmod -v u+w /etc/sudoers "/etc/sudoers" 的權限模式保留為0640 (rw-r-----) |
2)在 sudoers 文件添加新用戶信息到 ## Allow root to run any commands anywher 下,修改后的效果為
1
2
3
|
## Allow root to run any commands anywher root ALL=(ALL) ALL dev ALL=(ALL) ALL #新增用戶信息 |
3)取消 sudoers 文件可寫權限
1
2
|
# 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
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://blog.csdn.net/johnnycode/article/details/40655857