DriteStudioDRITESTUDIODRITESTUDIO
HomeArticlesAbout UsContact
Home
VPSHigh-performance virtual servers with full root access
VPS ForexUltra-low latency VPS optimized for Forex & automated trading
Web HostingManaged hosting with Plesk and free SSL
Game Server HostingSupports 20+ games worldwide. Rent a VPS and tell us which game you want to run.
Dedicated ServersEnterprise hardware with IPMI access
ColocationSecure data center space for your servers
SecurityWAF, DDoS Protection & 24/7 SOC Monitoring
Web DevelopmentCustom website design & development with modern frameworks
SEO ServiceBoost rankings with articles, backlinks & technical SEO
StatusCheck system uptime and service availability
ArticlesAbout UsContact
0%
วิธีเปลี่ยนรหัสผ่าน Linux ทุกเวอร์ชัน ครบทั้ง passwd, root reset และนโยบายความปลอดภัย
Back to articles

วิธีเปลี่ยนรหัสผ่าน Linux ทุกเวอร์ชัน ครบทั้ง passwd, root reset และนโยบายความปลอดภัย

คู่มือเปลี่ยนรหัสผ่าน Linux แบบครบจบ ตั้งแต่ passwd เปลี่ยนรหัสตัวเอง เปลี่ยนรหัส user อื่น reset root ที่ลืม ไปจนถึงตั้งนโยบายรหัสผ่านที่ปลอดภัย ใช้ได้ทุก distro

Linux-August 11, 2023-Updated: April 17, 2026

การเปลี่ยนรหัสผ่านใน Linux ทำได้ง่ายด้วยคำสั่ง passwd ซึ่งเป็นมาตรฐานที่ใช้ได้กับทุก distro ไม่ว่าจะเป็น Ubuntu, CentOS, Debian หรือ AlmaLinux บทความนี้ครอบคลุมทุกกรณี ตั้งแต่เปลี่ยนรหัสตัวเอง เปลี่ยนรหัส user อื่น ไปจนถึง reset รหัส root ที่ลืม

วิธีเปลี่ยนรหัสผ่านของตัวเอง

พิมพ์คำสั่งนี้ใน Terminal:

passwd

ระบบจะถามรหัสผ่านเดิมก่อน แล้วให้ใส่รหัสผ่านใหม่สองครั้ง:

Changing password for user demo.
Current password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

เคล็ดลับคือควรตั้งรหัสผ่านที่แข็งแรง ยาวอย่างน้อย 12 ตัวอักษร ผสม uppercase, lowercase, ตัวเลข และอักขระพิเศษ

เปลี่ยนรหัสผ่าน User อื่น

ผู้ดูแลระบบสามารถเปลี่ยนรหัสผ่านของ user คนอื่นได้โดยใช้ sudo:

sudo passwd username

ในกรณีนี้ไม่ต้องใส่รหัสผ่านเดิมของ user นั้น:

New password:
Retype new password:
passwd: all authentication tokens updated successfully.

บังคับให้เปลี่ยนรหัสผ่านเมื่อ Login ครั้งถัดไป

เหมาะสำหรับกรณีสร้าง user ใหม่และให้รหัสผ่านชั่วคราว:

sudo passwd --expire username

เมื่อ user นั้น login ครั้งถัดไป ระบบจะบังคับให้ตั้งรหัสผ่านใหม่ทันที

ตั้งนโยบายรหัสผ่านด้วย chage

สำหรับเซิร์ฟเวอร์ที่ต้องการความปลอดภัยสูง ควรตั้งนโยบายรหัสผ่านอย่างรัดกุม

ดูนโยบายปัจจุบัน

sudo chage -l username

ตัวอย่างผลลัพธ์:

Last password change                    : Mar 15, 2026
Password expires                        : Jun 13, 2026
Password inactive                       : never
Account expires                         : never
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7

กำหนดให้ต้องเปลี่ยนรหัสทุก 90 วัน

sudo chage -M 90 username

กำหนดจำนวนวันขั้นต่ำก่อนเปลี่ยนรหัสได้

ป้องกันไม่ให้ user เปลี่ยนรหัสกลับไปใช้ตัวเก่าทันที:

sudo chage -m 7 username

กำหนดวันเตือนก่อนรหัสหมดอายุ

sudo chage -W 14 username

ตั้งค่าทั้งหมดในคำสั่งเดียว

sudo chage -M 90 -m 7 -W 14 username

กำหนดความซับซ้อนของรหัสผ่านด้วย PAM

สำหรับ Ubuntu/Debian

ติดตั้ง libpam-pwquality แล้วแก้ไข config:

sudo apt install libpam-pwquality

แก้ไขไฟล์ /etc/pam.d/common-password เพิ่มหรือแก้บรรทัด:

