Ubuntu Server 24.04 xài thuật toán SHA512 hay thuật toán yescrypt để băm mật khẩu ?

Trong khi Red Hat Enterprise Linux chỉ băm mật khẩu bằng thuật toán SHA512 từ RHEL 5 tới giờ, cũng 17 năm òi thì Ubuntu đã chuyển sang xài thuật toán yescrypt để băm mật khẩu từ Ubuntu Server 22.04.

Khi cài Ubuntu Server 24.04 hoặc Ubuntu Desktop 24.04 thì chương trình cài đặt tự động băm mật khẩu bằng thuật toán SHA512.

Trong shadow password thì user hieu thấy có số 6, số 6 cho biết kiểu băm mật khẩu là SHA512.

# tail /etc/shadow
cups-browsed:!:19837::::::
hplip:!:19837::::::
polkitd:!*:19837::::::
rtkit:!:19837::::::
colord:!:19837::::::
gnome-initial-setup:!:19837::::::
gdm:!:19837::::::
nm-openvpn:!:19837::::::
gnome-remote-desktop:!*:19865::::::
hieu:$6$qbTjH3YLAXdDCLL5$b4b0ALZJ9jd2sx/IlPYX.RDubxSxaI6IV3hfhrqjp8wUA2RsWD1.EKMkcH4.of.0NjpA1R1HfSR.brWHmZpqv.:19865:0:99999:7:::

# egrep 'root|hieu' /etc/shadow
root:*:19837:0:99999:7:::
hieu:$6$qbTjH3YLAXdDCLL5$b4b0ALZJ9jd2sx/IlPYX.RDubxSxaI6IV3hfhrqjp8wUA2RsWD1.EKMkcH4.of.0NjpA1R1HfSR.brWHmZpqv.:19865:0:99999:7:::

Để cho an toàn mặc định user root bị khóa trên Ubuntu, phải tạo user thường được cấp quyền chuyển sang user root.

Sau khi chuyển lên user root và đổi mật khẩu cho root thì trong file shadow password là /etc/shadow thấy root có chữ y, chữ y cho biết mật khẩu bị băm bằng thuật toán yescrypt.

$ sudo -i
 
# passwd 
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: password updated successfully

# egrep 'root|hieu' /etc/shadow
root:$y$j9T$0ttCDeqVyAVgwWVj1r8AQ0$YOCpaG3gZjYdplkgNAKEGaZLU2mqRRfmdxPypoDrwi9:19867:0:99999:7:::
hieu:$6$qbTjH3YLAXdDCLL5$b4b0ALZJ9jd2sx/IlPYX.RDubxSxaI6IV3hfhrqjp8wUA2RsWD1.EKMkcH4.of.0NjpA1R1HfSR.brWHmZpqv.:19865:0:99999:7:::

Nếu chịu khó soi kĩ cơ chế chứng thực trên Linux là Pluggable Authentication Modules gọi tắt là Linux PAM sẽ thấy kiểu chứng thực mặc định là yescrypt trong /etc/pam.d/common-password.

cat /etc/pam.d/common-password
#
# /etc/pam.d/common-password - password-related modules common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of modules that define the services to be
# used to change user passwords.  The default is pam_unix.

# Explanation of pam_unix options:
# The "yescrypt" option enables
#hashed passwords using the yescrypt algorithm, introduced in Debian
#11.  Without this option, the default is Unix crypt.  Prior releases
#used the option "sha512"; if a shadow password hash will be shared
#between Debian 11 and older releases replace "yescrypt" with "sha512"
#for compatibility .  The "obscure" option replaces the old
#`OBSCURE_CHECKS_ENAB' option in login.defs.  See the pam_unix manpage
#for other options.

# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.

# here are the per-package modules (the "Primary" block)
password	requisite			pam_pwquality.so retry=3
password	[success=2 default=ignore]	pam_unix.so obscure use_authtok try_first_pass yescrypt
password	sufficient			pam_sss.so use_authtok
# here's the fallback if no module succeeds
password	requisite			pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
password	required			pam_permit.so
# and here are more per-package modules (the "Additional" block)
password	optional	pam_gnome_keyring.so 
# end of pam-auth-update config