Zum Inhalt springen

Zugriff auf Ihre VM wiederherstellen oder Notfall-Fehlerbehebung durchführen

Falls Sie Ihren SSH-Schlüssel und Ihr Passwort verlieren oder der Server nicht booten kann, haben Sie immer noch die Möglichkeit, Ihre VM wiederherzustellen.

Linux-Betriebssystem: Jede Linux-Distribution verwendet einen anderen Standard-Benutzernamen und die Namen der SSH-Daemons unterscheiden sich bei EL- und Debian-Derivaten. Bitte sehen Sie: Betriebssystem-Images.

Starten Sie Ihre VM über die Web-Konsole neu. Screenshot of a virtual machine management panel showing a dropdown menu with actions. The VM is labeled "VM-1" and is "Online." The dropdown menu is open, and the 'Reboot' action is highlighted, indicated by a cursor pointing to it, suggesting a user is about to click or select this option to restart the virtual machine.

Gehen Sie zum STACKIT Portal und greifen Sie auf die Web-Konsole zu: Screenshot of a virtual machine management panel showing a dropdown menu with actions. The VM is labeled "VM-1" and is "Online." The dropdown menu is open, and the 'Web console' action is highlighted, indicated by a cursor pointing to it, suggesting a user is about to click or select this option to open the console access.

Sie werden sehen, wie Ihre VM bootet. Klicken Sie auf die Schaltfläche Send CtrlAltDel in der oberen rechten Ecke. Screenshot of a black terminal window displaying the login prompt for a successful text-based boot. The header text shows 'Ubuntu 22.04 LTS server3 tty1', and the prompt reads 'server3 login: _', indicating the virtual machine has finished booting and is ready for a user to log in.

Verwenden Sie die Pfeiltasten oder halten Sie die Umschalttaste während des Ladens von Grub gedrückt. Wenn Sie über BIOS booten oder das System UEFI verwendet, drücken Sie Esc, um den Menü-Timeout von Grub zu stoppen – dieser ist recht kurz. Wenn Sie den Moment verpassen, drücken Sie einfach erneut Send CtrlAltDel. Sie sollten etwas Ähnliches wie das hier sehen:

Drücken Sie Auf und Ab.

Wählen Sie den neuesten (obersten) Menüeintrag aus.

Screenshot of the GNU GRUB version 2.06 boot loader menu. The main options visible are 'Ubuntu' (highlighted) and 'Advanced options for Ubuntu.' At the bottom, text instructs the user: "Use the $\uparrow$ and $\downarrow$ keys to select which entry is highlighted. Press enter to boot the selected OS, 'e' to edit the commands before booting or 'c' for a command-line."

Bearbeiten Sie nun Ihr Menü (drücken Sie den Buchstaben e auf der Tastatur), um das Menü editieren zu können.

Sie werden etwas Ähnliches wie das hier sehen: Screenshot of the GNU GRUB version 2.06 boot loader edit screen, showing the boot commands for the Ubuntu entry. The text displays a sequence of commands, including setparams 'Ubuntu', load_video, gfxmode $linux_gfx_mode, insmod ext2, and the linux and initrd lines specifying the kernel path (/boot/vmlinuz-5.15.0-41-generic) and boot parameters. The bottom text explains the editing controls: "Minimum Emacs-like screen editing is supported. TAB lists completions. Press Ctrl-x or F10 to boot, Ctrl-c or F2 for a command-line or ESC to discard edits and return to the GRUB menu."

Scrollen Sie nun nach unten (verwenden Sie die Pfeiltasten) bis zu der Zeile, die je nach Distribution mit linux, linux16 oder linuxefi beginnt: Screenshot of the GNU GRUB version 2.06 boot loader edit screen. It shows the commands for the Ubuntu entry, specifically after an edit to the linux and initrd lines. The command lines are partially visible, showing the kernel path and a modification where the initrd command is now on a separate line below the linux command. This represents an intermediate step in modifying the boot parameters.