password requisite pam_pwquality.so retry=3 minlen=12 ucredit=-1 dcredit=-1 ocredit=-1

สำหรับ CentOS/RHEL

แก้ไขไฟล์ /etc/security/pwquality.conf:

sudo nano /etc/security/pwquality.conf

ใส่ค่าเหล่านี้:

minlen = 12
ucredit = -1
lcredit = -1
dcredit = -1
ocredit = -1

ความหมายของแต่ละค่า: minlen = ความยาวขั้นต่ำ, ucredit=-1 = ต้องมีตัวพิมพ์ใหญ่อย่างน้อย 1 ตัว, dcredit=-1 = ต้องมีตัวเลขอย่างน้อย 1 ตัว, ocredit=-1 = ต้องมีอักขระพิเศษอย่างน้อย 1 ตัว

Reset รหัส root ที่ลืม

วิธี Reset บน Ubuntu/Debian

  1. รีบูตเครื่องแล้วกด Shift ค้างเพื่อเข้า GRUB Menu
  2. เลือก Advanced Options แล้วเลือก Recovery Mode
  3. เลือก root - Drop to root shell prompt
  4. Remount filesystem เป็น read-write แล้วตั้งรหัสใหม่:
mount -o remount,rw /
passwd root
reboot

วิธี Reset บน CentOS/RHEL

  1. รีบูตเครื่องแล้วกด e ที่ GRUB Menu เพื่อแก้ไข Boot Parameters
  2. เพิ่ม rd.break ที่ท้ายบรรทัด linux
  3. กด Ctrl+X เพื่อบูตแล้วรันคำสั่ง:
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel
exit
reboot

สำหรับผู้ใช้ VPS ของ DriteStudio หากลืมรหัสผ่าน root สามารถติดต่อทีมซัพพอร์ตเพื่อ reset ผ่าน Console ได้ทันที

แนวทางรักษาความปลอดภัยเพิ่มเติม

ปิด root login ผ่าน SSH โดยแก้ไข /etc/ssh/sshd_config:

sudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sudo systemctl restart sshd

สร้าง SSH Key แทนการใช้รหัสผ่าน:

ssh-keygen -t ed25519 -C "[email protected]"
ssh-copy-id user@server-ip

คำถามที่พบบ่อย

คำสั่ง passwd ใช้ได้กับทุก Linux Distro หรือไม่

ใช่ คำสั่ง passwd เป็นมาตรฐานของ Linux ทุกเวอร์ชัน ไม่ว่าจะเป็น Ubuntu, CentOS, Debian, Fedora หรือ Arch Linux ใช้วิธีเดียวกันทั้งหมด

ลืมรหัสผ่าน root ทำอย่างไร

สามารถ reset ได้ผ่าน Recovery Mode หรือ Single User Mode ของ GRUB หากใช้ VPS สามารถขอ reset ผ่าน Console จากผู้ให้บริการได้ สำหรับ DriteStudio ติดต่อทีมซัพพอร์ตได้ตลอด 24 ชั่วโมง

ควรตั้งรหัสผ่านยาวแค่ไหนจึงจะปลอดภัย

แนะนำอย่างน้อย 12 ตัวอักษร ผสมตัวพิมพ์ใหญ่ พิมพ์เล็ก ตัวเลข และอักขระพิเศษ ยิ่งยาวยิ่งปลอดภัย การใช้ passphrase เช่นประโยคยาวที่จำง่ายก็เป็นทางเลือกที่ดี

SSH Key ดีกว่ารหัสผ่านอย่างไร

SSH Key ใช้การเข้ารหัสแบบ Public-Private Key ที่ปลอดภัยกว่ารหัสผ่านมาก ไม่สามารถถูก Brute Force ได้ และไม่ต้องจำรหัสผ่าน


การเปลี่ยนรหัสผ่านบน Linux ทำได้ง่ายด้วยคำสั่ง passwd สิ่งสำคัญคือต้องตั้งรหัสผ่านที่แข็งแรงและพิจารณาใช้ SSH Key สำหรับ Remote Access หากต้องการเซิร์ฟเวอร์ที่ดูแลเรื่องความปลอดภัยอย่างครบวงจร DriteStudio มีบริการ VPS และ Hosting พร้อมทีมผู้เชี่ยวชาญที่พร้อมช่วยเหลือตลอด 24 ชั่วโมง

Share article:
View more articles
D

DriteStudio | ไดรท์สตูดิโอ

Digital infrastructure provider for VPS, web hosting, and colocation in Thailand

Operated by Craft Intertech (Thailand) Co., Ltd.

© 2026 Craft Intertech (Thailand) Co., Ltd. All rights reserved.

Privacy PolicyTerms of ServiceSystem Status