ubuntu22.04桌面版默认不支持root用户登陆,测试环境每次都要敲个sudo,实在麻烦

  1. 先给root用户设置密码
    1
    sudo passwd root
  2. 将下面两个文件/etc/pam.d/gdm-password/etc/pam.d/gdm-autologin中的一行代码
    1
    auth required pam_succeed_if.so user != root quiet_success
  3. 修改/root/.profile文件
    1
    2
    - mesg n 2> /dev/null || true
    + tty -s && mesg n || true
  4. 修改/etc/gdm3/custom.conf,没有这个文件就在设置里开启自动登录,或者自己创建
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    # GDM configuration storage
    #
    # See /usr/share/gdm/gdm.schemas for a list of available options.

    [daemon]
    AutomaticLoginEnable=true
    - AutomaticLogin=pblood
    + AutomaticLogin=root

    # Uncomment the line below to force the login screen to use Xorg
    #WaylandEnable=false

    # Enabling automatic login

    # Enabling timed login
    # TimedLoginEnable = true
    # TimedLogin = user1
    # TimedLoginDelay = 10

    [security]

    [xdmcp]

    [chooser]

    [debug]
    # Uncomment the line below to turn on debugging
    # More verbose logs
    # Additionally lets the X server dump core if it crashes
    #Enable=true

另外,桌面版也不支持root用户远程登陆,下面是开启方法

  1. 安装openssl-server
    1
    apt install openssh-server
  2. 修改/etc/ssh/sshd_config文件
    1
    2
    - #PermitRootLogin prohibit-password
    + PermitRootLogin yes
  3. 重启ssh服务
    1
    service ssh restart
    测试:
    1
    ssh root@localhost