前言
最近在筆記本裝了一個(gè)centos,想要讓別人也可以登錄訪(fǎng)問(wèn),用自己的賬號(hào)確實(shí)不太好,于是準(zhǔn)備新建一個(gè)用戶(hù)給他。發(fā)現(xiàn)網(wǎng)站這方便的資料比較少,所以將自己實(shí)現(xiàn)的步驟總結(jié)分享出來(lái),話(huà)不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹:
創(chuàng)建新用戶(hù)
創(chuàng)建一個(gè)用戶(hù)名為:zhangbiao
[root@localhost ~]# adduser zhangbiao
為這個(gè)用戶(hù)初始化密碼,linux會(huì)判斷密碼復(fù)雜度,不過(guò)可以強(qiáng)行忽略:
[root@localhost ~]# passwd zhangbiao更改用戶(hù) zhangbiao 的密碼 。新的 密碼:無(wú)效的密碼: 密碼未通過(guò)字典檢查 - 過(guò)于簡(jiǎn)單化/系統(tǒng)化重新輸入新的 密碼:passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新。
授權(quán)
個(gè)人用戶(hù)的權(quán)限只可以在本home下有完整權(quán)限,其他目錄要看別人授權(quán)。而經(jīng)常需要root用戶(hù)的權(quán)限,這時(shí)候sudo可以化身為root來(lái)操作。我記得我曾經(jīng)sudo創(chuàng)建了文件,然后發(fā)現(xiàn)自己并沒(méi)有讀寫(xiě)權(quán)限,因?yàn)椴榭礄?quán)限是root創(chuàng)建的。
新創(chuàng)建的用戶(hù)并不能使用sudo命令,需要給他添加授權(quán)。
sudo命令的授權(quán)管理是在sudoers文件里的。
可以看看sudoers:
[root@localhost ~]# sudoersbash: sudoers: 未找到命令...[root@localhost ~]# whereis sudoerssudoers: /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
是的,只有只讀的權(quán)限,如果想要修改的話(huà),需要先添加w權(quán)限:
[root@localhost ~]# chmod -v u+w /etc/sudoersmode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加內(nèi)容了,在下面的一行下追加新增的用戶(hù):
[root@localhost ~]# vim /etc/sudoers## Allow root to run any commands anywher root ALL=(ALL) ALL zhangbiao ALL=(ALL) ALL #這個(gè)是新增的用戶(hù)
wq保存退出,這時(shí)候要記得將寫(xiě)權(quán)限收回:
[root@localhost ~]# chmod -v u-w /etc/sudoersmode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
這時(shí)候使用新用戶(hù)登錄,使用sudo:
[zhangbiao@localhost ~]$ sudo cat /etc/passwd[sudo] password for zhangbiao: We trust you have received the usual lecture from the local SystemAdministrator. 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.
第一次使用會(huì)提示你,你已經(jīng)化身超人,身負(fù)責(zé)任。而且需要輸入密碼才可以下一步。如果不想需要輸入密碼怎么辦,將最后一個(gè) ALL 修改成 NOPASSWD: ALL 。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)VEVB武林網(wǎng)的支持。
新聞熱點(diǎn)
疑難解答
圖片精選