Linux sunucularda root şifresinin değiştirilmesi, hem rutin güvenlik bakımı hem de unutulmuş şifre kurtarma senaryosu için gerekebilir. AlmaLinux, CentOS, Debian, Ubuntu ailelerinin tamamında yöntem benzer olsa da bazı küçük farklılıklar vardır. Bu yazıda hem giriş yapılabilen bir sistemde hem de kullanıcı şifresi unutulduğunda başvurulan kurtarma modunda izlenecek adımları sırasıyla açıklıyoruz.
1) Çalışan sistem üzerinde değiştirme
Eğer root oturumuna girebiliyorsanız:
Code:
passwd
2) Bir başka kullanıcı olarak değiştirme
Sudo yetkili kullanıcı, root'un veya başka bir kullanıcının şifresini güncelleyebilir:
Code:
sudo passwd root
sudo passwd kullaniciadi
3) Tek seferlik komutla şifre belirleme (provisioning)
Otomatik kurulum betiklerinde:
Code:
echo "root:yeni-guclu-sifre" | chpasswd
4) Kurtarma modu (single user)
Şifreyi unuttuysanız, sunucuya fiziksel/console erişiminiz varsa GRUB kurtarma akışı:
- Sunucuyu yeniden başlatın, GRUB menüsünde varsayılan kernel'e e basın.
- Kernel satırının sonuna rd.break enforcing=0 ekleyin (RHEL 8/9 için).
- Ctrl+X ile boot edin.
- Switch_root komut isteminde: mount -o remount,rw /sysroot sonra chroot /sysroot.
- passwd root çalıştırın.
- touch /.autorelabel (SELinux yeniden etiketleme için).
- exit ve sonra exit ile boot devam eder.
5) Debian/Ubuntu kurtarma
GRUB'da kernel satırının sonuna init=/bin/bash ekleyin. Boot sonrası:
Code:
mount -o remount,rw /
passwd root
sync
exec /sbin/init
6) Güçlü şifre seçimi
Root şifresi minimum 20 karakter, harf-sayı-sembol karması olmalı. AIOR'da prod sunucularında root için ortalama 32 karakter, anahtar-yöneticisinde saklanan rastgele şifre kullanırız. Aynı şifre iki sunucuda tekrar etmemeli; sızıntı durumunda yatay hareket olasılığı düşer.
7) Şifre yaşam döngüsü
Mevcut şifre politikalarını chage -l root ile görebilirsiniz. Periyodik değişim alışkanlığı yerine, biz şifre rotasyonunu sızıntı veya personel ayrılması gibi olaylara bağlıyoruz; rastgele döndürme genelde zayıf şifrelere yol açar.
8) SSH key-only zorunluluğu
Root şifresine güvenmek yerine, SSH'da PermitRootLogin prohibit-password (veya no) ayarını tercih edin. Anahtar bazlı giriş, şifre brute-force riskine kapı kapatır. Şifre yine sistem konsolundan kullanılabilir ama uzaktan deneyenlere kapalıdır.
9) Audit kaydı
Her şifre değişikliği /var/log/secure içinde iz bırakır. Ortak yönetimli sunucularda bu logu merkezî bir log toplayıcıya (rsyslog, Loki, Graylog) aktarmak iyi bir alışkanlıktır.
10) Doğrulama
Yeni şifre ile yeni bir oturum açın. PAM kuralları reddediyorsa /etc/security/pwquality.conf dosyasını kontrol edin; minlen, dcredit, ucredit, ocredit ayarları olası nedendir.
Changing the root password on Linux is part of routine security maintenance and the answer to forgotten-credential incidents. The approach is similar across AlmaLinux, CentOS, Debian and Ubuntu but with small distribution-specific variations. This guide covers both live-system updates and the rescue-mode workflow for unrecoverable passwords.
1) Live-system change
If you can already log in as root:
Code:
passwd
2) Changing another user's password
A sudo-enabled user can update root's or any other account's password:
Code:
sudo passwd root
sudo passwd username
3) One-shot provisioning
In automation scripts:
Code:
echo "root:strong-new-password" | chpasswd
4) Rescue mode (single user)
When the password is lost and you have console access, GRUB recovery is the path:
- Reboot, press e on the default kernel entry in GRUB.
- Append rd.break enforcing=0 to the kernel line (RHEL 8/9).
- Boot with Ctrl+X.
- At the switch_root prompt: mount -o remount,rw /sysroot then chroot /sysroot.
- Run passwd root.
- touch /.autorelabel for SELinux relabel.
- Exit twice and let the boot continue.
5) Debian/Ubuntu recovery
Append init=/bin/bash to the kernel line in GRUB. After boot:
Code:
mount -o remount,rw /
passwd root
sync
exec /sbin/init
6) Choosing a strong password
Root passwords should be at least 20 characters with mixed character classes. We use a 32-character random password stored in our password manager, unique per server — so a single leak doesn't enable lateral movement.
7) Rotation policy
Inspect aging policy with chage -l root. We tie rotation to events (leaks, staff changes) rather than a fixed calendar, because mandatory rotation tends to push people toward weak, predictable patterns.
8) SSH key-only access
Instead of trusting root passwords for remote login, configure PermitRootLogin prohibit-password (or no) in sshd_config. The password still works on the console but is unreachable over SSH, removing the brute-force vector entirely.
9) Audit trail
Every password change is recorded in /var/log/secure. On shared infrastructure, ship that log to a central collector (rsyslog, Loki, Graylog) so the trail survives even if a single host is compromised.
10) Verification
Open a new session with the new password. If PAM rejects it, check /etc/security/pwquality.conf — minlen, dcredit, ucredit and ocredit are the usual blockers.