Linux'ta root parolasını (çoğu kişinin aradığı adıyla root şifresini) değiştirmek, sisteme girebiliyorsanız iki dakikalık bir iştir. Parolayı unuttuysanız ve sunucu sizi içeri almıyorsa iş bambaşka bir hâl alır. İkisini tek rehberde topladık, çünkü "root parolasını nasıl değiştiririm?" sorusunun arkasında neredeyse her zaman aşağıdaki altı durumdan biri vardır. Rehber bir karar tablosuyla başlıyor; kendi satırınızı bulup doğrudan ilgili bölüme geçebilirsiniz.
Başlamadan iki not. Birincisi, unutulan bir root parolasını sıfırlamak çoğu zaman makineyi yeniden başlatmak, yani servisi kısa bir süre durdurmak demektir; üretim (production) sunucusunda bunu bir bakım penceresine koyun ve işiniz bitince denetim izini (audit trail) kontrol edin (7. bölüm). İkincisi, buradaki kurtarma yöntemleri sahibi ya da yöneticisi olduğunuz sistemler içindir; başkasına ait bir sunucuya erişemiyorsanız sahibine veya sağlayıcıya başvurun.
Hangi durumdasınız?
| Durum | Yapılacak | Bölüm |
|---|---|---|
| root olarak girebiliyorsunuz | passwd | 1 |
| sudo yetkili bir hesabınız var | sudo passwd root (Ubuntu'da çoğu zaman gerekmez) | 1 |
| Parola kayıp ama fiziksel ya da konsol erişimi var (VPS panelindeki VNC/web konsolu dahil) | Root kabuğuyla açılış: rd.break, kurtarma modu veya init=/bin/bash | 2 ve 3 |
| Konsolu olmayan VPS veya bulut sunucu | Sağlayıcının kurtarma (rescue) sistemi, chroot, passwd | 4 |
| Windows'ta WSL | wsl -u root, ardından passwd kullanıcı-adı | 5 |
| Docker, Podman veya LXC konteyneri | Konteynere root olarak exec; kalıcı ayar imajda | 5 |
1) Çalışan sistemde root parolasını değiştirmek
root oturumundaysanız tek komut yeter:
Bash:
passwd
sudo yetkili bir hesaptan, eski parolayı bilmeden root'un ya da herhangi bir kullanıcının parolasını ayarlayabilirsiniz; sudo yalnızca kendi parolanızı sorar:
Bash:
sudo passwd root
sudo passwd ahmet
Betiklerde parolayı etkileşimsiz ayarlamak için chpasswd kullanılır. Düz metin parola yerine önceden üretilmiş bir hash vermek daha güvenlidir:
Bash:
openssl passwd -6 # parolayı sorar, SHA-512 hash'ini yazdırır
echo 'root:HASH' | chpasswd -e # HASH yerine üretilen değeri koyun
Ubuntu ve Debian'da root neden kilitli olabilir?
Ubuntu, root hesabını kilitli bir parolayla kurar: parola alanında hiçbir parolanın eşleşemeyeceği bir değer bulunur, bu yüzden kimse doğrudan root olarak giriş yapamaz. Debian'da kurulum sırasında root parolasını boş bırakırsanız aynı düzen kurulur: root hesabı kapatılır ve ilk kullanıcı sudo ile yönetici yetkisi alır. Bu sistemlerde root'a sudo ile geçersiniz:
Bash:
sudo -i # root oturum kabuğu (root'un ortamı, /root dizini)
sudo -s # oturum açmadan root kabuğu, bulunduğunuz dizinde kalır
sudo komut # tek bir komutu root olarak çalıştırır
Bash:
sudo passwd -l root
İkincisi, durumu tek bakışta görebilirsiniz:
Bash:
passwd -S root
2) RHEL, AlmaLinux ve Rocky Linux 8/9'da unutulan root parolasını sıfırlama (rd.break)
Bu, Red Hat'in RHEL 8 ve 9 için belgelediği yöntemdir; aynı adımlar ikili uyumlu (binary compatible) yeniden derlemeler olan AlmaLinux ve Rocky Linux'ta da çalışır. Konsol erişimi gerekir: fiziksel ekran, IPMI/iDRAC/iLO ya da sanallaştırma platformunuzun veya sağlayıcınızın verdiği VNC/web konsolu.- Sistemi yeniden başlatın; GRUB ekranında varsayılan girdiyi seçip e tuşuna basın.
- linux ile başlayan satırı bulun, satırın sonuna gidin ve bir boşluk bırakarak rd.break ekleyin. Satırın geri kalanına dokunmayın.
- Ctrl+x ile açılışı başlatın. Sistem, asıl sistem devreye girmeden önce initramfs içindeki switch_root:/# isteminde durur.
- Asıl kök dosya sistemi /sysroot altında salt-okunur bağlıdır; önce yazılabilir olarak yeniden bağlayın.
- chroot ortamına geçin, parolayı ayarlayın ve bir sonraki açılış için SELinux yeniden etiketlemesi (relabel) isteyin; bu ortamda yazılan /etc/shadow yanlış SELinux bağlamıyla (context) kalır.
- chroot'tan çıkmak için exit, switch_root isteminden çıkmak için bir kez daha exit yazın; açılış kaldığı yerden sürer.
Bash:
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit
exit
Pratikte iki takılma noktası çıkar. Red Hat'in RHEL 7 kılavuzuna göre initramfs istemi, linux satırındaki son console= aygıtında açılır. Bulut imajlarında bu satır çoğu zaman console=ttyS0,... ile biter; istem seri konsola gider ve VNC ekranında hiçbir şey görmezsiniz. Bu durumda seri konsolu kullanın ya da yalnızca o açılış için satırın sonuna console=tty0 ekleyin. Disk LUKS ile şifreliyse açılışta parola sorulur; aynı kılavuza göre istem günlük mesajlarının arasında kaybolabilir, Backspace'e basınca görünür.
Aynı RHEL 7 kılavuzu, yeniden etiketlemeyi beklemek istemeyenler için bir kısayol da anlatır: rd.break'in yanına enforcing=0 eklerseniz SELinux o açılışta izin verici (permissive) modda çalışır ve touch /.autorelabel adımını atlayabilirsiniz. Açılış tamamlanınca root olarak girip yalnızca o dosyanın bağlamını düzeltin ve zorlayıcı (enforcing) moda dönün:
Bash:
restorecon /etc/shadow
setenforce 1
getenforce # Enforcing yazmalı
3) Debian ve Ubuntu: kurtarma modu veya init=/bin/bash
Ubuntu'da en kolay yol kurtarma menüsüdür. Açılışta Shift tuşunu basılı tutun (BIOS) ya da Esc tuşuna, gerekirse birkaç kez basın (UEFI). GRUB menüsünde Advanced options for Ubuntu'yu, ardından sonu (recovery mode) ile biten girdiyi, açılan menüde de "root – Drop to root shell prompt" seçeneğini seçin. Kök dosya sistemi salt-okunur bağlıdır, önce yazılabilir yapın:
Bash:
mount -o remount,rw /
passwd ahmet # Ubuntu'da genelde kaybolan, kendi kullanıcınızın parolasıdır
passwd root # yalnızca root'a gerçekten parola vermek istiyorsanız
Ubuntu'da root kilitli olduğu için bu kabuk genellikle parola sormadan açılır. root'a bir parola verilmişse kurtarma modu tam da o parolayı ister. Debian'ın kurtarma girdisinde bu menü hiç yoktur: root parolası belirlenmiş bir sistemde doğrudan o parola sorulur, root kilitliyse kabuk hiç açılmayabilir. Parolayı bilmiyorsanız güvenilir yol init=/bin/bash'tir.
GRUB satırını 2. bölümdeki gibi düzenleyin, ama sona rd.break yerine init=/bin/bash ekleyin. Hiçbir servis çalışmadan doğrudan root kabuğuna düşersiniz:
Bash:
mount -o remount,rw /
passwd root # ya da: passwd kullanıcı-adı
sync
Bash:
exec /sbin/init
# ya da:
mount -o remount,ro /
reboot -f
4) Konsolu olmayan VPS veya bulut sunucu
Açılış ekranını göremiyorsanız GRUB yöntemleri işe yaramaz; bir alt katmana inmeniz gerekir. Önce panele bakın: VNC ya da web konsolu varsa aslında konsol erişiminiz vardır ve 2. ile 3. bölümler doğrudan uygulanır. Bazı bulut panellerinde "root parolasını sıfırla" türünden bir işlev de bulunur; neye ihtiyaç duyduğunu (çoğu zaman bir konuk aracısı ya da yeniden başlatma) sağlayıcınızın belgesinden kontrol edin.Sağlayıcının kurtarma (rescue) sistemi. Birçok sağlayıcı, sunucunuzu RAM'den çalışan küçük bir kurtarma Linux'uyla açabilir (örneğin Hetzner Rescue System, OVHcloud rescue modu, DigitalOcean Recovery ISO). Diskleriniz bu ortamda takılıdır ama bağlanmamıştır (unmounted). AWS'te karşılığı, örneği (instance) durdurup kök diskini (EBS birimi) yardımcı bir örneğe takmaktır. Kurtarma ortamında:
Bash:
lsblk -f # disk, bölüm ve dosya sistemlerini gösterir
mount /dev/sda2 /mnt # kök bölümünüz; vda2 veya nvme0n1p2 de olabilir
mount /dev/sda1 /mnt/boot # yalnızca /boot ayrı bir bölümdeyse
for d in dev proc sys run; do mount --rbind /$d /mnt/$d; done
chroot /mnt
passwd root
# touch /.autorelabel # yalnızca SELinux kullanan sistemlerde
exit
sync
# panelde açılışı yeniden diske alın ve sunucuyu yeniden başlatın
Bash:
cryptsetup luksOpen /dev/sda2 root
mount /dev/mapper/root /mnt # LUKS içinde LVM varsa önce vgchange -ay
cloud-init. Bulut imajlarında ilk açılış parolası çoğu zaman cloud-init'ten gelir. chpasswd ve ssh_pwauth değerlerini sunucunun user-data'sında ayarlayabilirsiniz, ama bunları uygulayan modül her örnek için yalnızca bir kez çalışır (once-per-instance). Bu yüzden var olan bir sunucuda user-data'yı değiştirmek, cloud-init durumunu temizleyip (cloud-init clean) yeniden başlatmadıkça genellikle etkisizdir. cloud-init clean sonraki açılışı ilk açılış gibi çalıştırır: diğer modüller de yeniden çalışır ve varsayılan ayarlarla SSH ana makine anahtarları (host keys) yeniden üretilir. Üretimde bunu iyi tartın; kurtarma ya da konsol yolu çoğu zaman daha basittir. Ayrıca cloud-init varsayılan olarak disable_root uygular: root'un authorized_keys dosyasındaki anahtarın önüne, "Please login as the user ... rather than the user root" mesajını yazıp bağlantıyı kapatan zorunlu bir komut (forced command) ekler. root olarak anahtarla giriş "çalışıyor" görünüp sizi hemen dışarı atıyorsa nedeni budur.
Hipervizör tarafı. Ana makineyi (host) siz yönetiyorsanız konuğun (guest) parolasını onu açmadan da ayarlayabilirsiniz. libguestfs ile virt-customize -a disk.qcow2 --root-password password:YENI kullanılır; konuk kapalı olmalıdır, SELinux kullanan konuklarda --selinux-relabel ekleyin, password: yerine file
5) Windows'ta WSL ve konteynerler
WSL
WSL kullanıcınızın (sudo çalıştıran hesabın) parolasını unuttuysanız yukarıdakilerin hiçbirine gerek yok. PowerShell'den dağıtıma root olarak girip kullanıcının parolasını yenileyin:
Bash:
# PowerShell'de:
wsl -u root
# açılan root kabuğunda:
passwd kullanici-adiniz
exit
Bash:
wsl -l -v
wsl -d Ubuntu-24.04 -u root
Konteynerler
Docker veya Podman konteynerinde root parolasının pratikte pek anlamı yoktur: konteyner motorunu yönetebilen herkes, parola olmadan içeride root kabuğu açabilir:
Bash:
docker exec -it -u root <konteyner> sh
podman exec -it -u root <konteyner> sh
6) passwd başarısız olunca: "Authentication token manipulation error" ve kalite reddi
"Authentication token manipulation error" (PAM_AUTHTOK_ERR), passwd'nin değişikliği yazamadığı anlamına gelir. En sık nedenler, kontrol sırasıyla:- Salt-okunur dosya sistemi. Kurtarma kabuklarında en sık neden budur: yeniden bağlamayı unuttunuz. Red Hat de bu hatayı tam bu durum için anar. Çözüm: mount -o remount,rw / (rd.break'te /sysroot).
- Disk ya da inode dolu. /etc/shadow geçici bir dosya üzerinden yeniden yazılır; boş yer yoksa yazma başarısız olur. df -h / ve df -i / ile kontrol edin.
- Değiştirilemez (immutable) /etc/shadow. Dosyaya immutable biti konmuşsa root bile yazamaz. lsattr /etc/shadow ile görün, chattr -i /etc/shadow ile kaldırın; bu biti kimin ve neden koyduğunu da araştırın.
- Yanlış SELinux bağlamı. Çevrimdışı düzenlemeden sonra görülür; EL kurtarma yönteminin touch /.autorelabel ya da restorecon /etc/shadow ile bitmesinin nedeni budur.
İki komşu mesaj da sık görülür. "Have exhausted maximum number of retries for service": yeni parola denetimi geçemedi ya da iki giriş eşleşmedi ve izin verilen deneme sayısı (retry) doldu; passwd'yi yeniden çalıştırın. "Authentication token lock busy": passwd parola dosyalarını kilitleyemedi. Kurtarma kabuğunda bu mesaj da salt-okunur dosya sisteminden kaynaklanabilir; çalışan bir sistemde ise o anda parola dosyalarını düzenleyen başka bir işlem (useradd, vipw ya da bir yapılandırma yönetimi çalıştırması) olabilir, bitmesini bekleyip yeniden deneyin.
7) Sıfırladıktan sonra: kapıyı kapatın ve kayıt tutun
Parolayı yeniledikten sonra, internet ile sunucunuz arasında yalnızca bu parolanın durmadığından emin olun.SSH'ta root için parola yerine anahtar kullanın. /etc/ssh/sshd_config dosyasında ya da ana yapılandırmanın genellikle en başta Include ettiği /etc/ssh/sshd_config.d/ dizinindeki bir dosyada:
INI:
PermitRootLogin prohibit-password
Bash:
sshd -t && systemctl reload sshd # Debian/Ubuntu'da: systemctl reload ssh
sshd -T | grep -i permitrootlogin # etkin değeri gösterir
Denetim izini kontrol edin. Parola değişikliği günlüğe düşer. RHEL, AlmaLinux ve Rocky'de /var/log/secure, Debian ve Ubuntu'da /var/log/auth.log dosyasına bakın. Debian 12'den itibaren rsyslog varsayılan olarak kurulmadığı için yeni kurulmuş bir Debian sisteminde bu dosya olmayabilir; o durumda günlüğü (journal) okuyun:
Bash:
journalctl -t passwd
journalctl _COMM=sudo
ausearch -m USER_CHAUTHTOK # auditd kuruluysa
last # oturum geçmişi; Debian 13'te wtmpdb last
Güçlü bir parola seçin. Burada sabit bir karakter sayısı dayatmıyoruz, çünkü kurallar kurumdan kuruma değişir. Güvenli genel kural şudur: parola yöneticisinin ürettiği uzun ve rastgele bir parola kullanın (biz 24 karakterin altına inmiyoruz) ve her sunucuda farklı olsun ki tek bir sızıntı bütün sunuculara taşınmasın. Parolayı takvime göre değil olaya göre değiştirin (sızıntı şüphesi, ekipten ayrılan biri); NIST SP 800-63B de periyodik zorunlu değişimi önermez, değişimi ele geçirilme belirtisine bağlar. Daha geniş resim için sunucu sertleştirme rehberimize bakın. Bu adımlar sırasında bir komut "bu komut root yetkisiyle çalıştırılmalıdır" diye yanıt verirse (çoğu zaman sudo unutulmuştur), bu hata için hazırladığımız başlık sudo ve PATH kaynaklı nedenleri adım adım anlatır.
Sıkça sorulan sorular
Yeni root parolası koymak için eskisini bilmem gerekir mi?Hayır. Zaten root iseniz ya da sudo yetkiniz varsa passwd ve sudo passwd root eski parolayı sormaz; sudo yalnızca kendi parolanızı ister. Eski parola, normal bir kullanıcı kendi parolasını değiştirirken gerekir.
Parolayı değiştirmek açık oturumları veya servisleri etkiler mi?
Hayır. Parola değişikliği açık oturumları kapatmaz, çalışan servisleri durdurmaz. Kesintiyi kurtarma yöntemlerinin gerektirdiği yeniden başlatma yaratır; 1. bölümdeki canlı passwd yeniden başlatma gerektirmez.
rd.break ile sıfırladım, açılış çok uzun sürüyor. Normal mi?
Evet. Bu, touch /.autorelabel'in başlattığı SELinux yeniden etiketlemesidir ve büyük diskte uzun sürer. Bitmesini bekleyin; makine kendini yeniden başlatır. Bir dahaki sefere 2. bölümdeki enforcing=0 kısayolunu kullanabilirsiniz.
passwd "Authentication token manipulation error" veriyor. Ne yapmalıyım?
Büyük olasılıkla dosya sistemini yazılabilir olarak yeniden bağlamadınız. mount -o remount,rw / (ya da /sysroot) çalıştırıp tekrar deneyin. Sorun bu değilse dolu disk, değiştirilemez /etc/shadow (lsattr) ve SELinux bağlamını kontrol edin.
Ubuntu'da root'a parola vermeli miyim?
Çoğu sunucuda gerek yok. root'u kilitli tutup sudo kullanmak, korumanız gereken parolalardan birini ortadan kaldırır. root parolası en çok sulogin'in parola istediği acil durum (emergency) ve kurtarma (rescue) kabuklarında işe yarar; root kilitliyken bu kabuklar açılmayabilir ve o zaman 3. bölümdeki GRUB yöntemlerine dönersiniz. Parola koyarsanız uzun ve benzersiz olsun, bir parola yöneticisinde saklayın.
Birinin parolayı bu yollarla sıfırlamasını nasıl engellerim?
Fiziksel ya da konsol erişimi pratikte root erişimi demektir. Açılış satırının düzenlenmesini engellemek için GRUB parolası koyun, çevrimdışı bir chroot'un diski okuyamaması için diski LUKS ile şifreleyin, IPMI/VNC konsolunu ve sağlayıcı panelinizi güçlü parola ve iki adımlı doğrulamayla koruyun. Ayrıntılar sertleştirme başlığında.
Sonuç ve sonraki adımlar
Karar tablosunda kendi satırınızı bulun ve yalnızca o bölümü uygulayın: çalışan makinede passwd, RHEL ailesinde rd.break, Debian ve Ubuntu'da kurtarma modu ya da init=/bin/bash, konsolsuz VPS'te sağlayıcının kurtarma sistemi, Windows'ta wsl -u root. passwd değişikliği kaydedemiyorsa neden neredeyse her zaman salt-okunur dosya sistemi, dolu disk, değiştirilemez dosya ya da SELinux'tur. İş bitince root'un SSH girişini PermitRootLogin prohibit-password ile anahtara bağlayın, yeni parolayı bir parola yöneticisinde saklayın ve değişikliğin günlüklere düştüğünü doğrulayın. VPS seçerken pakette web konsolu ve kurtarma modu olup olmadığını önceden sorun; böyle bir günde sizi destek talebi beklemekten kurtarır. AIOR sanal sunucu paketlerinde root erişimi, yeniden kurulum ve snapshot seçenekleri pakete göre netleştirilir; kurtarma işini kendiniz yapmak istemiyorsanız uygun paketlerde yönetim hizmeti ayrıca teklif edilebilir. Dağıtımınıza ya da sağlayıcınıza özel sorularınızı bu başlıkta sorabilirsiniz.Changing the root password on Linux is a two-minute job when you can log in. When you have forgotten it and the server will not let you in, it is a different job entirely. Both belong in one guide, because "how do I reset the root password?" almost always turns out to be one of the six situations below. Start with the decision table, find your row and jump straight to that section.
Two notes before you touch anything. First, resetting a forgotten root password usually means a reboot, so plan a short outage on a production host and check the audit trail when you are done (section 7). Second, these recovery procedures are for machines you own or administer; if you are locked out of someone else's server, go to its owner or provider.
Which situation are you in?
| Situation | What to do | Section |
|---|---|---|
| You can log in as root | Run passwd | 1 |
| You have a sudo account | sudo passwd root (often unnecessary on Ubuntu) | 1 |
| Password lost, but you have physical or console access (including a VPS panel's VNC/web console) | Boot to a root shell: rd.break, recovery mode or init=/bin/bash | 2 and 3 |
| VPS or cloud server with no console | Provider's rescue system, chroot, passwd | 4 |
| WSL on Windows | wsl -u root, then passwd username | 5 |
| Docker, Podman or LXC container | Exec in as root; set anything permanent in the image | 5 |
1) Change the root password on a running system
If you are logged in as root, it is one command:
Bash:
passwd
From a sudo account you can set root's password, or any user's, without knowing the old one; sudo asks only for your own password:
Bash:
sudo passwd root
sudo passwd alice
In scripts, chpasswd sets passwords non-interactively. Feeding it a pre-generated hash is safer than plain text:
Bash:
openssl passwd -6 # prompts for the password, prints a SHA-512 hash
echo 'root:HASH' | chpasswd -e # replace HASH with that output
Why root may be locked on Ubuntu and Debian
Ubuntu installs the root account with a locked password: the password field holds a value that no password can match, so nobody can log in as root directly. Debian does the same if you leave the root password empty in the installer: the root account is disabled and the first user gets sudo. On these systems you become root through sudo:
Bash:
sudo -i # root login shell (root's environment, /root)
sudo -s # root shell without a login; stays in the current directory
sudo command # run one command as root
Bash:
sudo passwd -l root
Second, you can check the state at a glance:
Bash:
passwd -S root
2) Reset a forgotten root password on RHEL, AlmaLinux and Rocky Linux 8/9 (rd.break)
This is the procedure Red Hat documents for RHEL 8 and 9, and the same steps work on the binary-compatible rebuilds AlmaLinux and Rocky Linux. You need console access: a physical screen, IPMI/iDRAC/iLO, or the VNC/web console of your virtualisation platform or provider.- Reboot and, on the GRUB screen, highlight the default entry and press e.
- Find the line that starts with linux, move to its end and append rd.break after a space. Leave the rest of the line alone.
- Press Ctrl+x to boot. The system stops at a switch_root:/# prompt inside the initramfs, before the real system takes over.
- The real root filesystem is mounted read-only under /sysroot, so remount it read-write first.
- Enter the chroot, set the password and request an SELinux relabel for the next boot; /etc/shadow written from this environment ends up with the wrong SELinux context.
- Type exit to leave the chroot and exit again to leave the switch_root prompt; the boot carries on.
Bash:
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit
exit
Two snags come up in practice. Red Hat's RHEL 7 guide notes that the initramfs prompt appears on the last console= device on the linux line. Cloud images often end that line with console=ttyS0,..., so the prompt goes to the serial console and the VNC screen shows nothing; use the serial console, or append console=tty0 for that one boot. And if the disk is LUKS-encrypted, you are asked for the passphrase during boot; according to the same guide the prompt can be buried under log messages, and pressing Backspace brings it into view.
The same RHEL 7 guide describes a shortcut for when you do not want to wait for the relabel. Add enforcing=0 next to rd.break: SELinux runs in permissive mode for that boot, and you can skip touch /.autorelabel. Once the system is up, log in as root, fix the context of that one file and return to enforcing mode:
Bash:
restorecon /etc/shadow
setenforce 1
getenforce # should print Enforcing
3) Debian and Ubuntu: recovery mode or init=/bin/bash
On Ubuntu the easy path is the recovery menu. Hold Shift during boot (BIOS) or press Esc, possibly several times (UEFI), to reach GRUB. Choose Advanced options for Ubuntu, then the entry ending in (recovery mode), then "root – Drop to root shell prompt". The root filesystem is mounted read-only, so remount it first:
Bash:
mount -o remount,rw /
passwd alice # on Ubuntu it is usually your own user's password that is lost
passwd root # only if you really want root to have a password
Because root is locked on Ubuntu, this shell usually opens without asking for a password. If root has a password, recovery mode asks for exactly that password. Debian's recovery entry has no such menu at all: on a system with a root password it asks for that password straight away, and if root is locked it may not give you a shell. When you do not know the password, init=/bin/bash is the reliable route.
Edit the GRUB line as in section 2, but append init=/bin/bash instead of rd.break. You land in a bare root shell with no services running:
Bash:
mount -o remount,rw /
passwd root # or: passwd username
sync
Bash:
exec /sbin/init
# or:
mount -o remount,ro /
reboot -f
4) VPS or cloud server with no console
If you cannot see the boot screen, the GRUB methods are no use and you have to work one layer down. Check the panel first: if it offers a VNC or web console, you do have console access and sections 2 and 3 apply directly. Some cloud panels also have a "reset root password" function; check your provider's documentation for what it needs (often a guest agent or a reboot).Provider rescue system. Many providers can boot your server into a small rescue Linux that runs from RAM (for example Hetzner's Rescue System, OVHcloud rescue mode or DigitalOcean's Recovery ISO). Your disks are attached but not mounted. On AWS the equivalent is to stop the instance and attach its root EBS volume to a helper instance. In the rescue environment:
Bash:
lsblk -f # disks, partitions and filesystems
mount /dev/sda2 /mnt # your root partition; may be vda2 or nvme0n1p2
mount /dev/sda1 /mnt/boot # only if /boot is a separate partition
for d in dev proc sys run; do mount --rbind /$d /mnt/$d; done
chroot /mnt
passwd root
# touch /.autorelabel # only on SELinux systems
exit
sync
# switch the panel back to booting from disk, then reboot
Bash:
cryptsetup luksOpen /dev/sda2 root
mount /dev/mapper/root /mnt # with LVM inside LUKS, run vgchange -ay first
cloud-init. On cloud images the first-boot password often comes from cloud-init. You can set chpasswd and ssh_pwauth in the instance's user-data, but the module that applies them runs once per instance, so editing user-data on an existing server usually does nothing unless you also clear cloud-init's state (cloud-init clean) and reboot. That makes the next boot behave like a first boot: other modules run again too, and with default settings the SSH host keys are regenerated, so think twice before doing it in production; the rescue or console route is usually simpler. Note also that cloud-init applies disable_root by default: it puts a forced command in front of root's key in authorized_keys that prints "Please login as the user ... rather than the user root" and closes the connection. That is why key login as root seems to work and then drops you straight back out.
Hypervisor side. If you run the host, you can set a guest's password without booting it. With libguestfs, use virt-customize -a disk.qcow2 --root-password password:NEW; the guest must be shut down, add --selinux-relabel for SELinux guests, and the file:FILENAME selector instead of password: keeps the password out of your shell history. For running guests, Proxmox has qm guest passwd <vmid> root and libvirt has virsh set-user-password <domain> root NEW; both need the QEMU guest agent running in the guest.
5) WSL on Windows and containers
WSL
If you forgot the password of your WSL user (the account that runs sudo), you need none of the above. From PowerShell, enter the distribution as root and reset that user's password:
Bash:
# in PowerShell:
wsl -u root
# in the root shell that opens:
passwd your-username
exit
Bash:
wsl -l -v
wsl -d Ubuntu-24.04 -u root
Containers
In a Docker or Podman container a root password rarely means anything: anyone who can manage the container engine can already open a root shell inside without one:
Bash:
docker exec -it -u root <container> sh
podman exec -it -u root <container> sh
6) When passwd fails: "Authentication token manipulation error" and quality rejections
"Authentication token manipulation error" (PAM_AUTHTOK_ERR) means passwd could not write the change. The usual causes, in the order worth checking:- Read-only filesystem. The most common cause in rescue and recovery shells: you forgot the remount. Red Hat's documentation names this exact error for that case. Fix: mount -o remount,rw / (or /sysroot under rd.break).
- Disk or inodes full. /etc/shadow is rewritten through a temporary file, which fails when there is no free space. Check with df -h / and df -i /.
- Immutable /etc/shadow. If someone set the immutable bit, even root cannot write the file. See it with lsattr /etc/shadow, clear it with chattr -i /etc/shadow, and find out who set it and why.
- Wrong SELinux context after an offline edit; this is why the EL recovery procedure ends with touch /.autorelabel or restorecon /etc/shadow.
Two neighbouring messages are also common. "Have exhausted maximum number of retries for service" means the new password failed the checks, or the two entries did not match, as many times as the retry setting allows; just run passwd again. "Authentication token lock busy" means passwd could not lock the password files. In a recovery shell a read-only filesystem can cause this one too; on a running system another process (useradd, vipw or a configuration-management run) may be editing the files, so wait for it to finish and retry.
7) After the reset: close the door and keep a record
Once the password is reset, make sure it is not the only thing standing between the internet and your server.Use keys instead of the root password for SSH. In /etc/ssh/sshd_config, or in a file under /etc/ssh/sshd_config.d/, which the main config usually Includes near the top:
INI:
PermitRootLogin prohibit-password
Bash:
sshd -t && systemctl reload sshd # on Debian/Ubuntu: systemctl reload ssh
sshd -T | grep -i permitrootlogin # shows the effective value
Check the audit trail. A password change is logged. On RHEL, AlmaLinux and Rocky look in /var/log/secure; on Debian and Ubuntu in /var/log/auth.log. Since Debian 12, rsyslog is no longer installed by default, so a fresh Debian system may not have that file; read the journal instead:
Bash:
journalctl -t passwd
journalctl _COMM=sudo
ausearch -m USER_CHAUTHTOK # if auditd is installed
last # login history; wtmpdb last on Debian 13
Choose a strong password. We do not impose a fixed character count here, because rules differ between organisations. The safe general rule: use a long random password generated by a password manager (we do not go below 24 characters), unique per server so one leak cannot be replayed across your fleet. Change it when something happens (a suspected leak, someone leaving the team) rather than on a calendar; NIST SP 800-63B also advises against forced periodic changes and ties a change to evidence of compromise. For the wider picture, see our server hardening guide. If a command in these steps answers "this command must be run as root" (usually because sudo was left off), our thread on that error walks through the sudo and PATH causes step by step.
FAQ
Do I need the old root password to set a new one?No. If you are already root or have sudo, passwd and sudo passwd root do not ask for it; sudo asks only for your own password. You need the old password only when a normal user changes their own.
Will changing the password log everyone out or break services?
No. Changing the password does not end open sessions or stop running services. The downtime comes from the reboot that the recovery procedures need; the live passwd in section 1 needs no reboot.
I reset it with rd.break and the boot is taking ages. Is that normal?
Yes. That is the SELinux relabel triggered by touch /.autorelabel, and it is slow on a big disk. Let it finish; the machine reboots itself. Next time you can use the enforcing=0 shortcut from section 2.
passwd says "Authentication token manipulation error". What now?
You most likely did not remount the filesystem read-write. Run mount -o remount,rw / (or /sysroot) and try again. If that is not it, check for a full disk, an immutable /etc/shadow (lsattr) and the SELinux context.
Should I give root a password on Ubuntu?
On most servers, no. Keeping root locked and using sudo means one less secret to protect. A root password mostly matters for the emergency and rescue shells where sulogin asks for it; with root locked those shells may refuse to open, and you fall back to the GRUB methods in section 3. If you do set one, make it long and unique and keep it in a password manager.
How do I stop someone else resetting the password this way?
Physical or console access is effectively root access. Set a GRUB password to block editing of the boot line, encrypt the disk with LUKS so an offline chroot cannot read it, and protect the IPMI/VNC console and your provider panel with strong passwords and two-factor authentication. The hardening thread covers the details.
Conclusion and next steps
Find your row in the decision table and follow that section only: passwd on a running machine, rd.break on the RHEL family, recovery mode or init=/bin/bash on Debian and Ubuntu, the provider's rescue system on a console-less VPS, or wsl -u root on Windows. When passwd cannot save the change, the cause is nearly always a read-only filesystem, a full disk, an immutable file or SELinux. Afterwards, restrict root SSH to keys with PermitRootLogin prohibit-password, store the new password in a password manager and confirm that the change shows up in your logs. When you choose a VPS, ask up front whether the plan includes a web console and a rescue mode; on a day like this it saves you waiting on a support ticket. On AIOR VPS hosting plans, root access, reinstall and snapshot options are confirmed per plan, and on eligible plans management can be quoted separately if you would rather not handle recovery yourself. Questions about your specific distribution or provider are welcome in this thread.
Last edited: