Centos7 添加用戶及設置權限


一、添加用戶

  • 1、登錄root 用戶

[gau@localhost /]$ su
Password:   # 輸入密碼
[root@localhost /]# 
  • 2、添加用戶
[root@localhost /]# useradd testuser
[root@localhost /]#
  • 3、設置用戶密碼
[root@localhost /]# passwd testuser
Changing password for user testuser.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost /]#

二、給該用戶添加root權限

  • 1、切換到root(#su)

  • 2、#chmod -v u+w /etc/sudoers 為sudoers添加可寫權限

  • 3、輸入vi sudoers,進入命令模式,按Insert,進入編輯模式

  • 4、在 sudoers 文件添加新用戶信息到 ## Allow root to run any commands anywhere 下,修改后的效果為

## Allow root to run any commands anywher
      root   ALL=(ALL)    ALL
      xxx    ALL=(ALL)    ALL #xxx為新增用戶

  • 5、保存:按Esc 后 輸入 :wq 保存並退出

  • 6、取消 sudoers 文件可寫權限     # chmod -v u-w /etc/sudoers

三、測試

1、普通用戶進入

2、#sudo mkdir test(創建的文件夾名)

3、#ls 查看目錄

4、#sudo rm -r test ( 刪除文件夾)
————————————————
版權聲明:本文為CSDN博主「喜歡海呀」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_25046261/article/details/78182536


免責聲明!

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



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