惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - emanlee

ubuntu 设置北京日期时间 mysql 在新电脑上导入,出现错误:ERROR at line 4019: Unknown command '\''. - emanlee 安装 yarn npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本。 - emanlee VS code, 最近打开过哪些项目或文件夹,把这些备份下来,到另外一台电脑上恢复 傲梅分区助手 【好用】 ubuntu 可以使用Windows远程桌面连接吗?【可以】 把xshell的全部连接和密码,从一台Windows 10电脑,迁移到Windows11电脑。 Windows 远程桌面(mstsc)完整迁移方案(含历史连接记录、RDP 配置、保存的账号密码)【可行】 Endnote,如何能完整迁移库和模版 ubuntu 安装 locate “华为杯”第八届中国研究生人工智能创新大赛 当数据量很大时,执行 mysql> source filename.sql 很慢,有什么办法更快 pip install django-ranged-response==0.2.0 部署Vue+Django 04c,mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory Ubuntu Server 24.04 安装 MySQL, ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory ubuntu server 24.04: 如何设置默认采用 Xorg 方式登录 Ubuntu Server 24.04 设置锁屏时间 Ubuntu Server 启动过程中,比较慢 Job systemd-networkd-wait-online.service/start running Ubuntu snap install 安装todesk是否必须检查 CPU 是否支持 AVX / AVX2 命令 Ubuntu Server 24.04下解决SunloginClient 向日葵依赖libgconf-2-4安装问题 Ubuntu Server 24.04 安装图形界面 ubuntu server 24.04 安装 中文输入法 Ubuntu Server 24.04 安装浏览器firefox Ubuntu Server 24.04 安装todesk【先联网,CPU必须支持 AVX / AVX2 】 Ubuntu Server 24.04 安装中文,汉字 Python赋值,什么时候传引用? 大驼峰命名法 python 容易理解类和对象的例子 django+mysql: 如何添加一个新的超级用户?
Ubuntu Server 24.04 启用root用户
emanlee · 2026-05-04 · via 博客园 - emanlee

Ubuntu Server 24.04 启用root用户

Ubuntu Server 24.04 启用 root 登录 完整草稿(可直接照着执行)

一、设置 root 密码(启用 root 账号)

Ubuntu 默认 root 未设置密码,无法登录,先设密码:

按提示输入当前普通用户密码,然后设置 root 新密码、确认密码。

二、允许 SSH 远程登录 root(关键)

编辑 SSH 配置文件:

sudo nano /etc/ssh/sshd_config

找到这一行:

#PermitRootLogin prohibit-password 

三、保存退出

nano 编辑器:

Ctrl+O → 回车保存 → Ctrl+X 退出

四、重启 SSH 服务生效

sudo systemctl restart ssh

五、测试登录

输入刚设置的 root 密码即可登录。

六、补充:关闭 root 登录(以后想禁用)

sudo nano /etc/ssh/sshd_config 

改回:

PermitRootLogin prohibit-password 

重启 SSH:

sudo systemctl restart ssh 

安全提醒

生产环境不建议开启 root SSH 直接登录,日常用普通用户 + sudo 即可;仅内网测试、本地虚拟机可以开启。

 =========================

Ubuntu Server 24.04,ssh 可以用root登录了。但是, desktop桌面无法使用root登录。

 Ubuntu 默认 SSH 允许 root ≠ 图形界面允许 root。桌面被禁是因为 GDM 配置 + PAM 认证两道锁,需要手动放开。下面直接给可复制的完整步骤(适用于 Ubuntu Server 24.04 + GNOME 桌面)。

可行,可用


一、先确认 root 密码已设置

sudo passwd root
# 输入两次 root 密码(你 SSH 登录用的那个) 

二、修改 GDM 配置,允许 root 登录 

sudo nano /etc/gdm3/custom.conf 

找到 [security] 段,添加 / 取消注释: 

[security]
AllowRoot=true 

图片

保存退出:Ctrl+O → 回车 → Ctrl+X


三、注释 PAM 里禁止 root 的规则(关键)

1)gdm-password

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

找到这一行,在行首加 # 注释掉

auth required pam_succeed_if.so user != root quiet_success
 

图片

 保存退出:Ctrl+O → 回车 → Ctrl+X

2)gdm-autologin(也要改)

sudo nano /etc/pam.d/gdm-autologin

同样注释掉(前面加 # ):

auth required pam_succeed_if.so user != root quiet_success

图片

  保存退出:Ctrl+O → 回车 → Ctrl+X


编辑 GDM 的默认配置: 

sudo nano /etc/gdm3/greeter.dconf-defaults 

找到这段(没有就直接加在文件末尾):

[org/gnome/login-screen]
#disable-user-list=true 

改成(去掉注释、设为 false):

[org/gnome/login-screen]
disable-user-list=false 

保存退出(Ctrl+O 回车,Ctrl+X)。

然后重启 gdm:【会断开todesk】

sudo systemctl restart gdm3

四、重启 GDM 生效 

sudo systemctl restart gdm3
# 或直接重启系统
sudo reboot 

五、登录测试

重启后在登录界面:

  • 用户名填:root
  • 密码填:你设置的 root 密码
  • 能进桌面即成功。

新问题:以前在另外一个用户下配置好的中文输入法,在root下不能使用了。


常见坑

  1. Wayland 下仍失败:登录界面点齿轮 → 选 GNOME on Xorg 再登录。
  2. 改完没重启 GDM:PAM/GDM 配置不重启不生效。
  3. 只改了一个 PAM 文件gdm-passwordgdm-autologin 两个都要注释