如何在centos下創(chuàng)建新用戶名和密碼

如何在centos下創(chuàng)建新用戶名和密碼?

一、創(chuàng)建新用戶

1、創(chuàng)建一個新用戶:prefma

[root@localhost ~]# adduser prefma

2、為新用戶創(chuàng)建初始化密碼

[root@localhost~]# passwd prefma

Changing password foruser prefma.

New password:???????????? # 輸入密碼

Retype newpassword:????? # 再次輸入密碼

passwd: all authentication tokens updated successfully.

二、授權

個人用戶的權限只可以在本home下有完整權限,其他目錄需要別人授權。經(jīng)常需要root用戶的權限,可以通過修改sudoers文件來賦予權限。

新創(chuàng)建的用戶并不能使用sudo命令,需要給他添加授權。

1、查找sudoers文件路徑并賦予權限

1 [root@localhost~]# whereis sudoers???????????????????? # 查找sudoers文件路徑

2 sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz

3 [root@localhost~]# ls -l /etc/sudoers????????????????? # 查看權限

4 -r--r----- 1 root root 3938 Sep? 6? 2017 /etc/sudoers? # 只有讀權限

5 [root@localhost~]# chmod-v u+w /etc/sudoers?????????? # 賦予讀寫權限

6 mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)

2、修改sudoers文件

輸入命令?vim /etc/sudoers?修改sudoers文件,添加新用戶信息:

## Allow root to run any commands anywhere

root ALL=(ALL) ALL

prefma ALL=(ALL) ALL #這個是新用戶

然后輸入命令 wq! 保存修改。

3、收回權限

[root@localhost~]# chmod-v u-w /etc/sudoers

mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)

4、新用戶登錄

新建連接,使用新創(chuàng)建的用戶登錄,并進行驗證,比如:

[prefma@localhost~]$ pwd

/home/prefma

[prefma@localhost~]$ ls -l /etc/sudoers

-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers

本文來自PHP中文網(wǎng)的centos教程欄目:https://www.php.cn/centos/

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容