Home / AWS

AWSHow-toAdvanced

EC2 Serial Console: get into an instance with a broken boot, network or sshd, and fix it in place

Enable EC2 Serial Console access, connect over SSH with a 60-second key, and repair fstab, sshd, firewall and network faults on Linux and Windows without detaching volumes.

Deepak Bhardwaj7 min read

Applies toAmazon EC2 Nitro-based and most bare metal instances, Amazon Linux 2023/AL2, Ubuntu, RHEL, Windows Server with EC2Launch v2.5.0+

The instance is running, status checks may even pass, but SSH times out, Session Manager shows the node offline and the console screenshot shows a boot prompt or emergency shell. The serial console gives you a keyboard on ttyS0 (Linux) or COM1 (Windows) that does not depend on the instance's network, sshd or SSM Agent. It is usually faster than the "stop, detach root volume, mount on a rescue instance" routine, and it does not change the instance's volumes or IP addresses.

Before you start: what it needs

Requirement Detail
Instance type Nitro-based virtualized instances and most bare metal (a1.metal, Mac and some u-*tb1.metal types are excluded)
State running only
Account setting Serial console access enabled per Region (off by default)
IAM ec2-instance-connect:SendSerialConsoleSSHPublicKey on the instance
Linux login A password-based OS user. AWS AMIs ship without one
Windows SAC enabled via bcdedit, EC2Launch v2.5.0+ and EC2WinUtil 3.2.0+

Warning

Serial console access is close to physical console access. Anyone with SendSerialConsoleSSHPublicKey and a valid OS password can log in as that user. Scope the IAM permission to tagged instances and to your break-glass role, not to every developer.

Step 1: check and enable account access

aws ec2 get-serial-console-access-status --region eu-west-1
# {"SerialConsoleAccessEnabled": false, "ManagedBy": "account"}

aws ec2 enable-serial-console-access --region eu-west-1

If ManagedBy is declarative-policy, the setting is controlled from AWS Organizations and you cannot change it in the account. Ask whoever owns the org policies. An SCP that denies ec2:EnableSerialConsoleAccess or ec2-instance-connect:SendSerialConsoleSSHPublicKey will also block you; see the AccessDenied posts if the call fails.

A minimal IAM policy for a break-glass role, limited by tag:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["ec2:DescribeInstances", "ec2:DescribeInstanceTypes", "ec2:GetSerialConsoleAccessStatus"],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "ec2-instance-connect:SendSerialConsoleSSHPublicKey",
      "Resource": "arn:aws:ec2:eu-west-1:111122223333:instance/*",
      "Condition": {"StringEquals": {"aws:ResourceTag/SerialConsole": "allowed"}}
    }
  ]
}

Step 2: connect over SSH

Push a public key, then connect within 60 seconds. The username is <instance-id>.port0 and the endpoint is per Region.

INSTANCE=i-0abc1234def567890
REGION=eu-west-1

ssh-keygen -t ed25519 -f ~/.ssh/serial -N "" -q   # once

aws ec2-instance-connect send-serial-console-ssh-public-key \
  --instance-id "$INSTANCE" --serial-port 0 \
  --ssh-public-key file://$HOME/.ssh/serial.pub --region "$REGION"

ssh -i ~/.ssh/serial "$INSTANCE.port0@serial-console.ec2-instance-connect.$REGION.aws"

Most commercial Regions use the serial-console.ec2-instance-connect.<region>.aws pattern, but some newer Regions use a different host name. Check the endpoint and fingerprint table in the EC2 User Guide for your Region.

Session rules worth knowing:

  • One active serial session per instance. A second key push fails while someone is connected.
  • After you disconnect, wait about 30 seconds before a new session can start.
  • A session typically lasts up to an hour. Wrap it with timeout 3600 ssh ... if you want it closed for you.
  • Press Enter if the screen is blank. If you see nothing on Linux and the OS is still partly up, sudo systemctl restart serial-getty@ttyS0 (from any working shell) restarts the login prompt.

Step 3 (Linux): fix the common faults

fstab entry stops the boot

Symptom: emergency mode, Give root password for maintenance, or a timeout waiting for dev-xvdf.device or a UUID.

# In the emergency shell
mount -o remount,rw /
cat /etc/fstab
# Comment out the bad line, or add nofail to non-root volumes
sed -i 's|^\(UUID=1234-abcd .*\)defaults|\1defaults,nofail|' /etc/fstab
systemctl daemon-reload
reboot

