萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Ubuntu 修改 root 密碼:sudo passwd root 一指令搞定

背景

Ubuntu 安裝時只設定一般使用者密碼,root 帳號預設鎖定 (無密碼),需透過 sudo 提權操作。

設定 root 密碼

sudo passwd root
# 輸入當前使用者密碼 (sudo 認證)
# 輸入新 root 密碼
# 重新輸入確認
# passwd: password updated successfully

切換至 root

su - root
# 輸入新設定的 root 密碼
root@ubuntu:~#

安全建議

  • 日常操作請使用 sudo,避免長期以 root 登入。
  • 若需圖形介面以 root 登入 (不建議),需修改 /etc/gdm3/custom.conf 允許 AllowRoot=true 並調整 PAM 設定。
  • SSH 禁止 root 登入:/etc/ssh/sshd_config 設 PermitRootLogin no。

恢復 root 鎖定

sudo passwd -l root

鎖定後 su - root 將失敗,恢復預設安全狀態。

copyright © 萬盛學電腦網 all rights reserved