centOS7:創建的新用戶如何獲得寫權限


要在root用戶下使用

1.新建用戶 

adduser testuser //新建testuser 用戶 
passwd testuser //給testuser 用戶設置密碼

 

2、賦予root權限 


方法一: 修改 /etc/sudoers 文件,找到下面一行,把前面的注釋(#)去掉

## Allows people in group wheel to run all commands
%wheel    ALL=(ALL)    ALL

然后修改用戶,使其屬於root組(wheel),命令如下:

#usermod -g root tommy

修改完畢,現在可以用tommy帳號登錄,然后用命令 su - ,即可獲得root權限進行操作。

方法二: 修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
tommy   ALL=(ALL)     ALL

修改完畢,現在可以用tommy帳號登錄,然后用命令 su - ,即可獲得root權限進行操作。

方法三: 修改 /etc/passwd 文件,找到如下行,把用戶ID修改為 0 ,如下所示:

tommy:x:500:500:tommy:/home/tommy:/bin/bash

修改后如下

tommy:x:0:500:tommy:/home/tommy:/bin/bash

保存,用tommy賬戶登錄后,直接獲取的就是root帳號的權限。

友情提醒:雖然方法三看上去簡單方便,但一般不推薦使用,推薦使用方法二。
 
 
3.將文件所屬組改變
[root@centos7 www] ll
drwxr-xr-x 2 root root  4096 5月   6 01:49  html2
[root@centos7 www]# chown root:Abble html2

4.改變組權限,給予寫權限

[root@centos7 www]# chmod -R 775 html2
[root@centos7 www]# ll

 

 

5.建工作組 
groupadd testgroup //新建test工作組

6..新建用戶同時增加工作組 
useradd -g testgroup testuser //新建testuser用戶並增加到testgroup工作組

//注::-g 所屬組 -d 家目錄 -s 所用的SHELL

7.給已有的用戶增加工作組 
usermod -G groupname username

8.臨時關閉 
在/etc/shadow文件中屬於該用戶的行的第二個字段(密碼)前面加上就可以了。想恢復該用戶,去掉即可 
//或者使用如下命令關閉用戶賬號: 
passwd testuser –l 
//重新釋放: 
passwd testuser –u

9.永久性刪除用戶賬號 
userdel testuser 
groupdel testgroup 
usermod –G testgroup testuser //(強制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)

10.顯示用戶信息 
id user 
cat /etc/passwd

補充:查看用戶和用戶組的方法 
用戶列表文件:/etc/passwd 
用戶組列表文件:/etc/group 
查看系統中有哪些用戶:cut -d : -f 1 /etc/passwd 
查看可以登錄系統的用戶:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1 
查看用戶操作:w命令(需要root權限) 
查看某一用戶:w 用戶名 
查看登錄用戶:who 
查看用戶登錄歷史記錄:last

 

2.建工作組 
groupadd testgroup //新建test工作組

3.新建用戶同時增加工作組 
useradd -g testgroup testuser //新建testuser用戶並增加到testgroup工作組

//注::-g 所屬組 -d 家目錄 -s 所用的SHELL

4.給已有的用戶增加工作組 
usermod -G groupname username

5.臨時關閉 
在/etc/shadow文件中屬於該用戶的行的第二個字段(密碼)前面加上就可以了。想恢復該用戶,去掉即可 
//或者使用如下命令關閉用戶賬號: 
passwd testuser –l 
//重新釋放: 
passwd testuser –u

6.永久性刪除用戶賬號 
userdel testuser 
groupdel testgroup 
usermod –G testgroup testuser //(強制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)

7.顯示用戶信息 
id user 
cat /etc/passwd

補充:查看用戶和用戶組的方法 
用戶列表文件:/etc/passwd 
用戶組列表文件:/etc/group 
查看系統中有哪些用戶:cut -d : -f 1 /etc/passwd 
查看可以登錄系統的用戶:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1 
查看用戶操作:w命令(需要root權限) 
查看某一用戶:w 用戶名 
查看登錄用戶:who 
查看用戶登錄歷史記錄:last


免責聲明!

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



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