在VM中安装CentOs后无法切换到root用户

一、问题描述:刚装好的CentOs7 64位系统,运行 (sudo) yum install sz 后显示

      wang is not in the sudoers file . this incident will be reported

      you need to be root to perform this command

这个时候试过了 ” su - “ 也是显示wang is not in the sudoers file . this incident will be reported

1、直接输入 " su " 后可以进入一个如下的root伪权限中,

        在VM中安装CentOs后无法切换到root用户

2、然后添加文件的写权限。也就是输入命令"chmod u+w /etc/sudoers"。

3、编辑/etc/sudoers文件。也就是输入命令"vim /etc/sudoers",输入"i"进入编辑模式,找到这一 行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(这里的xxx是你的用户名),然后保存(就是先按一 下Esc键,然后输入":wq")退出。如下,就可以了。  

在VM中安装CentOs后无法切换到root用户