centOS7:创建的新用户如何获得写权限
要在root用戶下使用
1.新建用戶
adduser testuser //新建testuser 用戶
passwd testuser //給testuser 用戶設(shè)置密碼
2、賦予root權(quán)限
方法一:修改 /etc/sudoers 文件,找到下面一行,把前面的注釋(#)去掉
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
然后修改用戶,使其屬于root組(wheel),命令如下:
#usermod -g root tommy
修改完畢,現(xiàn)在可以用tommy帳號(hào)登錄,然后用命令su -,即可獲得root權(quán)限進(jìn)行操作。
方法二:修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL
修改完畢,現(xiàn)在可以用tommy帳號(hào)登錄,然后用命令 su - ,即可獲得root權(quán)限進(jìn)行操作。
方法三:修改 /etc/passwd 文件,找到如下行,把用戶ID修改為 0 ,如下所示:
tommy:x:500:500:tommy:/home/tommy:/bin/bash
修改后如下
tommy:x:0:500:tommy:/home/tommy:/bin/bash
保存,用tommy賬戶登錄后,直接獲取的就是root帳號(hào)的權(quán)限。
友情提醒:雖然方法三看上去簡(jiǎn)單方便,但一般不推薦使用,推薦使用方法二。
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.改變組權(quán)限,給予寫權(quán)限
[root@centos7 www]# chmod -R 775 html2 [root@centos7 www]# ll
5.建工作組
groupadd testgroup //新建test工作組
6..新建用戶同時(shí)增加工作組
useradd -g testgroup testuser //新建testuser用戶并增加到testgroup工作組
//注::-g 所屬組 -d 家目錄 -s 所用的SHELL
7.給已有的用戶增加工作組
usermod -G groupname username
8.臨時(shí)關(guān)閉
在/etc/shadow文件中屬于該用戶的行的第二個(gè)字段(密碼)前面加上就可以了。想恢復(fù)該用戶,去掉即可
//或者使用如下命令關(guān)閉用戶賬號(hào):
passwd testuser –l
//重新釋放:
passwd testuser –u
9.永久性刪除用戶賬號(hào)
userdel testuser
groupdel testgroup
usermod –G testgroup testuser //(強(qiáng)制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)
10.顯示用戶信息
id user
cat /etc/passwd
補(bǔ)充:查看用戶和用戶組的方法
用戶列表文件:/etc/passwd
用戶組列表文件:/etc/group
查看系統(tǒng)中有哪些用戶:cut -d : -f 1 /etc/passwd
查看可以登錄系統(tǒng)的用戶:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
查看用戶操作:w命令(需要root權(quán)限)
查看某一用戶:w 用戶名
查看登錄用戶:who
查看用戶登錄歷史記錄:last
2.建工作組
groupadd testgroup //新建test工作組
3.新建用戶同時(shí)增加工作組
useradd -g testgroup testuser //新建testuser用戶并增加到testgroup工作組
//注::-g 所屬組 -d 家目錄 -s 所用的SHELL
4.給已有的用戶增加工作組
usermod -G groupname username
5.臨時(shí)關(guān)閉
在/etc/shadow文件中屬于該用戶的行的第二個(gè)字段(密碼)前面加上就可以了。想恢復(fù)該用戶,去掉即可
//或者使用如下命令關(guān)閉用戶賬號(hào):
passwd testuser –l
//重新釋放:
passwd testuser –u
6.永久性刪除用戶賬號(hào)
userdel testuser
groupdel testgroup
usermod –G testgroup testuser //(強(qiáng)制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)
7.顯示用戶信息
id user
cat /etc/passwd
補(bǔ)充:查看用戶和用戶組的方法
用戶列表文件:/etc/passwd
用戶組列表文件:/etc/group
查看系統(tǒng)中有哪些用戶:cut -d : -f 1 /etc/passwd
查看可以登錄系統(tǒng)的用戶:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
查看用戶操作:w命令(需要root權(quán)限)
查看某一用戶:w 用戶名
查看登錄用戶:who
查看用戶登錄歷史記錄:last
總結(jié)
以上是生活随笔為你收集整理的centOS7:创建的新用户如何获得写权限的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: oracle 11g函数包缓存,Orac
- 下一篇: php时间比现实时间慢8个小时,关于PH