在 Ubuntu GUI 中以 root 身份登录
root
![](/data/attachment/album/202302/28/104536gesxvetse1rrru4q.jpg)


默认情况下，Ubuntu 禁用了 root 账户。你必须使用 `sudo` 命令来执行任何需要 root 权限的任务。


当然，这是为了你自己的安全。一直以 root 身份使用系统，就像手里拿着一把剑到处跑。它增加了把事情搞乱的机会。


以 root 身份登录在服务器中仍然很常见。在桌面方面，以 root 身份登录的情况相当少见。甚至 Kali Linux 也做了改变。


然而，有一些桌面用户想以 root 身份登录。这不是什么明智之举，但肯定是可以做到的。


在本指南中，我将向你展示如何在 Ubuntu 中 **以 root 身份登录 GNOME 桌面**。


### 如何在 GNOME 桌面上以 root 身份登录



> 
> ? 我不建议在桌面上以 root 身份登录。你有 sudo 机制来满足你所有的 root 需求。只有在你有足够理由的情况下才这样做。本教程仅用于演示目的。你已经被警告过了。
> 
> 
> 


#### 步骤 1：启用 root 账户


你想以 root 身份登录。但默认情况下，root 账户是禁用的。第一步是启用它。


改变 root 账户的密码，这将为你启用 root 账户：



```
sudo passwd root

```

![change the password of root account in ubuntu](/data/attachment/album/202302/28/104559wu07pjsd4p1ja7ja.png)


不言而喻，你不应该忘记 root 密码。


#### 步骤 2：改变 GDM 配置