Gehen Sie nun zum Ende dieser Zeile und löschen Sie alles nach ro. Ändern Sie dann ro in rw um und fügen Sie danach init=/bin/bash hinzu. Bei Servern, die auf Fedora basieren, müssen Sie rootflags=subvol=root beibehalten, was nach ro steht, zum Beispiel rw rootflags=subvol=root init=/bin/bash.

A screenshot of the GNU GRUB version 2.06 bootloader menu, showing the commands used to configure the boot process. The central white box displays lines including: recordfail, load_video, insmod part_gpt, insmod ext2, a long search command, the linux command line loading vmlinuz-5.15.0-41-generic and setting init=/bin/bash, and the initrd command line. This screen is typically used to edit boot parameters for recovery or advanced troubleshooting.

Halten Sie nun die Strg-Taste auf der Tastatur gedrückt und drücken Sie x. Das System beginnt zu booten. Es wird einen Zustand erreichen, der etwa so aussieht: A console screenshot showing part of the Linux boot sequence and recovery shell access. The top lines show kernel messages (RAID/Btrfs operations), followed by status messages like Begin: Running /scripts/init-premount ... done. and warnings like Warning: fsck not present, so skipping root file system. The sequence concludes with a key error message: bash: cannot set terminal process group (-1): Inappropriate ioctl for device in this shell, immediately followed by the root shell prompt: root@(none):/#, indicating the user has been dropped into an emergency or recovery shell.

Jetzt können Sie eine Notfall-Fehlerbehebung durchführen oder einfach Ihren Zugriff auf den Server wiederherstellen, indem Sie Folgendes in Ihre Konsole eingeben (Kopieren und Einfügen funktioniert nicht):

Terminal-Fenster
passwd root

Ändern Sie nun das Root-Passwort, das Sie für die Anmeldung verwenden werden. Aus Sicherheitsgründen werden Sie das Root-Passwort später erneut ändern! A minimal Linux console screenshot demonstrating a successful root password change. The prompt is root@(none):/#. The command passwd root is entered, followed by prompts for New password: and Retype new password:, and finally the confirmation message: passwd: password updated successfully.

Wiederholen Sie den obigen Schritt für die Standard-Benutzer Ihrer Distribution.

Nun müssen Sie vorübergehend die Anmeldung per Passwort erlauben. Wir werden dies zu einem späteren Zeitpunkt wieder ändern. Öffnen Sie /etc/ssh/sshd_config.

Terminal-Fenster
vi /etc/ssh/sshd\_config

Suchen Sie die Zeile, die so aussieht:

#PasswordAuthentication yes

Sobald sich der Indikator über dem Zeichen# befindet, drücken Sie x um dieses Zeichen zu löschen. Drücken Sie die folgende Tastenfolge: Esc, :, w, q, Enter.
Diese Sequenz speichert Ihre Änderungen.

Terminal-Fenster
sshd -t

A Linux terminal screenshot showing an error while checking the SSH daemon configuration. The command sshd -t is run, and the output shows: /etc/ssh/sshd_config: line 63: Bad configuration option: 1PasswordAuthentication followed by /etc/ssh/sshd_config: terminating, 1 bad configuration options. This indicates a configuration error on line 63 of the sshd_config file due to a misspelled or invalid option.

