Centos6增加新用户并赋予权限

第一步:创建用户并设置密码

useradd testuser  // 增加用户名为'testuser'的用户
passwd testpasswd  //设定密码为'testpasswd'

第二步:用户授权

创建账户必须授权,不然,个人用户的权限只可以在本home下有权限,其他的必须有授权,一般需要root的权限,sudo的命令授权一般在sudoers里面,找到sudoer文件位置,看下文件的权限

[root@iZ2ze503xw2q1fftv5rhboZ ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz

第三步:编辑sudoers文件并强制保存修改权限

[root@iZ2ze503xw2q1fftv5rhboZ ~]# vim /etc/sudoers
[root@iZ2ze503xw2q1fftv5rhboZ ~]# chmod -v u+w /etc/sudoers  //收回权限
mode of `/etc/sudoers' changed to 0640 (rw-r-----)

编辑增加内容

然后打开新的终端,登录用户,并切换root权限用户测试,成功~

赋予root权限
方法一: 修改 /etc/sudoers 文件,找到%wheel一行,把前面的注释(#)去掉

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

然后修改用户,使其属于root组(wheel),命令如下:

#usermod -g root testuser

修改完毕,现在可以用testuser帐号登录,然后用命令 sudo su - ,即可获得root权限进行操作。

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

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

修改完毕,现在可以用testuser帐号登录,然后用命令 sudo su - ,即可获得root权限进行操作。

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

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

修改后如下

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

保存,用testuser账户登录后,直接获取的就是root帐号的权限。

 

建议使用方法二,不要轻易使用方法三。

posted @ 2018-01-15 16:02  温柔的风  阅读(5817)  评论(0编辑  收藏  举报