ubuntu 16.04默认root登录

ubuntu 16.04默认root登录

在笔者使用docker过程中,docker的操作命令之前都需要加上sudo。如果不想加上sudo,则需要在shell中先切换到root,即使用命令su root。但是,每启动一个终端都需要重新切换到root。所以,为了偷懒,笔者希望一开始就使用root账户登录~~

为root设置密码

如果之前没有切换过root,那么root账户是没有设置密码的,需要先为其设置密码。

sudo passwd root

然后输入密码即可,输出信息如下。

nelson@ubuntu:~$ sudo passwd root
[sudo] password for nelson: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

设置root启动

首先在配置文件中设置root自启。

使用如下命令编辑/etc/lightdm/lightdm.conf

sudo gedit /etc/lightdm/lightdm.conf

然后在打开的gedit中写入如下信息。

[Seat:*]
autologin-guest=false
autologin-user=root
autologin-user-timeout=0
greeter-session=lightdm-gtk-greeter 

保存退出。

然后使用如下命令编辑/root/.profile,加上tty -s &&

sudo gedit /root/.profile

注意,/root/.profile文件是有如下内容的

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n || true

加上tty -s &&后如下所示

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

tty -s && mesg n || true

保存退出,然后重启即可

扫描二维码关注公众号,回复: 12611091 查看本文章

猜你喜欢

转载自blog.csdn.net/NelsonCheung/article/details/109163865