linux管理之:普通用户切换root用户
都知道root用户在linux中有莫大的权限,但也容易出错,如果用了root权限,改了配置文件,就容易导致系统出问题,所以通常情况下,不能使用root用户。
从普通用户怎么能切换到root用户呢?有两种方法,如下:
第一:
使用命令 su - root 命令 :这个从相当于古代的农民起义,把root干掉,自己来当root。
例:
[test@moban ~]$ pwd
/home/test
[test@moban ~]$ su - root
Password:
[root@moban ~]#
第二:
使用命令 sudo配置文件,给普通用户加上的root权限
配置方法:
[root@moban ~]# visudo #编辑sudo ,不管这个是什么,直接打命令即可。
root ALL=(ALL) ALL #找到这一行
test ALL=(ALL) NOPASSWD:ALL #在上一行后面,加上这一行。这意思就是说,把test用户制授权为root用户的全部权力,并且不用密码。
[test@moban ~]$ useradd yyy
-bash: /usr/sbin/useradd: Permission denied #提示没权力 ,那是因为没有用sudo.
[test@moban ~]$ sudo useradd yyy
[test@moban ~]$ sudo passwd yyy
Changing password for user yyy.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
这样就可以了,这就是授权普通用户root权限。当你不是root的时候,也能执行root的权力了