重启后SSH无法连接实例,咨询无账号密码时串口控制台使用方法
Hey there, sorry to hear you're dealing with this SSH connectivity issue for the second time—total frustration when everything was working perfectly before the reboot. Let's break down how to tackle the serial console username/password problem so you can get back in:
1. Start with Default/Provisioned Credentials
First, let's rule out the obvious:
- If you set up a custom admin user during initial instance setup, that's the first username to try—most systems lock down root access over serial by default, so skip
rootfirst unless you explicitly enabled it. - Cloud providers have standard default usernames:
ubuntufor Ubuntu instances,ec2-userfor AWS EC2,azureuserfor Azure VMs,debianfor Debian,centos/rockyfor RHEL-based distros. - Check your instance's dashboard in your cloud/host portal—many providers store initial credentials (or a link to reset them) in the "Instance Details" or "Credentials" tab, even if you used SSH keys originally.
2. Reset Credentials via Your Provider's Tools
If defaults don't work, every major provider has a way to reset credentials or enable serial access through their web console:
- AWS: Use the EC2 Serial Console feature. If login fails, detach the root EBS volume, attach it to a working instance, mount the partition, and either reset the user password in
/etc/shadowor editsshd_configto fix SSH issues. - Azure: Head to your VM's blade in the Azure Portal, use the "Reset password" option—you can set a new password for your existing user or create a new admin account with serial access.
- GCP: Go to your VM instance details, enable the serial console connection, then use the "Set password" tool to reset or create a valid user.
- On-prem/physical servers: Boot from a live USB (like Ubuntu Live), mount the root partition, and edit
/etc/shadowto clear the password hash for your user (or set a new one withpasswdonce mounted).
3. Bypass Login with Single-User Mode (Linux Systems)
If you can access the serial console but can't log in, boot into single-user mode to reset credentials directly:
- Interrupt the GRUB boot menu (press
EscorShiftas the instance starts—you might need to enable GRUB visibility in your instance settings first) - Select your active kernel, press
eto edit the boot parameters - Find the line starting with
linux(orlinux16), addinit=/bin/bashat the end of the line - Press
Ctrl+Xto boot—this drops you into a root shell without needing a password - Remount the root partition as read-write:
mount -o remount,rw / - Reset your user's password:
passwd your_username - Reboot normally:
reboot -f
4. Fix the Root Cause (To Avoid This Again)
Since this is the second time this has happened, once you regain access, dig into why SSH is breaking post-reboot:
- Check if SSH is set to start on boot:
systemctl is-enabled sshd(for systemd-based distros) - Review SSH logs for startup errors:
journalctl -u sshd - Verify firewall rules didn't reset—make sure port 22 is allowed (use
ufw statusorfirewall-cmd --list-all) - Confirm your instance's network settings (IP, subnet, gateway) are consistent post-reboot
内容的提问来源于stack exchange,提问作者Łukasz Marchewka

