将远程服务器设置为禁止使用root登录,在使用用户登录后,进入root权限失败
,这是由于在Centos上安装ftp服务时错误的批量修改了系统根目录全部文件的权限,导致进入root权限时出现报错:

sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

执行命令

chown root:root /etc/sudo.conf -R
chmod 4755 /usr/bin/sudo

执行sudo ,出现错误

su: Authentication failure

执行命令

chown -R root:root /etc/sudoers.d
chown root:root /etc/sudoers

执行sudo命令,出现错误

sudo: error in /etc/sudo.conf, line 19 while loading plugin "sudoers_policy"
sudo: /usr/libexec/sudo/sudoers.so must be owned by uid 0
sudo: fatal error, unable to load plugins

执行命令 =====》

chmod 644 /usr/libexec/sudo/sudoers.so
chown -R root /usr/libexec/sudo/

执行sudo,出现错误

sudo: /var/db/sudo/lectured is owned by uid 1000, should be 0
dog is not in the sudoers file.  This incident will be reported.

执行命令

chown root:root /var/db/sudo/lectured/

执行命令sudo,出现错误

dog is not in the sudoers file.  This incident will be reported.

执行命令

[root@myyuncentos ~]# chmod u+x /etc/sudoers
[root@myyuncentos ~]# vi /etc/sudoers

找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
执行命令

chmod u-w /etc/sudoers

在执行sudo,输入密码可以进入root权限了====》

在sudoers文件中,可以sudoers添加下面四行中任意一条
youuser ALL=(ALL) ALL  //允许用户youuser执行sudo命令(需要输入密码).
%youuser ALL=(ALL) ALL	//允许用户组youuser里面的用户执行sudo命令(需要输入密码).
youuser ALL=(ALL) NOPASSWD: ALL   //允许用户youuser执行sudo命令,并且在执行的时候不输入密码.
%youuser ALL=(ALL) NOPASSWD: ALL   //允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码.
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