Linux系统设置默认用户为root并自动登录(详解,包含Centos及Ubuntu系统)

一、Centos系统

1、普通用户登录后先给超级用户root创建密码

2、通过su指令切换至root用户

3、更改文件默认登录账户为root


打开 /etc/gdm/custom.conf
vi /etc/gdm/custom.conf或者nano /etc/gdm/custom.conf(看自己熟练哪个用哪个命令)


在文件[daemon]下写入(注意:在这个下面写入,别的地方写入无效!):
AutomaticLoginEnable=True
AutomaticLogin=root

然后保存出来重启Reboot

二、Ubuntu系统


1、 为root设置密码并测试登录退出


打开终端开启root账户,设置密码 :

sudo passwd  root

 测试root用户登录

su -
登录成功后即可注销为普通用户继续之后的操作

exit


2、修改50-ubuntu.conf配置文件内容


文件位置 /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf(如果没有此文件,就到这个目录找类似文件)
sudo  chmod  777  /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
在文件末尾加入两行代码
greeter-show-manual-login=true
all-guest=false

3、修改gdm-autologin和gdm-passwd文件


进入/etc/pam.d文件夹下,找到gdm-autologin和gdm-passwd文件(没有的话找类似文件)
sudo  chmod  777 /etc/pam.d/gdm-autologin
sudo  chmod  777 /etc/pam.d/gdm-password

两个文件都注释掉auth required pam_success_if.so user!=root quiet_success这一行


修改/root/.profile文件
找到要修改的.profile文件,此文件为隐藏文件,没有的话勾上选项框
开启root权限,打开文件,注释掉最后一行,然后加上一行
tty -s&&mesg n || true

4、找到custom.conf配置文件并修改


文件夹路径为/etc/gdm3/(没有的话找类似文件夹,例如:/gdm)

修改文件

TimedLoginEnable=false
AutomaticLoginEnable=true #设为true
TimedLogin=root #设成root
AutomaticLogin=root #设成root
TimedLoginDelay=10

AutomaticLoginEnable=true #设为true
AutomaticLogin=root #设为root

猜你喜欢

转载自blog.csdn.net/weixin_68971793/article/details/132965884
今日推荐