Eine gute Ausgabe sieht so aus: A Linux terminal screenshot showing a successful check of the SSH daemon configuration. The command sshd -t is run, and the output is a new, blank command prompt ([root@vm-1-fq4tx0z0 ~]#), indicating no configuration errors were found.

Starten Sie den sshd-Daemon neu. Dieser Daemon steuert den Fernzugriff auf den Linux-Server.

Terminal-Fenster
systemctl restart sshd

Auf EL-basierten Systemen (wie CentOS) heißt der Daemon sshd, während er auf Debian und Derivaten ssh heißt.

Wenn Ihr Server auf der Red Hat-Familie basiert (wie CentOS, CentOS Stream, Fedora, AlmaLinux, Rocky Linux), müssen Sie nun die SELinux-Sicherheit mit dem Befehl touch /.autorelabel.neu kennzeichnen. Wenn Ihr Server auf der Debian-Familie basiert (wie Debian, Ubuntu), benötigen Sie dies nicht. Starten Sie danach den Server mit dem Befehl exec /sbin/init 6 neu.

touch /.autorelabel exec /sbin/init 6

Jetzt sollten Sie in der Lage sein, sich per SSH mit Ihrem Passwort anzumelden. Verwenden Sie das von Ihnen erstellte Passwort:

Terminal-Fenster
ssh centos@4.159.97.5 Warning: Permanently added '4.159.97.5' (ECDSA) to the list of known hosts. centos@4.159.97.5's password: X11 forwarding request failed on channel 0 Last login: Thu May 21 09:15:14 2020 from 4.159.97.30 [centos@vm-1-fq4tx0z0 \~]$

Bearbeiten Sie Ihre authorized_keys, um Ihren neuen SSH-Key zu erlauben.

Terminal-Fenster
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMbC29mO0j9NnjTt/eSNQuwX0XPcFT77Fg20wUKCHFyJrC+yldMja8EEEo+LY2HRgu5mzDHdKG9nHW2yGtPt1kUfz6Icck/Of5uT5G9139IKdDd1VxdqDOKKQq6e+3cbtLe0JvAdEG/B7M0nIkpguVX2T2Lojsi7xF3sHjrg7vjYeFWmoBjWl7tilgu0eXTHFdmKvCJ05qjgU5OwXitE8YtxKd/iifs0YACan3PCFX4P4vAe/oBjmaIW2qCLaBTEI2COMl6/EVaIhiudplTFJV4ebbbidwhXkGWj8o0mMEv7umgIsU3Fv4UoUQ0fU7ZxqReApIBGLtKL6rG7NntTD6r6ROrh5VXfJfWRXQgBh+S/Ei9gvRBeu0qzqEiSIyIWT14+RsXjDuGBRch2GZmGjres7XEqtCRvpnDJ6A1gS8NFeHr9GcATUbBhS45iFCuDTvFfNgI7ydyOfWlB+/D8fvrfgXH7k1r5291oiNonVTmYkF3sDVWGmRvFoyZcSqBxftok4TCD9vEmqg7Uqa0eAkYIxyxffNmzUgY3UrxRLD+IyUFAoaXKMtkuxE5KrrBYSweIOa5pCvbJOjX/yP7R5SumvEOEJMSiu0bdd5UsP6ed8omax6FWcp3g+P4PMRMbaM/aMowAE+02TizdJ+PDfWD1+f6W4XMZHHyfwsfTeLKw== someuser@MYPC' >> \~/.ssh/authorized\_keys

Überprüfen Sie den Zugriff per Schlüssel. Sie sollten ohne Passwort angemeldet werden.

Machen Sie Ihre Änderungen in der sshd-Konfigurationsdatei rückgängig. Da wir nun in der Lage sind, in der Shell (nicht in der Web-Konsole) Kopieren / Einfügen zu nutzen, können Sie Folgendes ausführen:

Terminal-Fenster
sudo sed -i 's/PasswordAuthentication yes/#PasswordAuthentication no/' /etc/ssh/sshd\_config

Überprüfen Sie Ihre Änderungen erneut und starten Sie sshd neu, wenn keine Fehler erkannt werden:

Terminal-Fenster
sshd -t systemctl restart sshd

SELinux reparieren (CentOS und Derivate):

Terminal-Fenster
touch /.autorelabel restorecon -RFvv /etc/shadow restorecon -RFvv /etc/ssh/sshd\_config setenforce 1

Setzen Sie nun die Passwörter der Benutzer auf einen Zufallswert:

Terminal-Fenster
cat /dev/urandom | tr -dc 'A-Za-z0-9!"#$%&'\\''()*+,-./:;<=>?@[\\]^\_`{|}\~' | head -c 25 | passwd --stdin root cat /dev/urandom | tr -dc 'A-Za-z0-9!"#$%&'\\''()*+,-./:;<=>?@[\\]^\_`{|}\~' | head -c 25 | passwd --stdin centos

Neustart:

Terminal-Fenster
reboot