創(chuàng)建新用戶
創(chuàng)建一個(gè)用戶名為:cheng
[root@localhost ~]# adduser cheng
為這個(gè)用戶初始化秘密策州,linux會判斷密碼復(fù)雜度陷猫,不過可以強(qiáng)行忽略
[root@localhost ~]# passwd cheng
更改用戶 cheng 的密碼 祠乃。
新的 密碼:
無效的密碼: 密碼未通過字典檢查 - 過于簡單化/系統(tǒng)化
重新輸入新的 密碼:
passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新缴渊。
授權(quán)
個(gè)人用戶的權(quán)限只可以在本home下完成權(quán)限藐俺,其他目錄別人授權(quán)炊甲。而經(jīng)常需要root用戶的權(quán)限,這時(shí)候sudo可以化身為root來操作欲芹。新創(chuàng)建的用戶并不能使用sudo命令卿啡,需要給它添加授權(quán),sudo命令的授權(quán)管理在sudoers文件里的菱父,sudoers文件只有讀的權(quán)限颈娜,如果要寫需要加入權(quán)限
[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers // 查找sudoers的路徑
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
找到這個(gè)文件位置之后再查看權(quán)限
[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers
發(fā)現(xiàn)只有讀的權(quán)限,如果要修改浙宜,需要先添加w權(quán)限
[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加內(nèi)容官辽,在下面的一行追加新增的用戶:
[root@localhost ~]# vim /etc/sudoers
## Allow root to run any commands anywher
root ALL=(ALL) ALL
cheng ALL=(ALL) ALL #這個(gè)是新增的用戶
wq保存退出,收回sudoers的寫入權(quán)限:
[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
這時(shí)新用戶登錄就可以使用sudo了
[cheng@localhost ~]$ sudo cat /etc/passwd
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.
第一次使用會提示你粟瞬,你已經(jīng)化身超人同仆,身負(fù)責(zé)任。而且需要密碼才可以下一步裙品,如果不想需要輸入密碼俗批,可以將最后一個(gè)ALL修改成NOPASSWD:ALL俗或。
如果需要?jiǎng)h除用戶
userdel -rf cheng:刪除名稱為cheng的用戶
然后就可以ls -l /home查看,會返現(xiàn)cheng用戶沒有了