centOS添加新用戶


Linux:CentOS7.4新建用戶並授權

 

之前買了一台阿里雲服務器,准備用來搭建一些服務,由於使用root用戶登錄進行操作比較敏感,就新建了一個用戶,用來登錄並進行日常操作。

這篇博客,介紹下centos7.4下如何新建用戶並且授權。。。

 

一、創建新用戶

1、創建一個新用戶:prefma

 [root@localhost ~]# adduser prefma 

2、為新用戶創建初始化密碼

[root@localhost~]# passwd prefma
Changing password for user prefma.
New password:             # 輸入密碼
Retype new password:      # 再次輸入密碼
passwd: all authentication tokens updated successfully.

 

二、授權

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

新創建的用戶並不能使用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、新用戶登錄

新建連接,使用新創建的用戶登錄,並進行驗證,比如:

[prefma@localhost~]$ pwd
/home/prefma
[prefma@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers

 

更多關於Linux和centos的內容,可以關注Linux公社。。。

 

轉載請注明出處,商用請征得作者本人同意,謝謝!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM