要在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