Centos7 添加用户及设置权限
Centos7 添加用户及设置权限

Centos7 添加用户及设置权限

一、添加用户

1、登录root 用户

[gau@localhost /]$ su
Password:   # 输入密码

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 ( 删除文件夹)

发表回复

您的电子邮箱地址不会被公开。