> 
> ? 本教程的这一部分只对 GNOME 有效。请 [检查你的桌面环境](https://itsfoss.com/find-desktop-environment/) 并确保它是 GNOME。
> 
> 
> 


Ubuntu 默认使用 GNOME，GNOME 使用 GDM 显示管理器。


为了允许以 root 身份登录到 GNOME，你需要对位于 `/etc/gdm3/custom.conf` 的 GDM 配置文件做一些修改。


对该配置文件做一个备份：



```
cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf~

```

在最坏的情况下，如果你以某种方式把事情搞砸了，备份的文件可以用来从 TTY 上替换现有文件。


现在，用以下命令打开 GDM 文件：



```
sudo nano /etc/gdm3/custom.conf

```

并添加以下一行，允许 root 用户登录：



```
AllowRoot=true

```

![configure GDM on ubuntu](/data/attachment/album/202302/28/104600rw59b554oup960p6.png)


按 `Ctrl+X` 退出 Nano，同时保存它。


#### 步骤 3：配置 PAM 认证


现在，你必须配置 PAM 认证守护进程文件，它可以通过以下命令打开：



```
sudo nano /etc/pam.d/gdm-password

```

在这个文件中，你必须注释掉以下带有 `#` 号的一行，该符号拒绝 GUI 中的 root 访问：



```
auth   required        pam_succeed_if.so user != root quiet_success

```

![](/data/attachment/album/202302/28/104600jxyrhiffrlcf5p3f.gif)


[保存修改并退出 nano](https://linuxhandbook.com/nano-save-exit/) 文本编辑器。


#### 步骤 4：以 root 身份登录


现在，重启你的系统：



```
reboot

```

在登录界面，选择 `Not listed` 选项，在用户名中输入 `root`，并输入你在本指南开头配置的密码：


![Login as a root in ubuntu desktop](/data/attachment/album/202302/28/104600skw9i341pfu5kw13.png)


当你登录后，它就会通知你，**“logged in as a privileged user”**：


![logged in as a privileged user in Ubuntu](/data/attachment/album/202302/28/104601mwgdx2305rg0xd3a.png)


这就完成了! 现在，你正在以 root 身份运行你的 Ubuntu 系统。


### 以 root 用户身份运行系统时，你应该知道的事情


Ubuntu 默认禁用 root 账户是有原因的。想知道为什么吗？在这里你可以找到：



> 
> **[Ubuntu 中的 root 用户-你应该知道的重要事项](https://itsfoss.com/root-user-ubuntu/#what-is-root)**
> 
> 
> 


再说一遍，在你的桌面 Linux 系统中以 root 登录是不可取的。请遵守规范，远离这种（错误的）冒险。




---


via: <https://itsfoss.com/ubuntu-login-root/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

By default, Ubuntu disables the root account. You must use the sudo command for any tasks requiring root privileges.

This is for your own security, of course. Using the system as root all the time is like running around with a sword in your hand. It increases the chances of messing up things.

Logging in as root is still common in the servers. On the desktop side, it's quite rare to log in as root. Even Kali Linux has changed it.

And yet, a few desktop users want to log in as root. This is not something advisable but surely doable.

in this guide, I will show you how to **log in as a root in your GNOME desktop** using Ubuntu.

## How to login as a root in the GNOME desktop

### Step 1: Enable root account

You want to log in as root. But the root account is disabled by default. The first step is to enable it.

Change the root account password that will eventually enable the root account for you:

`sudo passwd root`


![change the password of root account in ubuntu](https://itsfoss.com/content/images/2023/01/change-the-password-of-root-account-in-ubuntu.png)

It goes without saying that you should not forget the root password.

### Step 2: Change GDM configuration

[check your desktop environment](https://itsfoss.com/find-desktop-environment/)and ensure that it is GNOME.

Ubuntu uses GNOME by default and GNOME uses the GDM display manager.

To allow log in as root into GNOME, you need to make some changes in the GDM configuration file located at `/etc/gdm3/custom.conf`

.

Make a backup of the config file:

```
cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf~
```


In the worst case, if you somehow mess things up, the back up file can be used to replace the existing one from the TTY.

Now, open the GDM file with the following command:

```
sudo nano /etc/gdm3/custom.conf
```


And add the following line to allow the root login:

`AllowRoot=true`


![configure GDM on ubuntu](https://itsfoss.com/content/images/2023/01/configure-GDM-on-ubuntu.png)

Press Ctrl+X to exit Nano while saving it.

### Step 3: Configure PAM authentication

Now, you will have to configure the PAM authentication daemon file, which can be opened by the following command:

`sudo nano /etc/pam.d/gdm-password`


In this file, you will have to comment out the following line with the `#`

symbol that denies the root access in GUI:

`auth required pam_succeed_if.so user != root quiet_success`


![](https://itsfoss.com/content/images/2023/01/configure-PAM-authentication-daemon-in-ubuntu.gif)

[Save changes and exit from the nano](https://linuxhandbook.com/nano-save-exit/) text editor.

### Step 4: Log in as root

Now, reboot your system:

`reboot`


At the login screen, select the `Not listed`

option, enter `root`

in username and enter the password that you configured at the beginning of this guide:

![Login as a root in ubuntu desktop](https://itsfoss.com/content/images/2023/01/Login-as-a-root-in-Ubuntu-desktop.png)

Once you log in, it will notify you by saying, **"logged in as a privileged user":**

![logged in as a privileged user in Ubuntu](https://itsfoss.com/content/images/2023/01/logged-in-as-a-privileged-user-in-Ubuntu.png)

That's it! Now, you are running your Ubuntu system as a root.

## Things you should know when running the system as a root user

There is a reason why Ubuntu disables a root account by default. Want to know why? Here you have it:

[Root User in Ubuntu- Important Things You Should KnowHow do you become root user in Ubuntu? Either you run commands with root privilege like this: sudo any_command Or you switch user in Ubuntu to root user like this: sudo su In both cases, you’ll have to enter your own user account’s password. But there’s](https://itsfoss.com/root-user-ubuntu/#what-is-root)![](https://itsfoss.com/content/images/wordpress/2020/01/root_user_ubuntu.png)


![](https://itsfoss.com/content/images/wordpress/2020/01/root_user_ubuntu.png)

And again, it is not advisable to log in a s root in your desktop Linux system. Please follow the norms and stay away from such (mis) adventures.