If you never get a root prompt because root has no password, use single-user mode from GRUB: reboot, press a key at the GRUB menu, press e, append single (or emergency) to the linux line and press Ctrl+X. This only works if GRUB is configured to show its menu on the serial port (see "Prevent it next time").

sshd broken or the firewall blocks port 22

sshd -t                         # prints the config error and line number
journalctl -u sshd -b --no-pager | tail -50
systemctl restart sshd

# Host firewall rules someone added
iptables -S | head -40
firewall-cmd --list-all 2>/dev/null
ufw status 2>/dev/null

On Ubuntu the unit is ssh, not sshd.

Network does not come up

ip -br addr
ip route
journalctl -u systemd-networkd -b --no-pager | tail -50      # AL2023, Ubuntu
journalctl -u NetworkManager -b --no-pager | tail -50        # RHEL
cat /etc/resolv.conf

Typical causes are a static IP left in the network config after an AMI copy, a renamed interface (eth0 vs ens5) after an instance type change, or an old ENA driver after moving to a newer instance family.

SSM Agent stopped

systemctl status amazon-ssm-agent
tail -50 /var/log/amazon/ssm/amazon-ssm-agent.log
systemctl restart amazon-ssm-agent

Hung kernel: SysRq

If the kernel is alive but userspace is stuck, SysRq can sync disks and reboot cleanly. It must be enabled first (kernel.sysrq=1). Send a break with ~B in the SSH client, then a SysRq key such as h for help, s to sync, b to reboot.

Caution

SysRq b reboots immediately without unmounting filesystems. Run s (sync) and u (remount read-only) first if the data matters.

Step 3 (Windows): use SAC

At the SAC> prompt:

SAC> i                  # show network settings
SAC> cmd                # create a command channel (cmd0001)
SAC> ch -si 1           # switch to it, then sign in with an admin account

You can also switch channels with Esc+Tab. In the channel, start powershell and run $ProgressPreference = "SilentlyContinue" to stop progress bars flooding the console. Then fix the problem:

Get-NetFirewallRule -DisplayName "*Remote Desktop*" | Select DisplayName, Enabled, Action
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Get-Service TermService, AmazonSSMAgent | Select Name, Status
Start-Service AmazonSSMAgent
Get-NetIPConfiguration

When the serial console is not the answer

Situation Use instead
Instance type is Xen-based (older t2, m4, c4 and so on) aws ec2 get-console-output --instance-id $INSTANCE --latest --output text and get-console-screenshot, then the rescue-instance volume method
Linux user has no password and GRUB menu not on serial Rescue instance, or an SSM Automation runbook such as AWSSupport-ExecuteEC2Rescue
Instance stuck in stopping or pending The EC2 state troubleshooting runbook; the serial console needs running
Status check fails on the system side Stop and start to move hosts; the console cannot fix hardware

Prevent it next time

Bake these into the AMI so the console is usable when you need it:

  1. A password-based break-glass user on Linux (for example a local rescue user with a strong password kept in Secrets Manager), or sudo passwd root if your policy allows it.

  2. GRUB on the serial port. On Amazon Linux 2 and RHEL, set in /etc/default/grub:

    GRUB_TIMEOUT=1
    GRUB_TERMINAL="console serial"
    GRUB_SERIAL_COMMAND="serial --speed=115200"
    

    and keep console=tty0 console=ttyS0,115200n8 in GRUB_CMDLINE_LINUX_DEFAULT. Apply with sudo grub2-mkconfig -o /boot/grub2/grub.cfg (RHEL 9.3 and later add --update-bls-cmdline). Ubuntu uses /etc/default/grub.d/50-cloudimg-settings.cfg and sudo update-grub. Paths vary by distribution and version, so check your build.

  3. SysRq on: /etc/sysctl.d/99-sysrq.conf containing kernel.sysrq=1.

  4. Windows SAC on, from an elevated PowerShell:

    bcdedit /ems '{current}' on
    bcdedit /emssettings EMSPORT:1 EMSBAUDRATE:115200
    

    Recent EC2LaunchV2 Windows Server AMIs enable SAC by default. Check your AMI's release notes.

  5. nofail on every non-root entry in /etc/fstab.

  6. Enable serial console access in each Region in advance and test a connection during a game day, so the first try is not during an outage.