

# Troubleshoot issues with Amazon EC2 instances
<a name="ec2-instance-troubleshoot"></a>

The following procedures and tips can help you troubleshoot issues with your Amazon EC2 instances.

**Topics**
+ [Instance launch issues](troubleshooting-launch.md)
+ [Instance stop issues](TroubleshootingInstancesStopping.md)
+ [Instance termination issues](TroubleshootingInstancesShuttingDown.md)
+ [Unreachable instances](troubleshoot-unreachable-instance.md)
+ [Linux instance SSH issues](TroubleshootingInstancesConnecting.md)
+ [Linux instance failed status checks](TroubleshootingInstances.md)
+ [Linux instance boots from wrong volume](instance-booting-from-wrong-volume.md)
+ [Windows instance RDP issues](troubleshoot-connect-windows-instance.md)
+ [Windows instance start issues](common-messages.md)
+ [Windows instance issues](win-ts-common-issues.md)
+ [Windows instance kernel debug over network](troubleshoot-windows-with-kdnet.md)
+ [Reset Windows administrator password](ResettingAdminPassword.md)
+ [Troubleshoot Sysprep issues](sysprep-troubleshoot.md)
+ [EC2Rescue for Linux instances](Linux-Server-EC2Rescue.md)
+ [EC2Rescue for Windows instances](Windows-Server-EC2Rescue.md)
+ [EC2 Serial Console](ec2-serial-console.md)
+ [Send diagnostic interrupts](diagnostic-interrupt.md)

# Troubleshoot Amazon EC2 instance launch issues
<a name="troubleshooting-launch"></a>

The following are troubleshooting tips to help you solve issues when launching an Amazon EC2 instance.

**Topics**
+ [Invalid device name](#troubleshooting-launch-devicename)
+ [Instance limit exceeded](#troubleshooting-launch-limit)
+ [Insufficient instance capacity](#troubleshooting-launch-capacity)
+ [The requested configuration is currently not supported. Please check the documentation for supported configurations.](#troubleshooting-instance-configuration)
+ [Instance terminates immediately](#troubleshooting-launch-internal)
+ [Insufficient permissions](#troubleshooting-launch-permissions)
+ [High CPU usage shortly after Windows starts (Windows instances only)](#high-cpu-issue)
+ [Launching an IMDSv1-enabled instance fails](#launching-an-imdsv1-enabled-instance-fails)

## Invalid device name
<a name="troubleshooting-launch-devicename"></a>

### Description
<a name="troubleshooting-launch-devicename-description"></a>

You get the `Invalid device name device_name` error when you try to launch a new instance.

### Cause
<a name="troubleshooting-launch-devicename-cause"></a>

If you get this error when you try to launch an instance, the device name specified for one or more volumes in the request has an invalid device name. Possible causes include:
+ The device name might be in use by the selected AMI.
+ The device name might be reserved for root volumes.
+ The device name might be used for another volume in the request.
+ The device name might not be valid for the operating system.

### Solution
<a name="troubleshooting-launch-devicename-solution"></a>

To resolve the issue:
+ Ensure that the device name is not used in the AMI that you selected. Run the following command to view the device names used by the AMI.

  ```
  aws ec2 describe-images --image-id ami-0abcdef1234567890 --query 'Images[*].BlockDeviceMappings[].DeviceName'
  ```
+ Ensure that you are not using a device name that is reserved for root volumes. For more information, see [Available device names](device_naming.md#available-ec2-device-names).
+ Ensure that each volume specified in your request has a unique device name.
+ Ensure that the device names that you specified are in the correct format. For more information, see [Available device names](device_naming.md#available-ec2-device-names).

## Instance limit exceeded
<a name="troubleshooting-launch-limit"></a>

### Description
<a name="troubleshooting-launch-limit-description"></a>

You get the `InstanceLimitExceeded` error when you try to launch a new instance or restart a stopped instance.

### Cause
<a name="troubleshooting-launch-limit-cause"></a>

If you get an `InstanceLimitExceeded` error when you try to launch a new instance or restart a stopped instance, you have reached the limit on the number of instances that you can launch in a Region. When you create your AWS account, we set default limits on the number of instances you can run on a per-Region basis.

### Solution
<a name="troubleshooting-launch-limit-solution"></a>

You can request an instance limit increase on a per-region basis. For more information, see [Amazon EC2 service quotas](ec2-resource-limits.md).

## Insufficient instance capacity
<a name="troubleshooting-launch-capacity"></a>

### Description
<a name="troubleshooting-launch-capacity-description"></a>

You get the `InsufficientInstanceCapacity` error when you try to launch a new instance or restart a stopped instance.

### Cause
<a name="troubleshooting-launch-capacity-description"></a>

If you get this error when you try to launch an instance or restart a stopped instance, AWS does not currently have enough available On-Demand capacity to fulfill your request.

### Solution
<a name="troubleshooting-launch-capacity-description"></a>

To resolve the issue, try the following:
+ Wait a few minutes and then submit your request again; capacity can shift frequently.
+ Submit a new request with a reduced number of instances. For example, if you're making a single request to launch 15 instances, try making 3 requests for 5 instances, or 15 requests for 1 instance instead.
+ If you're launching an instance, submit a new request without specifying an Availability Zone.
+ If you're launching an instance, submit a new request using a different instance type (which you can resize at a later stage). For more information, see [Amazon EC2 instance type changes](ec2-instance-resize.md).
+ If you are launching instances into a cluster placement group, you can get an insufficient capacity error.

## The requested configuration is currently not supported. Please check the documentation for supported configurations.
<a name="troubleshooting-instance-configuration"></a>

### Description
<a name="troubleshooting-instance-configuration-description"></a>

You get the `Unsupported` error when you try to launch a new instance because the instance configuration is not supported.

### Cause
<a name="troubleshooting-instance-configuration-cause"></a>

The error message provides additional details. For example, an instance type or instance purchasing option might not be supported in the specified Region or Availability Zone.

### Solution
<a name="troubleshooting-instance-configuration-solution"></a>

Try a different instance configuration. To search for an instance type that meets your requirements, see [Find an Amazon EC2 instance type](instance-discovery.md).

## Instance terminates immediately
<a name="troubleshooting-launch-internal"></a>

### Description
<a name="troubleshooting-launch-internal-description"></a>

Your instance goes from the `pending` state to the `terminated` state.

### Cause
<a name="troubleshooting-launch-internal-cause"></a>

The following are a few reasons why an instance might immediately terminate:
+ You've exceeded your EBS volume limits. For more information, see [Amazon EBS volume limits for Amazon EC2 instances](volume_limits.md).
+ An EBS snapshot is corrupted.
+ The root EBS volume is encrypted and you do not have permissions to access the KMS key for decryption.
+ A snapshot specified in the block device mapping for the AMI is encrypted and you do not have permissions to access the KMS key for decryption or you do not have access to the KMS key to encrypt the restored volumes.
+ The Amazon S3-backed AMI that you used to launch the instance is missing a required part (an image.part.*xx* file).

For more information, get the termination reason using one of the following methods.

**To get the termination reason using the Amazon EC2 console**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and select the instance.

1. On the first tab, find the reason next to **State transition reason**.

**To get the termination reason using the AWS CLI**

1. Use the [describe-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) command and specify the instance ID.

   ```
   aws ec2 describe-instances --instance-id i-1234567890abcdef0
   ```

1. Review the JSON response returned by the command and note the values in the `StateReason` response element.

   The following code block shows an example of a `StateReason` response element.

   ```
   "StateReason": {
     "Message": "Client.VolumeLimitExceeded: Volume limit exceeded", 
     "Code": "Server.InternalError"
   },
   ```

**To get the termination reason using AWS CloudTrail**  
For more information, see [Viewing events with CloudTrail event history](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html) in the *AWS CloudTrail User Guide*.

### Solution
<a name="troubleshooting-launch-internal-solution"></a>

Depending on the termination reason, take one of the following actions:
+ **`Client.VolumeLimitExceeded: Volume limit exceeded`** — Delete unused volumes. You can [submit a request](https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase&limitType=service-code-ebs) to increase your volume limit.
+ **`Client.InternalError: Client error on launch`** — Ensure that you have the permissions required to access the AWS KMS keys used to decrypt and encrypt volumes. For more information, see [Using key policies in AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html) in the *AWS Key Management Service Developer Guide*.

## Insufficient permissions
<a name="troubleshooting-launch-permissions"></a>

### Description
<a name="troubleshooting-launch-permissions-description"></a>

You get the `"errorMessage": "You are not authorized to perform this operation."` error when you try to launch a new instance, and the launch fails.

### Cause
<a name="troubleshooting-launch-permissions-cause"></a>

If you get this error when you try to launch an instance, you don't have the required IAM permissions to launch the instance.

Possible missing permissions include:
+ `ec2:RunInstances`
+ `iam:PassRole`

Other permissions might also be missing. For the list of permissions required to launch an instance, see the example IAM policies under [Example: Use the EC2 launch instance wizard](iam-policies-ec2-console.md#ex-launch-wizard) and [Launch instances (RunInstances)](ExamplePolicies_EC2.md#iam-example-runinstances).

### Solution
<a name="troubleshooting-launch-permissions-solution"></a>

To resolve the issue:
+ If you are making requests as an IAM user, verify that you have the following permissions:
  + `ec2:RunInstances` with a wildcard resource ("\$1")
  + `iam:PassRole` with the resource matching the role ARN (for example, `arn:aws:iam::999999999999:role/ExampleRoleName`)
+ If you don't have the preceding permissions, [edit the IAM policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-edit.html) associated with the IAM role or user to add the missing required permissions.

If your issue is not resolved and you continue receiving a launch failure error, you can decode the authorization failure message included in the error. The decoded message includes the permissions that are missing from the IAM policy. For more information, see [How do I decode an authorization failure message after I receive an "UnauthorizedOperation" error during an EC2 instance launch?](https://repost.aws/knowledge-center/ec2-not-auth-launch)

## High CPU usage shortly after Windows starts (Windows instances only)
<a name="high-cpu-issue"></a>

**Note**  
This troubleshooting tip is for Windows instances only.

If Windows Update is set to **Check for updates but let me choose whether to download and install them** (the default instance setting) this check can consume anywhere from 50 - 99% of the CPU on the instance. If this CPU consumption causes problems for your applications, you can manually change Windows Update settings in **Control Panel** or you can use the following script in the Amazon EC2 user data field:

```
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 3 /f net stop wuauserv net start wuauserv
```

When you run this script, specify a value for /d. The default value is 3. Possible values include the following: 

1. Never check for updates

1. Check for updates but let me choose whether to download and install them

1. Download updates but let me choose whether to install them

1. Install updates automatically

After you modify the user data for your instance, you can run it. For more information, see [Run commands on your Windows instance at launch](user-data.md).

## Launching an IMDSv1-enabled instance fails
<a name="launching-an-imdsv1-enabled-instance-fails"></a>

### Description
<a name="launching-an-imdsv1-enabled-instance-fails-description"></a>

You get an `UnsupportedOperation` exception with the following message:

`You can't launch instances with IMDSv1 because httpTokensEnforced is enabled for this account. Either launch the instance with httpTokens=required or contact your account owner to disable httpTokensEnforced using the ModifyInstanceMetadataDefaults API or the account settings in the EC2 console.`

### Cause
<a name="launching-an-imdsv1-enabled-instance-fails-cause"></a>

This error is thrown when you attempt to launch a new instance to be IMDSv1 enabled (`httpTokens = optional`) in an account where the EC2 account settings or an AWS Organization declarative policy enforces the use of IMDSv2 (`httpTokensEnforced = enabled`). 

### Solution
<a name="launching-an-imdsv1-enabled-instance-fails-solution"></a>

If you’re ready to use IMDSv2 only, launch your instance with IMDSv1 disabled (`httpTokens = required`). To check if you’re ready, see [Transition to using Instance Metadata Service Version 2](instance-metadata-transition-to-version-2.md).

If you still require IMDSv1 support on new or existing instances, you'll need to disable IMDSv2 enforcement for the account in the Region. To disable IMDSv2 enforcement, set `HttpTokensEnforced` to `disabled`. For more information, see [ModifyInstanceMetadataDefaults](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceMetadataDefaults.html) in the Amazon EC2 API Reference. If you prefer to configure this setting using the console, see [Enforce IMDSv2 at the account level](configuring-IMDS-new-instances.md#enforce-imdsv2-at-the-account-level).

 

# Troubleshoot Amazon EC2 instance stop issues
<a name="TroubleshootingInstancesStopping"></a>

If your Amazon EBS-backed instance appears stuck in the `stopping` state, the issue might be with the underlying host computer.

To resolve the issue, follow these steps:

1. **Force stop the instance**

   Use the Amazon EC2 console or the AWS CLI to force stop the instance. For the steps, see [Force stop an instance](#force-stop-instance).

   The instance will first attempt a graceful shutdown, which includes flushing file system caches and metadata (although you can optionally bypass the graceful shutdown). If the graceful shutdown fails to complete within the timeout period, the instance shuts down forcibly without flushing the file system caches and metadata.

1. **After force stop**

   Perform file system check and repair procedures.
**Important**  
Performing these procedures is crucial because a forced stop prevents flushing of file system caches and metadata.

1. **If force stop fails**

   If, after 10 minutes, the instance has not stopped, do the following:

   1. Post a request for help on [AWS re:Post](https://repost.aws/). To help expedite a resolution, include the instance ID, and describe the steps that you've already taken.

   1. Alternatively, if you have a support plan, create a technical support case in the [Support Center](https://console.aws.amazon.com/support/home#/).

   1. While waiting for assistance, you can create a replacement instance if needed. For the steps, see [(Optional) Create a replacement instance](#Creating_Replacement_Instance).

There is no cost for instance usage while an instance is in the `stopping` state or in any other state except `running`. You are only charged for instance usage when an instance is in the `running` state.

**Topics**
+ [Force stop an instance](#force-stop-instance)
+ [(Optional) Create a replacement instance](#Creating_Replacement_Instance)

## Force stop an instance
<a name="force-stop-instance"></a>

You can force an instance to stop. If, after 10 minutes, the instance has not stopped, post a request for help on [AWS re:Post](https://repost.aws/). To help expedite a resolution, include the instance ID, and describe the steps that you've already taken. Alternatively, if you have a support plan, create a technical support case in the [Support Center](https://console.aws.amazon.com/support/home#/).

**Note**  
Using the console, you can force an instance to stop while the instance is in the `stopping` state only. Using the AWS CLI, you can force an instance to stop while the instance is in the `pending`, `running`, or `stopping` state.

------
#### [ Console ]

**To force stop an instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and select the stuck instance.

1. Choose **Instance state**, **Force stop instance**.

   Note that **Force stop instance** is only available in the console if your instance is in the `stopping` state. If your instance is in another state (except `shutting-down` and `terminated`) you can use the AWS CLI to force stop your instance.

1. (Optional) To bypass the graceful OS shutdown during the force stop, select the **Skip OS shutdown** checkbox.

1. Choose **Force stop**.

------
#### [ AWS CLI ]

**To force stop an instance**  
Use the [stop-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/stop-instances.html) command with the `--force` option.

```
aws ec2 stop-instances \
    --instance-ids i-1234567890abcdef0 \
    --force
```

To bypass the graceful OS shutdown during force stop, include the `--skip-os-shutdown` option.

```
aws ec2 stop-instances \
    --instance-ids i-1234567890abcdef0 \
    --force \
    --skip-os-shutdown
```

------
#### [ PowerShell ]

**To force stop an instance**  
Use the [Stop-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Stop-EC2Instance.html) cmdlet and set `-Enforce` to `true`.

```
Stop-EC2Instance `
    -InstanceId i-1234567890abcdef0 `
    -Enforce $true
```

To bypass the graceful OS shutdown during force stop, include `-SkipOsShutdown $true`.

```
Stop-EC2Instance `
    -InstanceId i-1234567890abcdef0 `
    -Enforce $true `
    -SkipOsShutdown $true
```

------

## (Optional) Create a replacement instance
<a name="Creating_Replacement_Instance"></a>

While you are waiting for assistance from [AWS re:Post](https://repost.aws/) or the [Support Center](https://console.aws.amazon.com/support/home#/), you can create a replacement instance if needed. Create an AMI from the stuck instance, and launch a new instance using the new AMI.

**Important**  
You can create a replacement instance if the stuck instance produces [system status checks](monitoring-instances-status-check.md) only, as instance status checks will result in the AMI copying over an exact replica of the broken operating system. After you've confirmed the status message, create the AMI and launch a new instance using the new AMI.

------
#### [ Console ]

**To create a replacement instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and select the stuck instance.

1. Choose **Actions**, **Image and templates**, **Create image**.

1. On the **Create image** page, do the following:

   1. Enter a name and description for the AMI.

   1. Clear **Reboot instance**.

   1. Choose **Create image**.

   For more information, see [Create an AMI from an instance](creating-an-ami-ebs.md#how-to-create-ebs-ami).

1. Launch a new instance from the AMI and verify that the new instance is working.

1. Select the stuck instance, and choose **Actions**, **Instance state**, **Terminate (delete) instance**. If the instance also gets stuck terminating, Amazon EC2 automatically forces it to terminate within a few hours.

If you are unable to create an AMI from the instance as described in the previous procedure, you can set up a replacement instance as follows:

**(Alternate) To create a replacement instance using the console**

1. Select the instance and choose **Description**, **Block devices**. Select each volume and make note of its volume ID. Be sure to note which volume is the root volume.

1. In the navigation pane, choose **Volumes**. Select each volume for the instance, and choose **Actions**, **Create Snapshot**.

1. In the navigation pane, choose **Snapshots**. Select the snapshot that you just created, and choose **Actions**, **Create Volume**.

1. Launch an instance with the same operating system as the stuck instance. Note the volume ID and device name of its root volume.

1. In the navigation pane, choose **Instances**, select the instance that you just launched, and choose **Instance state**, **Stop instance**.

1. In the navigation pane, choose **Volumes**, select the root volume of the stopped instance, and choose **Actions**, **Detach Volume**.

1. Select the root volume that you created from the stuck instance, choose **Actions**, **Attach Volume**, and attach it to the new instance as its root volume (using the device name that you made note of). Attach any additional non-root volumes to the instance.

1. In the navigation pane, choose **Instances** and select the replacement instance. Choose **Instance state**, **Start instance**. Verify that the instance is working.

1. Select the stuck instance, choose **Instance state**, **Terminate (delete) instance**. If the instance also gets stuck terminating, Amazon EC2 automatically forces it to terminate within a few hours.

------
#### [ AWS CLI ]

**To create a replacement instance**

1. Create an AMI from the stuck instance using the [create-image](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-image.html) command with the `--no-reboot` option.

   ```
   aws ec2 create-image \
       --instance-id i-1234567890abcdef0 \
       --name "my-replacement-ami" \
       --description ""AMI for replacement instance" \
       --no-reboot
   ```

1. Launch a new instance from the AMI that you just created, using the [run-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html) command.

1. Verify that the new instance is working.

1. (Optional) Terminate the stuck instance using the [terminate-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/terminate-instances.html) command.

   ```
   aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
   ```

------
#### [ PowerShell ]

**To create a replacement instance**

1. Create an AMI from the stuck instance using the [New-EC2Image](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Image.html) cmdlet and set `-NoReboot` to `true`.

   ```
   New-EC2Image `
       -InstanceId i-1234567890abcdef0 `
       -Name "my-replacement-ami" `
       -Description "AMI for replacement instance" `
       -NoReboot $true
   ```

1. Launch a new instance from the AMI that you just created, using the [New-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Instance.html) cmdlet.

1. Verify that the new instance is working.

1. (Optional) Terminate the stuck instance using the [Remove-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Remove-EC2Instance.html) cmdlet.

   ```
   Remove-EC2Instance -InstanceId i-1234567890abcdef0
   ```

------

# Troubleshoot Amazon EC2 instance termination issues
<a name="TroubleshootingInstancesShuttingDown"></a>

Shutting down or deleting your instance is known as instance termination. The following information can help you troubleshoot issues when you terminate your instance.

You are not billed for any instance usage while an instance is not in the `running` state. In other words, when you terminate an instance, you stop incurring charges for that instance as soon as its state changes to `shutting-down`.

## Instance terminates immediately
<a name="instance-terminates-immediately"></a>

Several issues can cause your instance to terminate immediately on start-up. See [Instance terminates immediately](troubleshooting-launch.md#troubleshooting-launch-internal) for more information.

## Delayed instance termination
<a name="instance-stuck-terminating"></a>

If your instance remains in the `shutting-down` state longer than a few minutes, it might be because:
+ The instance is running shutdown scripts.
+ There's a problem with the underlying host computer.

After several hours in the `shutting-down` state, Amazon EC2 treats the instance as stuck and forcibly terminates it.

To resolve a stuck instance yourself:

1. **Force terminate the instance**

   Use the Amazon EC2 console or the AWS CLI to force terminate the instance. For the steps, see [Force terminate an instance](#force-terminate-ec2-instance).

   The instance will first attempt a graceful shutdown, which includes flushing file system caches and metadata (although you can optionally bypass the graceful shutdown). If the graceful shutdown fails to complete within the timeout period, the instance shuts down forcibly without flushing the file system caches and metadata.

1. **If force terminate fails**

   If, after several hours, the instance has not terminated and it appears stuck terminating, do the following:

   1. Post a request for help on [AWS re:Post](https://repost.aws/). To help expedite a resolution, include the instance ID, and describe the steps that you've already taken.

   1. Alternatively, if you have a support plan, create a technical support case in the [Support Center](https://console.aws.amazon.com/support/home#/).

### Force terminate an instance
<a name="force-terminate-ec2-instance"></a>

If it appears that your instance is stuck terminating, you can force your instance to terminate. If, after several hours, the instance has not terminated, post a request for help to [AWS re:Post](https://repost.aws/). To help expedite a resolution, include the instance ID and describe the steps that you've already taken. Alternatively, if you have a support plan, create a technical support case in the [Support Center](https://console.aws.amazon.com/support/home#/).

------
#### [ Console ]

**To force terminate an instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and select the stuck instance.

1. Choose **Instance state**, **Force terminate instance**.

   Note that **Force terminate instance** is only available in the console if your instance is in the `stopping` state. If your instance is in another state (except `shutting-down` and `terminated`) you can use the AWS CLI to force terminate your instance.

1. (Optional) To bypass the graceful OS shutdown during the force terminate, select the **Skip OS shutdown** checkbox.

1. Choose **Force terminate**.

------
#### [ AWS CLI ]

**To force terminate an instance**  
Use the [terminate-instances](https://docs.aws.amazon.com/cli/latest/reference/ec2/terminate-instances.html) command with the `--force` option.

```
aws ec2 terminate-instances \
    --instance-ids i-1234567890abcdef0 \
    --force
```

To bypass the graceful OS shutdown during force terminate, include the `--skip-os-shutdown` option.

```
aws ec2 terminate-instances \
    --instance-ids i-1234567890abcdef0 \
    --force \
    --skip-os-shutdown
```

------
#### [ PowerShell ]

**To force terminate an instance**  
Use the [Remove-EC2Instance](https://docs.aws.amazon.com/powershell/latest/reference/items/Remove-EC2Instance.html) cmdlet and set `-Enforce` to `true`.

```
Remove-EC2Instance `
    -InstanceId i-1234567890abcdef0 `
    -Enforce $true
```

To bypass the graceful OS shutdown during force terminate, include `-SkipOsShutdown $true`.

```
Remove-EC2Instance `
    -InstanceId i-1234567890abcdef0 `
    -Enforce $true `
    -SkipOsShutdown $true
```

------

## Terminated instance still displayed
<a name="terminated-instance-still-displaying"></a>

After you terminate an instance, it remains visible for a short while before being deleted. The state shows as `terminated`. If the entry is not deleted after several hours, contact Support.

## Error: The instance may not be terminated. Modify its 'disableApiTermination' instance attribute
<a name="termination-protection-enabled"></a>

If you try to terminate an instance and get the `The instance i-1234567890abcdef0 may not be terminated. Modify its 'disableApiTermination' instance attribute` error message, it indicates that the instance has been enabled for termination protection. Termination protection prevents the instance from being accidentally terminated.

You must disable termination protection before you can terminate the instance.

For more information, see [Change instance termination protection](Using_ChangingDisableAPITermination.md).

## Instances automatically launched or terminated
<a name="automatic-instance-create-or-delete"></a>

Generally, the following behaviors mean that you've used Amazon EC2 Auto Scaling, EC2 Fleet, or Spot Fleet to scale your computing resources automatically based on criteria that you've defined:
+ You terminate an instance and a new instance launches automatically.
+ You launch an instance and one of your instances terminates automatically.
+ You stop an instance and it terminates and a new instance launches automatically.

To stop automatic scaling, find the Auto Scaling group or the fleet that is launching the instances and either set its capacity to 0 or delete it.

# Troubleshoot an unreachable Amazon EC2 instance
<a name="troubleshoot-unreachable-instance"></a>

The following information can help you troubleshoot unreachable Amazon EC2 instances. You can capture screenshots or access console output to help diagnose problems and determine if you should reboot your instance. For unreachable Windows instances, troubleshoot by reviewing screenshots returned by the service. 

**Topics**
+ [Instance reboot](#instance-console-rebooting)
+ [Instance console output](#instance-console-console-output)
+ [Capture a screenshot of an unreachable instance](#instance-console-screenshot)
+ [Common screenshots for Windows instances](ics-common.md)
+ [Instance recovery when a host computer fails](#instance-machine-failure)
+ [Instance appeared offline and unexpectedly rebooted](#troubleshoot-unavailable-instance-unexpected-reboot)

## Instance reboot
<a name="instance-console-rebooting"></a>

The ability to reboot instances that are otherwise unreachable is valuable for both troubleshooting and general instance management.

Just as you can reset a computer by pressing the reset button, you can reset EC2 instances using the Amazon EC2 console, CLI, or API. For more information, see [Reboot your Amazon EC2 instance](ec2-instance-reboot.md).

## Instance console output
<a name="instance-console-console-output"></a>

Console output is a valuable tool for problem diagnosis. It is especially useful for troubleshooting kernel problems and service configuration issues that could cause an instance to terminate or become unreachable before its SSH daemon can be started. 
+ **Linux instances** – The instance console output displays the exact console output that would normally be displayed on a physical monitor attached to a computer. The console output returns buffered information that was posted shortly after an instance transition state (start, stop, reboot, and terminate). The posted output is not continuously updated; only when it is likely to be of the most value.
+ **Windows instances** – The instance console output includes the last three system event log errors.

Only the instance owner can access the console output.

You can retrieve the latest serial console output during the instance lifecycle. This option is only supported on [Nitro-based instances](instance-types.md#instance-hypervisor-type).

------
#### [ Console ]

**To get console output**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**.

1. Select the instance.

1. Choose **Actions**, **Monitor and troubleshoot**, **Get system log**.

------
#### [ AWS CLI ]

**To get console output**  
Use the [get-console-output](https://docs.aws.amazon.com/cli/latest/reference/ec2/get-console-output.html) command.

```
aws ec2 get-console-output --instance-id i-1234567890abcdef0
```

------
#### [ PowerShell ]

**To get console output**  
Use the [Get-EC2ConsoleOutput](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ConsoleOutput.html) cmdlet.

```
Get-EC2ConsoleOutput -InstanceId i-1234567890abcdef0
```

------

## Capture a screenshot of an unreachable instance
<a name="instance-console-screenshot"></a>

If you are unable to connect to your instance, you can capture a screenshot of your instance and view it as an image. The image can provide visibility as to the status of the instance, and allows for quicker troubleshooting.

You can generate screenshots while the instance is running or after it has crashed. The image is generated in JPG format and is no larger than 100 kb. There is no data transfer cost for the screenshot.

**Limitations**

This feature is not supported for the following:
+ Bare metal instances (instances of type `*.metal`)
+ Instance is using an NVIDIA GRID driver
+ [Instances powered by Arm-based Graviton processors](https://aws.amazon.com/ec2/graviton/#EC2_Instances_Powered_by_AWS_Graviton_Processors)
+ Windows instances on AWS Outposts
+ Windows instances on AWS Local Zones

**Region support**

This feature is not available in the following Regions:
+ Asia Pacific (Thailand)
+ Mexico (Central)
+ GovCloud Regions

------
#### [ Console ]

**To get a screenshot of an instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the left navigation pane, choose **Instances**.

1. Select the instance to capture.

1. Choose **Actions**, **Monitor and troubleshoot**, **Get instance screenshot**.

1. Choose **Download**, or right-click the image to download and save it.

------
#### [ AWS CLI ]

**To capture a screenshot of an instance**  
Use the [get-console-screenshot](https://docs.aws.amazon.com/cli/latest/reference/ec2/get-console-screenshot.html) command. The output is base64-encoded.

```
aws ec2 get-console-screenshot --instance-id i-1234567890abcdef0
```

------
#### [ PowerShell ]

**To capture a screenshot of an instance**  
Use the [Get-EC2ConsoleScreenshot](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ConsoleScreenshot.html) cmdlet. The output is base64-encoded.

```
Get-EC2ConsoleScreenshot -InstanceId i-1234567890abcdef0
```

------

# Common screenshots to troubleshoot unreachable Windows instances
<a name="ics-common"></a>

You can use the following information to help you troubleshoot an unreachable Windows instance based on screenshots returned by the service.
+ [Log on screen (Ctrl\$1Alt\$1Delete)](#logon-screen) 
+ [Recovery console screen](#recovery-console-screen) 
+ [Windows boot manager screen](#boot-manager-screen) 
+ [Sysprep screen](#sysprep-screen) 
+ [Getting ready screen](#getting-ready-screen) 
+ [Windows Update screen](#windows-update-screen) 
+ [Chkdsk](#Chkdsk) 

## Log on screen (Ctrl\$1Alt\$1Delete)
<a name="logon-screen"></a>

Console Screenshot Service returned the following.

![\[Log on screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-1.png)


If an instance becomes unreachable during logon, there could be a problem with your network configuration or Windows Remote Desktop Services. An instance can also be unresponsive if a process is using large amounts of CPU. 

### Network configuration
<a name="network-config"></a>

Use the following information to verify that your AWS, Microsoft Windows, and local (or on-premises) network configurations aren't blocking access to the instance.


**AWS network configuration**  

| Configuration | Verify | 
| --- | --- | 
| Security group configuration | Verify that port 3389 is open for your security group. Verify you are connecting to the right public IP address. If the instance was not associated with an Elastic IP, the public IP changes after the instance stops/starts. For more information, see [Remote Desktop can't connect to the remote computer](troubleshoot-connect-windows-instance.md#rdp-issues). | 
| VPC configuration (Network ACLs) | Verify that the access control list (ACL) for your Amazon VPC is not blocking access. For information, see [Network ACLs](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html) in the Amazon VPC User Guide. | 
| VPN configuration | If you are connecting to your VPC using a virtual private network (VPN), verify VPN tunnel connectivity. For more information, see [Troubleshooting AWS Client VPN: Tunnel connectivity issues to a VPC](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/VPNTunnelConnectivityTroubleshooting.html). | 


**Windows network configuration**  

| Configuration | Verify | 
| --- | --- | 
| Windows Firewall | Verify that Windows Firewall isn't blocking connections to your instance. Disable Windows Firewall as described in bullet 7 of the remote desktop troubleshooting section, [Remote Desktop can't connect to the remote computer](troubleshoot-connect-windows-instance.md#rdp-issues).  | 
| Advanced TCP/IP configuration (Use of static IP) | The instance may be unresponsive because you configured a static IP address. For a VPC, [create a network interface](create-network-interface.md) and [attach it to the instance](network-interface-attachments.md#attach_eni).  | 

**Local or on-premises network configuration**

Verify that a local network configuration isn't blocking access. Try to connect to another instance in the same VPC as your unreachable instance. If you can't access another instance, work with your local network administrator to determine whether a local policy is restricting access.

### Remote Desktop Services issues
<a name="rds-issue"></a>

If the instance can't be reached during logon, there could a problem with Remote Desktop Services (RDS) on the instance.

**Tip**  
You can use the `AWSSupport-TroubleshootRDP` runbook to check and modify various settings that might affect Remote Desktop Protocol (RDP) connections. For more information, see [https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshootrdp.html](https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshootrdp.html) in the *AWS Systems Manager Automation runbook reference*.


**Remote Desktop Services configuration**  

| Configuration | Verify | 
| --- | --- | 
| RDS is running | Verify that RDS is running on the instance. Connect to the instance using the Microsoft Management Console (MMC) Services snap-in (services.msc). In the list of services, verify that Remote Desktop Services is Running. If it isn't, start it and then set the startup type to Automatic. If you can't connect to the instance by using the Services snap-in, detach the root volume from the instance, take a snapshot of the volume or create an AMI from it, attach the original volume to another instance in the same Availability Zone as a secondary volume, and modify the [Start](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-2000-server/cc959920(v=technet.10)) registry key. When you are finished, reattach the root volume to the original instance. | 
| RDS is enabled |  Even if the service is started, it might be disabled. Detach the root volume from the instance, take a snapshot of the volume or create an AMI from it, attach the original volume to another instance in the same Availability Zone as a secondary volume, and enable the service by modifying the **Terminal Server** registry key as described in [Enable Remote Desktop on an EC2 instance with remote registry](troubleshoot-connect-windows-instance.md#troubleshooting-windows-rdp-remote-registry). When you are finished, reattach the root volume to the original instance.  | 

### High CPU usage
<a name="high-cpu"></a>

Check the **CPUUtilization (Maximum)** metric on your instance by using Amazon CloudWatch. If **CPUUtilization (Maximum)** is a high number, wait for the CPU to go down and try connecting again. High CPU usage can be caused by:
+ Windows Update
+ Security Software Scan
+ Custom Startup Script
+ Task Scheduler

For more information, see [Get Statistics for a Specific Resource](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SingleMetricPerInstance.html) in the *Amazon CloudWatch User Guide*. For additional troubleshooting tips, see [High CPU usage shortly after Windows starts (Windows instances only)](troubleshooting-launch.md#high-cpu-issue).

## Recovery console screen
<a name="recovery-console-screen"></a>

Console Screenshot Service returned the following.

![\[Recovery console screenshot.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-2.png)


The operating system might boot into the Recovery console and get stuck in this state if the `bootstatuspolicy` is not set to `ignoreallfailures`. Use the following procedure to change the `bootstatuspolicy` configuration to `ignoreallfailures`.

By default, the policy configuration for public Windows AMIs provided by AWS is set to `ignoreallfailures`.

1. Stop the unreachable instance.

1. Create a snapshot of the root volume. The root volume is attached to the instance as `/dev/sda1`. 

   Detach the root volume from the unreachable instance, take a snapshot of the volume or create an AMI from it, and attach it to another instance in the same Availability Zone as a secondary volume.
**Warning**  
If your temporary instance and the original instance were launched using the same AMI, you must complete additional steps or you won't be able to boot the original instance after you restore its root volume because of a disk signature collision. If you must create a temporary instance using the same AMI, to avoid a disk signature collision, complete the steps in [Disk signature collision](win-ts-common-issues.md#disk-signature-collision).  
Alternatively, select a different AMI for the temporary instance. For example, if the original instance uses an AMI for Windows Server 2016, launch the temporary instance using an AMI for Windows Server 2019.

1. Log in to the instance and run the following command from a command prompt to change the `bootstatuspolicy` configuration to `ignoreallfailures`.

   ```
   bcdedit /store Drive Letter:\boot\bcd /set {default} bootstatuspolicy ignoreallfailures
   ```

1. Reattach the volume to the unreachable instance and start the instance again.

## Windows boot manager screen
<a name="boot-manager-screen"></a>

Console Screenshot Service returned the following.

![\[Windows Boot Manager Screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-3.png)


The operating system experienced a fatal corruption in the system file and/or the registry. When the instance is stuck in this state, you should recover the instance from a recent backup AMI or launch a replacement instance. If you need to access data on the instance, detach any root volumes from the unreachable instance, take a snapshot of those volume or create an AMI from them, and attach them to another instance in the same Availability Zone as a secondary volume.

## Sysprep screen
<a name="sysprep-screen"></a>

Console Screenshot Service returned the following.

![\[Sysprep Screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-4.png)


You may see this screen if you did not use the EC2Config Service to call Sysprep or if the operating system failed while running Sysprep. You can reset the password using [EC2Rescue](Windows-Server-EC2Rescue.md). Otherwise, see [Create an Amazon EC2 AMI using Windows Sysprep](ami-create-win-sysprep.md).

## Getting ready screen
<a name="getting-ready-screen"></a>

Console Screenshot Service returned the following.

![\[Getting Ready Screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-5.png)


Refresh the Instance Console Screenshot Service repeatedly to verify that the progress ring is spinning. If the ring is spinning, wait for the operating system to start up. You can also check the **CPUUtilization (Maximum)** metric on your instance by using Amazon CloudWatch to see if the operating system is active. If the progress ring is not spinning, the instance may be stuck at the boot process. Reboot the instance. If rebooting does not solve the problem, recover the instance from a recent backup AMI or launch a replacement instance. If you need to access data on the instance, detach the root volume from the unreachable instance, take a snapshot of the volume or create an AMI from it. Then attach it to another instance in the same Availability Zone as a secondary volume.

## Windows Update screen
<a name="windows-update-screen"></a>

Console Screenshot Service returned the following.

![\[Windows Update Screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-6.png)


The Windows Update process is updating the registry. Wait for the update to finish. Do not reboot or stop the instance as this may cause data corruption during the update.

**Note**  
The Windows Update process can consume resources on the server during the update. If you experience this problem often, consider using faster instance types and faster EBS volumes. 

## Chkdsk
<a name="Chkdsk"></a>

Console Screenshot Service returned the following.

![\[Chkdsk Screen.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/ts-cs-7.png)


Windows is running the chkdsk system tool on the drive to verify file system integrity and fix logical file system errors. Wait for process to complete.

## Instance recovery when a host computer fails
<a name="instance-machine-failure"></a>

If there is an unrecoverable issue with the hardware of an underlying host computer, AWS may schedule an instance stop event. You are notified of such an event ahead of time by email.

**To recover an Amazon EBS-backed instance running on a host computer that failed**

1. Back up any important data on your instance store volumes to Amazon EBS or Amazon S3.

1. Stop the instance.

1. Start the instance.

1. Restore any important data.

For more information, see [Stop and start Amazon EC2 instances](Stop_Start.md).

**To recover an instance with an instance store root volume running on a host computer that failed**

1. Create an AMI from the instance.

1. Upload the image to Amazon S3.

1. Back up important data to Amazon EBS or Amazon S3.

1. Terminate the instance.

1. Launch a new instance from the AMI.

1. Restore any important data to the new instance.

## Instance appeared offline and unexpectedly rebooted
<a name="troubleshoot-unavailable-instance-unexpected-reboot"></a>

If your instance appears to have been offline and then unexpectedly rebooted, it might have undergone automatic instance recovery. This happens when AWS detects that the instance is unavailable due to an underlying hardware or software issue, and either simplified automatic recovery or CloudWatch action based recovery is enabled on the instance.

During the recovery process, AWS attempts to restore the instance's availability by migrating it to different hardware. To verify whether automatic instance recovery occurred for your instance, see [Verify if automatic instance recovery occurred](verify-if-automatic-recovery-occurred.md).

**Note**  
If your workload or application is unresponsive, check whether it's running on the instance. If it's not, start it manually. To prevent this issue in the future, implement a recovery plan to ensure your workload or application functions properly after instance recovery.

# Troubleshoot issues connecting to your Amazon EC2 Linux instance
<a name="TroubleshootingInstancesConnecting"></a>

The following information and common errors can help you troubleshoot connecting to your Linux instance. 

**Topics**
+ [Common causes for connection issues](#TroubleshootingInstancesCommonCauses)
+ [Error connecting to your instance: Connection timed out](#TroubleshootingInstancesConnectionTimeout)
+ [Error: unable to load key ... Expecting: ANY PRIVATE KEY](#troubleshoot-instance-connect-key-file)
+ [Error: User key not recognized by server](#TroubleshootingInstancesServerError)
+ [Error: Permission denied or connection closed by [instance] port 22](#TroubleshootingInstancesConnectingSSH)
+ [Error: Unprotected private key file](#troubleshoot-unprotected-key)
+ [Error: Private key must begin with "-----BEGIN RSA PRIVATE KEY-----" and end with "-----END RSA PRIVATE KEY-----"](#troubleshoot-private-key-file-format)
+ [Error: Host key verification failed](#troubleshoot-host-key-verification-failed)
+ [Error: Server refused our key *or* No supported authentication methods available](#TroubleshootingInstancesConnectingPuTTY)
+ [Cannot ping instance](#troubleshoot-instance-ping)
+ [Error: Server unexpectedly closed network connection](#troubleshoot-ssh)
+ [Error: Host key validation failed for EC2 Instance Connect](#troubleshoot-host-key-validation)
+ [Can't connect to Ubuntu instance using EC2 Instance Connect](#troubleshoot-eic-ubuntu)
+ [I've lost my private key. How can I connect to my instance?](#replacing-lost-key-pair)

## Common causes for connection issues
<a name="TroubleshootingInstancesCommonCauses"></a>

We recommend that you start to troubleshoot instance connection problems by verifying that you have accurately performed the following tasks.

**Verify the username for your instance**  
You can connect to your instance using the username for your user account or the default username for the AMI that you used to launch your instance.  
+ **Get the username for your user account.**

  For more information about how to create a user account, see [Manage system users on your Amazon EC2 Linux instance](managing-users.md).
+ **Get the default username for the AMI that you used to launch your instance.**    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html)

**Verify that your security group rules allow traffic**  
Ensure that the security group associated with your instance allows incoming SSH traffic from your IP address. The default security group for the VPC does not allow incoming SSH traffic by default. The security group created by the launch instance wizard enables SSH traffic by default. For steps to add a rule for inbound SSH traffic to your Linux instance, see [Rules to connect to instances from your computer](security-group-rules-reference.md#sg-rules-local-access). For steps to verify, see [Error connecting to your instance: Connection timed out](#TroubleshootingInstancesConnectionTimeout).

**Verify that your instance is ready**  
After you launch an instance, it can take a few minutes for the instance to be ready to accept connection requests. Check your instance to make sure it is running and has passed its status checks.  

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and then select your instance.

1. Verify the following:

   1. In the **Instance state** column, verify that your instance is in the `running` state.

   1. In the **Status check** column, verify that your instance has passed all status checks.

**Verify that you've satisfied all prerequisites to connect**  
Ensure that you have all the information that you need to connect. For more information, see [Connect to your Linux instance using SSH](connect-to-linux-instance.md).  
**Connect from Linux or macOS X**  
If your local computer operating system is Linux or macOS X, check the following for specific prerequisites for connecting to a Linux instance:
+ [SSH client](connect-linux-inst-ssh.md)
+ [EC2 Instance Connect](connect-linux-inst-eic.md)
+ [AWS Systems Manager Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html)
**Connect from Windows**  
If your local computer operating system is Windows, check the following for specific prerequisites for connecting to a Linux instance:
+ [OpenSSH](connect-linux-inst-ssh.md)
+ [PuTTY](connect-linux-inst-from-windows.md)
+ [AWS Systems Manager Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html)
+ [Windows Subsystem for Linux](connect-linux-inst-ssh.md)

**Check if the instance is a managed instance**  
User-initiated connections to managed instances are not allowed. To determine if the instance is managed, find the **Managed** field for the instance. If the value is **true**, it's a managed instance. For more information, see [Amazon EC2 managed instances](amazon-ec2-managed-instances.md).

## Error connecting to your instance: Connection timed out
<a name="TroubleshootingInstancesConnectionTimeout"></a>

If you try to connect to your instance and get the error message `Network error: Connection timed out` or `Error connecting to [instance], reason: -> Connection timed out: connect`, try the following:

**Check your security group rules.**  
You need a security group rule that allows inbound traffic from your local computer's public IPv4 address on the proper port.

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and then select your instance.

1. On the **Security** tab at the bottom of the console page, under **Inbound rules**, check the list of rules that are in effect for the selected instance. Verify that there is a rule that allows traffic from your local computer to port 22 (SSH).

   If your security group does not have a rule that allows inbound traffic from your local computer, add a rule to your security group. For more information, see [Rules to connect to instances from your computer](security-group-rules-reference.md#sg-rules-local-access).

1. For the rule that allows inbound traffic, check the **Source** field. If the value is a single IP address, and if the IP address is not static, a new IP address will be assigned each time you restart your computer. This will result in the rule not including your computer's IP address traffic. The IP address might not be static if your computer is on a corporate network, or you're connecting through an internet service provider (ISP), or your computer IP address is dynamic and changes each time you restart your computer. To ensure that your security group rule allows inbound traffic from your local computer, instead of specifying a single IP address for **Source**, rather specify the range of IP addresses used by your client computers.

   For more information about security group rules, see [Security group rules](https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html) in the *Amazon VPC User Guide*.

**Check the route table for the subnet.**  
You need a route that sends all traffic destined outside the VPC to the internet gateway for the VPC.

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and then select your instance.

1. On the **Networking** tab, make note of the values for **VPC ID** and **Subnet ID**.

1. Open the Amazon VPC console at [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/).

1. In the navigation pane, choose **Internet Gateways**. Verify that there is an internet gateway attached to your VPC. Otherwise, choose **Create internet gateway**, enter a name for the internet gateway, and choose **Create internet gateway**. Then, for the internet gateway you created, choose **Actions**, **Attach to VPC**, select your VPC, and then choose **Attach internet gateway** to attach it to your VPC.

1. In the navigation pane, choose **Subnets**, and then select your subnet.

1. On the **Route table** tab, verify that there is a route with `0.0.0.0/0` as the destination and the internet gateway for your VPC as the target. If you're connecting to your instance using its IPv6 address, verify that there is a route for all IPv6 traffic (`::/0`) that points to the internet gateway. Otherwise, do the following:

   1. Choose the ID of the route table (rtb-*xxxxxxxx*) to navigate to the route table.

   1. On the **Routes** tab, choose **Edit routes**. Choose **Add route**, use `0.0.0.0/0` as the destination and the internet gateway as the target. For IPv6, choose **Add route**, use `::/0` as the destination and the internet gateway as the target.

   1. Choose **Save routes**.

**Check the network access control list (ACL) for the subnet.**

The network ACLs must allow inbound SSH traffic from your local IP address on port 22. It must also allow outbound traffic to the ephemeral ports (1024-65535).

1. Open the Amazon VPC console at [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/).

1. In the navigation pane, choose **Subnets**.

1. Select your subnet.

1. On the **Network ACL** tab, for **Inbound rules**, verify that the rules allow inbound traffic from your computer on the required port. Otherwise, delete or modify the rule that is blocking the traffic.

1. For **Outbound rules**, verify that the rules allow outbound traffic to your computer on the ephemeral ports. Otherwise, delete or modify the rule that is blocking the traffic.

**If your computer is on a corporate network**  
Ask your network administrator whether the internal firewall allows inbound and outbound traffic from your computer on port 22.

If you have a firewall on your computer, verify that it allows inbound and outbound traffic from your computer on port 22.

**Check that your instance has a public IPv4 address.**  
If not, you can associate an Elastic IP address with your instance. For more information, see [Elastic IP addresses](elastic-ip-addresses-eip.md). 

**Check the CPU load on your instance; the server may be overloaded.**  
AWS automatically provides data such as Amazon CloudWatch metrics and instance status, which you can use to see how much CPU load is on your instance and, if necessary, adjust how your loads are handled. For more information, see [Monitor your instances using CloudWatch](using-cloudwatch.md).
+ If your load is variable, you can automatically scale your instances up or down using [Auto Scaling](https://aws.amazon.com/autoscaling/) and [Elastic Load Balancing](https://aws.amazon.com/elasticloadbalancing/). 
+ If your load is steadily growing, you can move to a larger instance type. For more information, see [Amazon EC2 instance type changes](ec2-instance-resize.md). 

**To connect to your instance using an IPv6 address, check the following:**
+ Your subnet must be associated with a route table that has a route for IPv6 traffic (`::/0`) to an internet gateway. 
+ Your security group rules must allow inbound traffic from your local IPv6 address on port 22.
+ Your network ACL rules must allow inbound and outbound IPv6 traffic.
+ If you launched your instance from an older AMI, it might not be configured for DHCPv6 (IPv6 addresses are not automatically recognized on the network interface). For more information, see [Configure IPv6 on your instances](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-migrate-ipv6.html#vpc-migrate-ipv6-dhcpv6) in the *Amazon VPC User Guide*.
+ Your local computer must have an IPv6 address, and must be configured to use IPv6.

## Error: unable to load key ... Expecting: ANY PRIVATE KEY
<a name="troubleshoot-instance-connect-key-file"></a>

If you try to connect to your instance and get the error message, `unable to load key ... Expecting: ANY PRIVATE KEY`, the file in which the private key is stored is incorrectly configured. If the private key file ends in `.pem`, it might still be incorrectly configured. A possible cause for an incorrectly configured private key file is a missing certificate.

**If the private key file is incorrectly configured, follow these steps to resolve the error**

1. Create a new key pair. For more information, see [Create a key pair using Amazon EC2](create-key-pairs.md#having-ec2-create-your-key-pair).
**Note**  
Alternatively, you can create a new key pair using a third-party tool. For more information, see [Create a key pair using a third-party tool and import the public key to Amazon EC2](create-key-pairs.md#how-to-generate-your-own-key-and-import-it-to-aws).

1. Add the new key pair to your instance. For more information, see [I've lost my private key. How can I connect to my instance?](#replacing-lost-key-pair).

1. Connect to your instance using the new key pair.

## Error: User key not recognized by server
<a name="TroubleshootingInstancesServerError"></a>

**If you use SSH to connect to your instance**
+ Use `ssh -vvv` to get triple verbose debugging information while connecting:

  ```
  ssh -vvv -i path/key-pair-name.pem instance-user-name@ec2-203-0-113-25.compute-1.amazonaws.com
  ```

  The following sample output demonstrates what you might see if you were trying to connect to your instance with a key that was not recognized by the server:

  ```
  open/ANT/myusername/.ssh/known_hosts).
  debug2: bits set: 504/1024
  debug1: ssh_rsa_verify: signature correct
  debug2: kex_derive_keys
  debug2: set_newkeys: mode 1
  debug1: SSH2_MSG_NEWKEYS sent
  debug1: expecting SSH2_MSG_NEWKEYS
  debug2: set_newkeys: mode 0
  debug1: SSH2_MSG_NEWKEYS received
  debug1: Roaming not allowed by server
  debug1: SSH2_MSG_SERVICE_REQUEST sent
  debug2: service_accept: ssh-userauth
  debug1: SSH2_MSG_SERVICE_ACCEPT received
  debug2: key: boguspem.pem ((nil))
  debug1: Authentications that can continue: publickey
  debug3: start over, passed a different list publickey
  debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
  debug3: authmethod_lookup publickey
  debug3: remaining preferred: keyboard-interactive,password
  debug3: authmethod_is_enabled publickey
  debug1: Next authentication method: publickey
  debug1: Trying private key: boguspem.pem
  debug1: read PEM private key done: type RSA
  debug3: sign_and_send_pubkey: RSA 9c:4c:bc:0c:d0:5c:c7:92:6c:8e:9b:16:e4:43:d8:b2
  debug2: we sent a publickey packet, wait for reply
  debug1: Authentications that can continue: publickey
  debug2: we did not send a packet, disable method
  debug1: No more authentication methods to try.
  Permission denied (publickey).
  ```

**If you use PuTTY to connect to your instance**
+ Verify that your private key (.pem) file has been converted to the format recognized by PuTTY (.ppk). For more information about converting your private key, see [Connect to your Linux instance using PuTTY](connect-linux-inst-from-windows.md).
**Note**  
In PuTTYgen, load your private key file and select **Save Private Key** rather than **Generate**. 
+ Verify that you are connecting with the appropriate username for your AMI. Enter the username in the **Host name** box in the **PuTTY Configuration** window.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html)
+ Verify that you have an inbound security group rule to allow inbound traffic to the appropriate port. For more information, see [Rules to connect to instances from your computer](security-group-rules-reference.md#sg-rules-local-access). 

## Error: Permission denied or connection closed by [instance] port 22
<a name="TroubleshootingInstancesConnectingSSH"></a>

If you connect to your instance using SSH and get any of the following errors, `Host key not found in [directory]`, `Permission denied (publickey)`, `Authentication failed, permission denied`, or `Connection closed by [instance] port 22`, verify that you are connecting with the appropriate username for your AMI *and* that you have specified the proper private key (`.pem)` file for your instance.

The appropriate usernames are as follows:


| AMI used to launch instance | Default username | 
| --- | --- | 
|  Amazon Linux  | ec2-user  | 
| CentOS | centos or ec2-user | 
| Debian | admin | 
| Fedora  | fedora or ec2-user | 
| FreeBSD | ec2-user | 
| RHEL | ec2-user or root | 
| SUSE  | ec2-user or root | 
| Ubuntu  | ubuntu | 
| Oracle  | ec2-user | 
| Bitnami  | bitnami | 
| Rocky Linux  | rocky | 
| Other | Check with the AMI provider | 

For example, to use an SSH client to connect to an Amazon Linux instance, use the following command:

```
ssh -i /path/key-pair-name.pem instance-user-name@ec2-203-0-113-25.compute-1.amazonaws.com
```

Confirm that you are using the private key file that corresponds to the key pair that you selected when you launched the instance.

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and then select your instance.

1. On the **Details** tab, under **Instance details**, verify the value of **Key pair name**.

1. If you did not specify a key pair when you launched the instance, you can terminate the instance and launch a new instance, ensuring that you specify a key pair. If this is an instance that you have been using but you no longer have the `.pem` file for your key pair, you can replace the key pair with a new one. For more information, see [I've lost my private key. How can I connect to my instance?](#replacing-lost-key-pair).

If you generated your own key pair, ensure that your key generator is set up to create RSA keys. DSA keys are not accepted.

If you get a `Permission denied (publickey)` error and none of the above applies (for example, you were able to connect previously), the permissions on the home directory of your instance may have been changed. Permissions for `/home/instance-user-name/.ssh/authorized_keys` must be limited to the owner only.

**To verify the permissions on your instance**

1. Stop your instance and detach the root volume. For more information, see [Stop and start Amazon EC2 instances](Stop_Start.md).

1. Launch a temporary instance in the same Availability Zone as your current instance (use a similar or the same AMI as you used for your current instance), and attach the root volume to the temporary instance.

1. Connect to the temporary instance, create a mount point, and mount the volume that you attached.

1. From the temporary instance, check the permissions of the `/home/instance-user-name/` directory of the attached volume. If necessary, adjust the permissions as follows:

   ```
   [ec2-user ~]$ chmod 600 mount_point/home/instance-user-name/.ssh/authorized_keys
   ```

   ```
   [ec2-user ~]$ chmod 700 mount_point/home/instance-user-name/.ssh
   ```

   ```
   [ec2-user ~]$ chmod 700 mount_point/home/instance-user-name
   ```

1. Unmount the volume, detach it from the temporary instance, and re-attach it to the original instance. Ensure that you specify the correct device name for the root volume; for example, `/dev/xvda`.

1. Start your instance. If you no longer require the temporary instance, you can terminate it.

## Error: Unprotected private key file
<a name="troubleshoot-unprotected-key"></a>

Your private key file must be protected from read and write operations from any other users. If your private key can be read or written to by anyone but you, then SSH ignores your key and you see the following warning message below.

```
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '.ssh/my_private_key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: .ssh/my_private_key.pem
Permission denied (publickey).
```

If you see a similar message when you try to log in to your instance, examine the first line of the error message to verify that you are using the correct public key for your instance. The above example uses the private key `.ssh/my_private_key.pem` with file permissions of `0777`, which allow anyone to read or write to this file. This permission level is very insecure, and so SSH ignores this key. 

If you are connecting from macOS or Linux, run the following command to fix this error, substituting the path for your private key file.

```
[ec2-user ~]$ chmod 0400 .ssh/my_private_key.pem
```

If you are connecting to a Linux instance from Windows, perform the following steps on your local computer.

1. Navigate to your .pem file.

1. Right-click on the .pem file and select **Properties**.

1. Choose the **Security** tab.

1. Select **Advanced**.

1. Verify that you are the owner of the file. If not, change the owner to your username.

1. Select **Disable inheritance** and **Remove all inherited permissions from this object**.

1. Select **Add**, **Select a principal**, enter your username, and select **OK**.

1. From the **Permission Entry** window, grant **Read** permissions and select **OK**.

1. Click **Apply** to ensure all settings are saved.

1. Select **OK** to close the **Advanced Security Settings** window.

1. Select **OK** to close the **Properties** window.

1. You should be able to connect to your Linux instance from Windows using SSH.

From a Windows command prompt, run the following commands.

1. From the command prompt, navigate to the file path location of your .pem file.

1. Run the following command to reset and remove explicit permissions:

   ```
   icacls.exe $path /reset
   ```

1. Run the following command to grant Read permissions to the current user:

   ```
   icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
   ```

1. Run the following command to disable inheritance and remove inherited permissions.

   ```
   icacls.exe $path /inheritance:r
   ```

1. You should be able to connect to your Linux instance from Windows using SSH.

## Error: Private key must begin with "-----BEGIN RSA PRIVATE KEY-----" and end with "-----END RSA PRIVATE KEY-----"
<a name="troubleshoot-private-key-file-format"></a>

If you use a third-party tool, such as **ssh-keygen**, to create an RSA key pair, it generates the private key in the OpenSSH key format. When you connect to your instance, if you use the private key in the OpenSSH format to decrypt the password, you'll get the error `Private key must begin with "-----BEGIN RSA PRIVATE KEY-----" and end with "-----END RSA PRIVATE KEY-----"`.

To resolve the error, the private key must be in the PEM format. Use the following command to create the private key in the PEM format:

```
ssh-keygen -m PEM
```

## Error: Host key verification failed
<a name="troubleshoot-host-key-verification-failed"></a>

This error occurs if there is a mismatch between the host key stored on the instance in the `known_hosts` file and on the client. For example, a mismatch can occur if you connect to an instance using one public IP address, and then try to connect to it again using a different public IP address. This can happen after you add or remove an Elastic IP address, as doing so changes the public IP address of an instance.

To resolve this error, start by confirming that there was an expected change to the host key or the network configuration of the instance. Before you connect to the instance, you might also want to [verify the host fingerprint](connection-prereqs-general.md#connection-prereqs-fingerprint). After you connect to the instance, you can remove the old host key from the `known_hosts` file. For instructions, refer to the documentation for the Linux distribution in use on your instance.

## Error: Server refused our key *or* No supported authentication methods available
<a name="TroubleshootingInstancesConnectingPuTTY"></a>

If you use PuTTY to connect to your instance and get either of the following errors, Error: Server refused our key or Error: No supported authentication methods available, verify that you are connecting with the appropriate username for your AMI. Type the username in **User name** in the **PuTTY Configuration** window.

The appropriate usernames are as follows:


| AMI used to launch instance | Default username | 
| --- | --- | 
|  Amazon Linux  | ec2-user  | 
| CentOS | centos or ec2-user | 
| Debian | admin | 
| Fedora  | fedora or ec2-user | 
| FreeBSD | ec2-user | 
| RHEL | ec2-user or root | 
| SUSE  | ec2-user or root | 
| Ubuntu  | ubuntu | 
| Oracle  | ec2-user | 
| Bitnami  | bitnami | 
| Rocky Linux  | rocky | 
| Other | Check with the AMI provider | 

You should also verify that:
+ You are using the latest version of PuTTY. For more information, see the [PuTTY web page](https://www.chiark.greenend.org.uk/~sgtatham/putty/).
+ Your private key (.pem) file has been correctly converted to the format recognized by PuTTY (.ppk). For more information about converting your private key, see [Connect to your Linux instance using PuTTY](connect-linux-inst-from-windows.md).

## Cannot ping instance
<a name="troubleshoot-instance-ping"></a>

The `ping` command is a type of ICMP traffic — if you are unable to ping your instance, ensure that your inbound security group rules allow ICMP traffic for the `Echo Request` message from all sources, or from the computer or instance from which you are issuing the command.

If you are unable to issue a `ping` command from your instance, ensure that your outbound security group rules allow ICMP traffic for the `Echo Request` message to all destinations, or to the host that you are attempting to ping.

`Ping` commands can also be blocked by a firewall or time out due to network latency or hardware issues. You should consult your local network or system administrator for help with further troubleshooting.

## Error: Server unexpectedly closed network connection
<a name="troubleshoot-ssh"></a>

If you are connecting to your instance with PuTTY and you receive the error "Server unexpectedly closed network connection," verify that you have enabled keepalives on the Connection page of the PuTTY Configuration to avoid being disconnected. Some servers disconnect clients when they do not receive any data within a specified period of time. Set the Seconds between keepalives to 59 seconds. 

If you still experience issues after enabling keepalives, try to disable Nagle's algorithm on the Connection page of the PuTTY Configuration. 

## Error: Host key validation failed for EC2 Instance Connect
<a name="troubleshoot-host-key-validation"></a>

If you rotate your instance host keys, the new host keys are not automatically uploaded to the AWS trusted host keys database. This causes host key validation to fail when you try to connect to your instance using the EC2 Instance Connect browser-based client, and you're unable to connect to your instance.

To resolve the error, you must run the `eic_harvest_hostkeys` script on your instance, which uploads your new host key to EC2 Instance Connect. The script is located at `/opt/aws/bin/` on Amazon Linux 2 instances, and at `/usr/share/ec2-instance-connect/` on Ubuntu instances.

------
#### [ Amazon Linux 2 ]

**To resolve the host key validation failed error on an Amazon Linux 2 instance**

1. Connect to your instance using SSH.

   You can connect by using the EC2 Instance Connect CLI or by using the SSH key pair that was assigned to your instance when you launched it and the default username of the AMI that you used to launch your instance. For Amazon Linux 2, the default username is `ec2-user`.

   For example, if your instance was launched using Amazon Linux 2, your instance's public DNS name is `ec2-a-b-c-d.us-west-2.compute.amazonaws.com`, and the key pair is `my_ec2_private_key.pem`, use the following command to SSH into your instance:

   ```
   $ ssh -i my_ec2_private_key.pem ec2-user@ec2-a-b-c-d.us-west-2.compute.amazonaws.com
   ```

   For more information about connecting to your instance, see [Connect to your Linux instance using an SSH client](connect-linux-inst-ssh.md).

1. Navigate to the following folder.

   ```
   [ec2-user ~]$ cd /opt/aws/bin/
   ```

1. Run the following command on your instance. 

   ```
   [ec2-user ~]$ ./eic_harvest_hostkeys
   ```

   Note that a successful call results in no output.

   You can now use the EC2 Instance Connect browser-based client to connect to your instance.

------
#### [ Ubuntu ]

**To resolve the host key validation failed error on an Ubuntu instance**

1. Connect to your instance using SSH.

   You can connect by using the EC2 Instance Connect CLI or by using the SSH key pair that was assigned to your instance when you launched it and the default username of the AMI that you used to launch your instance. For Ubuntu, the default username is `ubuntu`.

   For example, if your instance was launched using Ubuntu, your instance's public DNS name is `ec2-a-b-c-d.us-west-2.compute.amazonaws.com`, and the key pair is `my_ec2_private_key.pem`, use the following command to SSH into your instance:

   ```
   $ ssh -i my_ec2_private_key.pem ubuntu@ec2-a-b-c-d.us-west-2.compute.amazonaws.com
   ```

   For more information about connecting to your instance, see [Connect to your Linux instance using an SSH client](connect-linux-inst-ssh.md).

1. Navigate to the following folder.

   ```
   [ec2-user ~]$ cd /usr/share/ec2-instance-connect/
   ```

1. Run the following command on your instance. 

   ```
   [ec2-user ~]$ ./eic_harvest_hostkeys
   ```

   Note that a successful call results in no output.

   You can now use the EC2 Instance Connect browser-based client to connect to your instance.

------

## Can't connect to Ubuntu instance using EC2 Instance Connect
<a name="troubleshoot-eic-ubuntu"></a>

If you use EC2 Instance Connect to connect to your Ubuntu instance and you get an error when attempting to connect, you can use the following information to try to fix the issue.

**Possible cause**

The `ec2-instance-connect` package on the instance is not the latest version.

**Solution**

Update the `ec2-instance-connect` package on the instance to the latest version, as follows:

1. [Connect](connect-to-linux-instance.md) to your instance using a method other than EC2 Instance Connect.

1. Run the following command on your instance to update the `ec2-instance-connect` package to the latest version.

   ```
   apt update && apt upgrade
   ```

## I've lost my private key. How can I connect to my instance?
<a name="replacing-lost-key-pair"></a>

If you lose the private key for an EBS-backed instance, you can regain access to your instance. You must stop the instance, detach its root volume and attach it to another instance as a data volume, modify the `authorized_keys` file with a new public key, move the volume back to the original instance, and restart the instance. For more information about launching, connecting to, and stopping instances, see [Amazon EC2 instance state changes](ec2-instance-lifecycle.md).

This procedure is only supported for instances with EBS root volumes. If the instance has an instance store root volume, you cannot use this procedure to regain access to your instance; you must have the private key to connect to the instance. To determine the root volume type of your instance, open the Amazon EC2 console, choose **Instances**, select the instance, choose the **Storage** tab, and in the **Root device details** section, check the value of **Root device type**. 

The value is either `EBS` or `INSTANCE-STORE`.

In addition to the following steps, there are other ways to connect to your Linux instance if you lose your private key. For more information, see [How can I connect to my Amazon EC2 instance if I lost my SSH key pair after its initial launch?](https://repost.aws/knowledge-center/user-data-replace-key-pair-ec2)

**Topics**
+ [Step 1: Create a new key pair](#step-1-create-new-key-pair)
+ [Step 2: Get information about the original instance and its root volume](#step-2-get-info-about-original-instance)
+ [Step 3: Stop the original instance](#step-3-stop-original-instance)
+ [Step 4: Launch a temporary instance](#step-4-launch-temp-instance)
+ [Step 5: Detach the root volume from the original instance and attach it to the temporary instance](#step-5-detach-root-volume-and-attach-to-temp-instance)
+ [Step 6: Add the new public key to `authorized_keys` on the original volume mounted to the temporary instance](#step-6-add-new-public-key-to-authorized_keys)
+ [Step 7: Unmount and detach the original volume from the temporary instance, and reattach it to the original instance](#step-7-unmount-detach-volume-and-reattach-to-original-instance)
+ [Step 8: Connect to the original instance using the new key pair](#step-8-connect-to-original-instance)
+ [Step 9: Clean up](#step-9-clean-up)

### Step 1: Create a new key pair
<a name="step-1-create-new-key-pair"></a>

Create a new key pair using either the Amazon EC2 console or a third-party tool. If you want to name your new key pair exactly the same as the lost private key, you must first delete the existing key pair. For information about creating a new key pair, see [Create a key pair using Amazon EC2](create-key-pairs.md#having-ec2-create-your-key-pair) or [Create a key pair using a third-party tool and import the public key to Amazon EC2](create-key-pairs.md#how-to-generate-your-own-key-and-import-it-to-aws).

### Step 2: Get information about the original instance and its root volume
<a name="step-2-get-info-about-original-instance"></a>

Make note of the following information because you'll need it to complete this procedure.

**To get information about your original instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. Choose **Instances** in the navigation pane, and then select the instance that you'd like to connect to. (We'll refer to this as the *original* instance.)

1. On the **Details** tab, make note of the instance ID and AMI ID.

1. On the **Networking** tab, make note of the Availability Zone.

1. On the **Storage** tab, under **Root device name**, make note of the device name for the root volume (for example, `/dev/xvda`). Then, under **Block devices**, find this device name and make note of the volume ID (for example, vol-0a1234b5678c910de).

### Step 3: Stop the original instance
<a name="step-3-stop-original-instance"></a>

Choose **Instance state**, **Stop instance**. If this option is disabled, either the instance is already stopped or its root volume is an instance store volume.

**Warning**  
When you stop an instance, the data on instance store volumes is lost. To preserve this data, back it up to persistent storage.

### Step 4: Launch a temporary instance
<a name="step-4-launch-temp-instance"></a>

**To launch a temporary instance**

1. In the navigation pane, choose **Instances**, and then choose **Launch instances**.

1. In the **Name and tags** section, for **Name**, enter **Temporary**.

1. In the **Application and OS Images** section, select the same AMI that you used to launch the original instance. If this AMI is unavailable, you can create an AMI that you can use from the stopped instance. For more information, see [Create an Amazon EBS-backed AMI](creating-an-ami-ebs.md).

1. In the **Instance type** section, keep the default instance type.

1. In the **Key pair** section, for **Key pair name**, select the existing key pair to use or create a new one.

1. In the **Network settings** section, choose **Edit**, and then for **Subnet**, select a subnet in the same Availability Zone as the original instance.

1. In the **Summary** panel, choose **Launch**.

### Step 5: Detach the root volume from the original instance and attach it to the temporary instance
<a name="step-5-detach-root-volume-and-attach-to-temp-instance"></a>

1. In the navigation pane, choose **Volumes** and select the root volume for the original instance (you made note of its volume ID in a previous step). Choose **Actions**, **Detach volume**, and then choose **Detach**. Wait for the state of the volume to become `available`. (You might need to choose the Refresh icon.)

1. With the volume still selected, choose **Actions**, and then choose **Attach volume**. Select the instance ID of the temporary instance, make note of the device name specified under **Device name** (for example, `/dev/sdf`), and then choose **Attach volume**.
**Note**  
If you launched your original instance from an AWS Marketplace AMI and your volume contains AWS Marketplace codes, you must first stop the temporary instance before you can attach the volume.

### Step 6: Add the new public key to `authorized_keys` on the original volume mounted to the temporary instance
<a name="step-6-add-new-public-key-to-authorized_keys"></a>

1. Connect to the temporary instance.

1. From the temporary instance, mount the volume that you attached to the instance so that you can access its file system. For example, if the device name is `/dev/sdf`, use the following commands to mount the volume as `/mnt/tempvol`.<a name="device-name"></a>
**Note**  
The device name might appear differently on your instance. For example, devices mounted as `/dev/sdf` might show up as `/dev/xvdf` on the instance. Some versions of Red Hat (or its variants, such as CentOS) might even increment the trailing letter by 4 characters, where `/dev/sdf` becomes `/dev/xvdk`.

   1. Use the **lsblk** command to determine if the volume is partitioned.

      ```
      [ec2-user ~]$ lsblk
      NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
      xvda    202:0    0    8G  0 disk
      └─xvda1 202:1    0    8G  0 part /
      xvdf    202:80   0  101G  0 disk
      └─xvdf1 202:81   0  101G  0 part
      xvdg    202:96   0   30G  0 disk
      ```

      In the preceding example, `/dev/xvda` and `/dev/xvdf` are partitioned volumes, and `/dev/xvdg` is not. If your volume is partitioned, you mount the partition (`/dev/xvdf1)` instead of the raw device (`/dev/xvdf`) in the next steps.

   1. Create a temporary directory to mount the volume.

      ```
      [ec2-user ~]$ sudo mkdir /mnt/tempvol
      ```

   1. Mount the volume (or partition) at the temporary mount point, using the volume name or device name that you identified earlier. The required command depends on your operating system's file system. Note that the device name might appear differently on your instance. See the [note](#device-name) in Step 6 for more information.
      + Amazon Linux, Ubuntu, and Debian

        ```
        [ec2-user ~]$ sudo mount /dev/xvdf1 /mnt/tempvol
        ```
      + Amazon Linux 2, CentOS, SUSE Linux 12, and RHEL 7.x

        ```
        [ec2-user ~]$ sudo mount -o nouuid /dev/xvdf1 /mnt/tempvol
        ```
**Note**  
If you get an error stating that the file system is corrupt, run the following command to use the **fsck** utility to check the file system and repair any issues:  

   ```
   [ec2-user ~]$ sudo fsck /dev/xvdf1
   ```

1. From the temporary instance, use the following command to update `authorized_keys` on the mounted volume with the new public key from the `authorized_keys` for the temporary instance.
**Important**  
The following examples use the Amazon Linux username `ec2-user`. You might need to substitute a different username, such as `ubuntu` for Ubuntu instances.

   ```
   [ec2-user ~]$ cp .ssh/authorized_keys /mnt/tempvol/home/ec2-user/.ssh/authorized_keys
   ```

   If this copy succeeded, you can go to the next step.

   (Optional) Otherwise, if you don't have permission to edit files in `/mnt/tempvol`, you must update the file using **sudo** and then check the permissions on the file to verify that you are able to log into the original instance. Use the following command to check the permissions on the file.

   ```
   [ec2-user ~]$ sudo ls -l /mnt/tempvol/home/ec2-user/.ssh
   total 4
   -rw------- 1 222 500 398 Sep 13 22:54 authorized_keys
   ```

   In this example output, *222* is the user ID and *500* is the group ID. Next, use **sudo** to re-run the copy command that failed.

   ```
   [ec2-user ~]$ sudo cp .ssh/authorized_keys /mnt/tempvol/home/ec2-user/.ssh/authorized_keys
   ```

   Run the following command again to determine whether the permissions changed.

   ```
   [ec2-user ~]$ sudo ls -l /mnt/tempvol/home/ec2-user/.ssh
   ```

   If the user ID and group ID have changed, use the following command to restore them.

   ```
   [ec2-user ~]$ sudo chown 222:500 /mnt/tempvol/home/ec2-user/.ssh/authorized_keys
   ```

### Step 7: Unmount and detach the original volume from the temporary instance, and reattach it to the original instance
<a name="step-7-unmount-detach-volume-and-reattach-to-original-instance"></a>

1. From the temporary instance, unmount the volume that you attached so that you can reattach it to the original instance. For example, use the following command to unmount the volume at `/mnt/tempvol`.

   ```
   [ec2-user ~]$ sudo umount /mnt/tempvol
   ```

1. Detach the volume from the temporary instance (you unmounted it in the previous step): From the Amazon EC2 console, choose **Volumes** in the navigation pane, select the root volume for the original instance (you made note of the volume ID in a previous step), choose **Actions**, **Detach volume**, and then choose **Detach**. Wait for the state of the volume to become `available`. (You might need to choose the Refresh icon.)

1. Reattach the volume to the original instance: With the volume still selected, choose **Actions**, **Attach volume**. Select the instance ID of the original instance, specify the device name that you noted earlier in [Step 2](#step-2-get-info-about-original-instance) for the original root volume attachment (`/dev/sda1` or `/dev/xvda`), and then choose **Attach volume**.
**Important**  
If you don't specify the same device name as the original attachment, you cannot start the original instance. Amazon EC2 expects the root volume at `sda1` or `/dev/xvda`.

### Step 8: Connect to the original instance using the new key pair
<a name="step-8-connect-to-original-instance"></a>

Select the original instance, choose **Instance state**, **Start instance**. After the instance enters the `running` state, you can connect to it using the private key file for your new key pair.

**Note**  
If the name of your new key pair and corresponding private key file is different from the name of the original key pair, ensure that you specify the name of the new private key file when you connect to your instance.

### Step 9: Clean up
<a name="step-9-clean-up"></a>

(Optional) You can terminate the temporary instance if you have no further use for it. Select the temporary instance, and choose **Instance state**, **Terminate (delete) instance**.

# Troubleshoot Amazon EC2 Linux instances with failed status checks
<a name="TroubleshootingInstances"></a>

The following information can help you troubleshoot issues if your Linux instance fails a status check. First determine whether your applications are exhibiting any problems. If you verify that the instance is not running your applications as expected, review the status check information and the system logs.

For examples of problems that can cause status checks to fail, see [Status checks for Amazon EC2 instances](monitoring-system-instance-status-check.md).

**Topics**
+ [Review status check information](#InitialSteps)
+ [Retrieve the system logs](#troubleshooting-retrieve-system-logs)
+ [Troubleshoot system log errors for Linux instances](#system-log-errors-linux)
+ [Out of memory: kill process](#MemoryOOM)
+ [ERROR: mmu\$1update failed (Memory management update failed)](#MemoryMMU)
+ [I/O error (block device failure)](#DeviceBlock)
+ [I/O ERROR: neither local nor remote disk (Broken distributed block device)](#DeviceDistributed)
+ [request\$1module: runaway loop modprobe (Looping legacy kernel modprobe on older Linux versions)](#KernelLoop)
+ ["FATAL: kernel too old" and "fsck: No such file or directory while trying to open /dev" (Kernel and AMI mismatch)](#KernelOld)
+ ["FATAL: Could not load /lib/modules" or "BusyBox" (Missing kernel modules)](#KernelMissing)
+ [ERROR Invalid kernel (EC2 incompatible kernel)](#KernelInvalid)
+ [fsck: No such file or directory while trying to open... (File system not found)](#FilesystemFschk)
+ [General error mounting filesystems (failed mount)](#FilesystemGeneral)
+ [VFS: Unable to mount root fs on unknown-block (Root filesystem mismatch)](#FilesystemKernel)
+ [Error: Unable to determine major/minor number of root device... (Root file system/device mismatch)](#FilesystemError)
+ [XENBUS: Device with no driver...](#FilesystemXenbus)
+ [... days without being checked, check forced (File system check required)](#FilesystemCheck)
+ [fsck died with exit status... (Missing device)](#FilesystemFschkDied)
+ [GRUB prompt (grubdom>)](#OpSystemGrub)
+ [Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring. (Hard-coded MAC address)](#OpSystemBringing)
+ [Unable to load SELinux Policy. Machine is in enforcing mode. Halting now. (SELinux misconfiguration)](#OpSystemUnable)
+ [XENBUS: Timeout connecting to devices (Xenbus timeout)](#OpSystemXenbus)

## Review status check information
<a name="InitialSteps"></a>

**To investigate impaired instances using the Amazon EC2 console**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and then select your instance.

1. Select the **Status and alarms** tab to see the individual results for all **System status checks**, **Instance status checks**, and **Attached EBS status checks**.

If a status check has failed, you can try one of the following options:
+ Create an alarm to recover the instance in response to the failed status check. For more information, see [Create alarms that stop, terminate, reboot, or recover an instance](UsingAlarmActions.md).
+ (Instance status checks) If you changed the instance type to a [Nitro-based instance](instance-types.md#instance-hypervisor-type), status checks fail if you migrated from an instance that does not have the required ENA and NVMe drivers. For more information, see [Compatibility for changing the instance type](resize-limitations.md).
+ For an instance with an EBS root volume, stop and restart the instance. For more information, see [Stop and start Amazon EC2 instances](Stop_Start.md).
+ For an instance with an instance store root volume, terminate the instance and launch a replacement instance. For more information, see [Terminate Amazon EC2 instances](terminating-instances.md).
+ Wait for Amazon EC2 to resolve the issue.
+ Contact Support or post your issue to [AWS re:Post](https://repost.aws/).
+ If your instance is in an Auto Scaling group:
  + (System status checks and instance status checks) By default, Amazon EC2 Auto Scaling automatically launches a replacement instance. For more information, see [Health checks for instances in an Auto Scaling group](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-health-checks.html) in the *Amazon EC2 Auto Scaling User Guide*.
  + (Attached EBS status checks) You must configure Amazon EC2 Auto Scaling to automatically launch a replacement instance. For more information, see [ Monitor and replace Auto Scaling instances with impaired Amazon EBS volumes](https://docs.aws.amazon.com/autoscaling/ec2/userguide/monitor-and-replace-instances-with-impaired-ebs-volumes.html) in the *Amazon EC2 Auto Scaling User Guide*.
+ Retrieve the system log and look for errors. For more information, see [Retrieve the system logs](#troubleshooting-retrieve-system-logs).

## Retrieve the system logs
<a name="troubleshooting-retrieve-system-logs"></a>

If an instance status check fails, you can reboot the instance and retrieve the system logs. The logs may reveal an error that can help you troubleshoot the issue. Rebooting clears unnecessary information from the logs.

**To reboot an instance and retrieve the system log**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**, and select your instance.

1. Choose **Instance state**, **Reboot instance**. It might take a few minutes for your instance to reboot.

1. Verify that the problem still exists; in some cases, rebooting may resolve the problem.

1. When the instance is in the `running` state, choose **Actions**, **Monitor and troubleshoot**, **Get system log**.

1. Review the log that appears on the screen, and use the list of known system log error statements below to troubleshoot your issue.

1. If your issue is not resolved, you can post your issue to [AWS re:Post](https://repost.aws/).

## Troubleshoot system log errors for Linux instances
<a name="system-log-errors-linux"></a>

For Linux instances that have failed an instance status check, such as the instance reachability check, verify that you followed the steps above to retrieve the system log. The following list contains some common system log errors and suggested actions you can take to resolve the issue for each error.

**Memory Errors**
+ [Out of memory: kill process](#MemoryOOM)
+ [ERROR: mmu\$1update failed (Memory management update failed)](#MemoryMMU)

**Device Errors**
+ [I/O error (block device failure)](#DeviceBlock)
+ [I/O ERROR: neither local nor remote disk (Broken distributed block device)](#DeviceDistributed)

**Kernel Errors**
+ [request\$1module: runaway loop modprobe (Looping legacy kernel modprobe on older Linux versions)](#KernelLoop)
+ ["FATAL: kernel too old" and "fsck: No such file or directory while trying to open /dev" (Kernel and AMI mismatch)](#KernelOld)
+ ["FATAL: Could not load /lib/modules" or "BusyBox" (Missing kernel modules)](#KernelMissing)
+ [ERROR Invalid kernel (EC2 incompatible kernel)](#KernelInvalid)

**File System Errors**
+ [fsck: No such file or directory while trying to open... (File system not found)](#FilesystemFschk)
+ [General error mounting filesystems (failed mount)](#FilesystemGeneral)
+ [VFS: Unable to mount root fs on unknown-block (Root filesystem mismatch)](#FilesystemKernel)
+ [Error: Unable to determine major/minor number of root device... (Root file system/device mismatch)](#FilesystemError)
+ [XENBUS: Device with no driver...](#FilesystemXenbus)
+ [... days without being checked, check forced (File system check required)](#FilesystemCheck)
+ [fsck died with exit status... (Missing device)](#FilesystemFschkDied)

**Operating System Errors**
+ [GRUB prompt (grubdom>)](#OpSystemGrub)
+ [Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring. (Hard-coded MAC address)](#OpSystemBringing)
+ [Unable to load SELinux Policy. Machine is in enforcing mode. Halting now. (SELinux misconfiguration)](#OpSystemUnable)
+ [XENBUS: Timeout connecting to devices (Xenbus timeout)](#OpSystemXenbus)

## Out of memory: kill process
<a name="MemoryOOM"></a>

An out-of-memory error is indicated by a system log entry similar to the one shown below.

```
[115879.769795] Out of memory: kill process 20273 (httpd) score 1285879
or a child 
[115879.769795] Killed process 1917 (php-cgi) vsz:467184kB, anon-
rss:101196kB, file-rss:204kB
```

### Potential cause
<a name="MemoryOOM-potential-cause"></a>

Exhausted memory

### Suggested actions
<a name="MemoryOOM-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## ERROR: mmu\$1update failed (Memory management update failed)
<a name="MemoryMMU"></a>

Memory management update failures are indicated by a system log entry similar to the following:

```
...
Press `ESC' to enter the menu... 0   [H[J  Booting 'Amazon Linux 2011.09 (2.6.35.14-95.38.amzn1.i686)'


root (hd0)

 Filesystem type is ext2fs, using whole disk

kernel /boot/vmlinuz-2.6.35.14-95.38.amzn1.i686 root=LABEL=/ console=hvc0 LANG=

en_US.UTF-8 KEYTABLE=us

initrd /boot/initramfs-2.6.35.14-95.38.amzn1.i686.img

ERROR: mmu_update failed with rc=-22
```

### Potential cause
<a name="MemoryMMU-potential-cause"></a>

Issue with Amazon Linux

### Suggested action
<a name="MemoryMMU-suggested-actions"></a>

Post your issue to [AWS re:Post](https://repost.aws/) or contact [Support](https://aws.amazon.com/premiumsupport/).

## I/O error (block device failure)
<a name="DeviceBlock"></a>

An input/output error is indicated by a system log entry similar to the following example:

```
[9943662.053217] end_request: I/O error, dev sde, sector 52428288
[9943664.191262] end_request: I/O error, dev sde, sector 52428168
[9943664.191285] Buffer I/O error on device md0, logical block 209713024
[9943664.191297] Buffer I/O error on device md0, logical block 209713025
[9943664.191304] Buffer I/O error on device md0, logical block 209713026
[9943664.191310] Buffer I/O error on device md0, logical block 209713027
[9943664.191317] Buffer I/O error on device md0, logical block 209713028
[9943664.191324] Buffer I/O error on device md0, logical block 209713029
[9943664.191332] Buffer I/O error on device md0, logical block 209713030
[9943664.191339] Buffer I/O error on device md0, logical block 209713031
[9943664.191581] end_request: I/O error, dev sde, sector 52428280
[9943664.191590] Buffer I/O error on device md0, logical block 209713136
[9943664.191597] Buffer I/O error on device md0, logical block 209713137
[9943664.191767] end_request: I/O error, dev sde, sector 52428288
[9943664.191970] end_request: I/O error, dev sde, sector 52428288
[9943664.192143] end_request: I/O error, dev sde, sector 52428288
[9943664.192949] end_request: I/O error, dev sde, sector 52428288
[9943664.193112] end_request: I/O error, dev sde, sector 52428288
[9943664.193266] end_request: I/O error, dev sde, sector 52428288
...
```

### Potential causes
<a name="DeviceBlock-potential-cause"></a>


| Instance type  | Potential cause | 
| --- | --- | 
|  Amazon EBS-backed  |  A failed Amazon EBS volume   | 
|  Instance store-backed  |  A failed physical drive   | 

### Suggested actions
<a name="DeviceBlock-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |   Terminate the instance and launch a new instance.  Data cannot be recovered. Recover from backups.   It's a good practice to use either Amazon S3 or Amazon EBS for backups. Instance store volumes are directly tied to single host and single disk failures.   | 

## I/O ERROR: neither local nor remote disk (Broken distributed block device)
<a name="DeviceDistributed"></a>

An input/output error on the device is indicated by a system log entry similar to the following example:

```
...
block drbd1: Local IO failed in request_timer_fn. Detaching...

Aborting journal on device drbd1-8.

block drbd1: IO ERROR: neither local nor remote disk

Buffer I/O error on device drbd1, logical block 557056

lost page write due to I/O error on drbd1

JBD2: I/O error detected when updating journal superblock for drbd1-8.
```

### Potential causes
<a name="DeviceDistributed-potential-cause"></a>


| Instance type  | Potential cause | 
| --- | --- | 
|  Amazon EBS-backed  |  A failed Amazon EBS volume   | 
|  Instance store-backed  |  A failed physical drive   | 

### Suggested action
<a name="DeviceDistributed-suggested-actions"></a>

Terminate the instance and launch a new instance. 

For an Amazon EBS-backed instance you can recover data from a recent snapshot by creating an image from it. Any data added after the snapshot cannot be recovered.

## request\$1module: runaway loop modprobe (Looping legacy kernel modprobe on older Linux versions)
<a name="KernelLoop"></a>

This condition is indicated by a system log similar to the one shown below. Using an unstable or old Linux kernel (for example, 2.6.16-xenU) can cause an interminable loop condition at startup.

```
Linux version 2.6.16-xenU (builder@xenbat.amazonsa) (gcc version 4.0.1 
20050727 (Red Hat 4.0.1-5)) #1 SMP Mon May 28 03:41:49 SAST 2007

BIOS-provided physical RAM map:

 Xen: 0000000000000000 - 0000000026700000 (usable)

0MB HIGHMEM available.
...

request_module: runaway loop modprobe binfmt-464c

request_module: runaway loop modprobe binfmt-464c

request_module: runaway loop modprobe binfmt-464c

request_module: runaway loop modprobe binfmt-464c

request_module: runaway loop modprobe binfmt-464c
```

### Suggested actions
<a name="KernelLoop-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use a newer kernel, either GRUB-based or static, using one of the following options: Option 1: Terminate the instance and launch a new instance, specifying the `-kernel` and `-ramdisk` parameters. Option 2: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Terminate the instance and launch a new instance, specifying the `-kernel` and `-ramdisk` parameters.   | 

## "FATAL: kernel too old" and "fsck: No such file or directory while trying to open /dev" (Kernel and AMI mismatch)
<a name="KernelOld"></a>

This condition is indicated by a system log similar to the one shown below.

```
Linux version 2.6.16.33-xenU (root@dom0-0-50-45-1-a4-ee.z-2.aes0.internal) 
(gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #2 SMP Wed Aug 15 17:27:36 SAST 2007
...
FATAL: kernel too old
Kernel panic - not syncing: Attempted to kill init!
```

### Potential causes
<a name="KernelOld-potential-cause"></a>

Incompatible kernel and userland

### Suggested actions
<a name="KernelOld-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## "FATAL: Could not load /lib/modules" or "BusyBox" (Missing kernel modules)
<a name="KernelMissing"></a>

This condition is indicated by a system log similar to the one shown below.

```
[    0.370415] Freeing unused kernel memory: 1716k freed 
Loading, please wait...
WARNING: Couldn't open directory /lib/modules/2.6.34-4-virtual: No such file or directory
FATAL: Could not open /lib/modules/2.6.34-4-virtual/modules.dep.temp for writing: No such file or directory
FATAL: Could not load /lib/modules/2.6.34-4-virtual/modules.dep: No such file or directory
Couldn't get a file descriptor referring to the console
Begin: Loading essential drivers... ...
FATAL: Could not load /lib/modules/2.6.34-4-virtual/modules.dep: No such file or directory
FATAL: Could not load /lib/modules/2.6.34-4-virtual/modules.dep: No such file or directory
Done.
Begin: Running /scripts/init-premount ...
Done.
Begin: Mounting root file system... ...
Begin: Running /scripts/local-top ...
Done.
Begin: Waiting for root file system... ...
Done.
Gave up waiting for root device.  Common problems:
 - Boot args (cat /proc/cmdline)
   - Check rootdelay= (did the system wait long enough?)
   - Check root= (did the system wait for the right device?)
 - Missing modules (cat /proc/modules; ls /dev)
FATAL: Could not load /lib/modules/2.6.34-4-virtual/modules.dep: No such file or directory
FATAL: Could not load /lib/modules/2.6.34-4-virtual/modules.dep: No such file or directory
ALERT! /dev/sda1 does not exist. Dropping to a shell!


BusyBox v1.13.3 (Ubuntu 1:1.13.3-1ubuntu5) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)
```

### Potential causes
<a name="KernelMissing-potential-cause"></a>

One or more of the following conditions can cause this problem:
+ Missing ramdisk 
+ Missing correct modules from ramdisk
+ Amazon EBS root volume not correctly attached as `/dev/sda1`

### Suggested actions
<a name="KernelMissing-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## ERROR Invalid kernel (EC2 incompatible kernel)
<a name="KernelInvalid"></a>

This condition is indicated by a system log similar to the one shown below.

```
...
root (hd0)

 Filesystem type is ext2fs, using whole disk

kernel /vmlinuz root=/dev/sda1 ro

initrd /initrd.img

ERROR Invalid kernel: elf_xen_note_check: ERROR: Will only load images 
built for the generic loader or Linux images
xc_dom_parse_image returned -1

Error 9: Unknown boot failure

  Booting 'Fallback'
  
root (hd0)

 Filesystem type is ext2fs, using whole disk

kernel /vmlinuz.old root=/dev/sda1 ro

Error 15: File not found
```

### Potential causes
<a name="KernelInvalid-potential-cause"></a>

One or both of the following conditions can cause this problem:
+ Supplied kernel is not supported by GRUB 
+ Fallback kernel does not exist 

### Suggested actions
<a name="KernelInvalid-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## fsck: No such file or directory while trying to open... (File system not found)
<a name="FilesystemFschk"></a>

This condition is indicated by a system log similar to the one shown below.

```
		Welcome to Fedora 
		Press 'I' to enter interactive startup.
Setting clock : Wed Oct 26 05:52:05 EDT 2011 [  OK  ]

Starting udev: [  OK  ]

Setting hostname localhost:  [  OK  ]

No devices found
Setting up Logical Volume Management: File descriptor 7 left open
  No volume groups found
[  OK  ]

Checking filesystems
Checking all file systems.
[/sbin/fsck.ext3 (1) -- /] fsck.ext3 -a /dev/sda1 
/dev/sda1: clean, 82081/1310720 files, 2141116/2621440 blocks
[/sbin/fsck.ext3 (1) -- /mnt/dbbackups] fsck.ext3 -a /dev/sdh 
fsck.ext3: No such file or directory while trying to open /dev/sdh

/dev/sdh: 
The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

[FAILED]


*** An error occurred during the file system check.
*** Dropping you to a shell; the system will reboot
*** when you leave the shell.
Give root password for maintenance
(or type Control-D to continue):
```

### Potential causes
<a name="FilesystemFschk-potential-cause"></a>
+ A bug exists in ramdisk filesystem definitions /etc/fstab
+ Misconfigured filesystem definitions in /etc/fstab
+ Missing/failed drive

### Suggested actions
<a name="FilesystemFschk-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html) The sixth field in the fstab defines availability requirements of the mount – a nonzero value implies that an fsck will be done on that volume and *must* succeed. Using this field can be problematic in Amazon EC2 because a failure typically results in an interactive console prompt that is not currently available in Amazon EC2. Use care with this feature and read the Linux man page for fstab.  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## General error mounting filesystems (failed mount)
<a name="FilesystemGeneral"></a>

This condition is indicated by a system log similar to the one shown below.

```
Loading xenblk.ko module 
xen-vbd: registered block device major 8

Loading ehci-hcd.ko module
Loading ohci-hcd.ko module
Loading uhci-hcd.ko module
USB Universal Host Controller Interface driver v3.0

Loading mbcache.ko module
Loading jbd.ko module
Loading ext3.ko module
Creating root device.
Mounting root filesystem.
kjournald starting.  Commit interval 5 seconds

EXT3-fs: mounted filesystem with ordered data mode.

Setting up other filesystems.
Setting up new root fs
no fstab.sys, mounting internal defaults
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
mountall:/proc: unable to mount: Device or resource busy
mountall:/proc/self/mountinfo: No such file or directory
mountall: root filesystem isn't mounted
init: mountall main process (221) terminated with status 1

General error mounting filesystems.
A maintenance shell will now be started.
CONTROL-D will terminate this shell and re-try.
Press enter for maintenance
(or type Control-D to continue):
```

### Potential causes
<a name="FilesystemGeneral-potential-cause"></a>


| Instance type  | Potential cause | 
| --- | --- | 
|  Amazon EBS-backed  |   [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |   [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

### Suggested actions
<a name="FilesystemGeneral-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Try one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## VFS: Unable to mount root fs on unknown-block (Root filesystem mismatch)
<a name="FilesystemKernel"></a>

This condition is indicated by a system log similar to the one shown below.

```
Linux version 2.6.16-xenU (builder@xenbat.amazonsa) (gcc version 4.0.1 
 20050727 (Red Hat 4.0.1-5)) #1 SMP Mon May 28 03:41:49 SAST 2007
...
Kernel command line:  root=/dev/sda1 ro 4
...
Registering block device major 8
...
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(8,1)
```

### Potential causes
<a name="FilesystemKernel-potential-cause"></a>


| Instance type  | Potential cause | 
| --- | --- | 
|  Amazon EBS-backed  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Hardware device failure.  | 

### Suggested actions
<a name="FilesystemKernel-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Terminate the instance and launch a new instance using a modern kernel.   | 

## Error: Unable to determine major/minor number of root device... (Root file system/device mismatch)
<a name="FilesystemError"></a>

This condition is indicated by a system log similar to the one shown below.

```
...
XENBUS: Device with no driver: device/vif/0
XENBUS: Device with no driver: device/vbd/2048
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
Initializing network drop monitor service
Freeing unused kernel memory: 508k freed
:: Starting udevd...
done.
:: Running Hook [udev]
:: Triggering uevents...<30>udevd[65]: starting version 173
done.
Waiting 10 seconds for device /dev/xvda1 ...
Root device '/dev/xvda1' doesn't exist. Attempting to create it.
ERROR: Unable to determine major/minor number of root device '/dev/xvda1'.
You are being dropped to a recovery shell
    Type 'exit' to try and continue booting
sh: can't access tty; job control turned off
[ramfs /]#
```

### Potential causes
<a name="FilesystemError-potential-cause"></a>
+ Missing or incorrectly configured virtual block device driver
+ Device enumeration clash (sda versus xvda or sda instead of sda1)
+ Incorrect choice of instance kernel

### Suggested actions
<a name="FilesystemError-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## XENBUS: Device with no driver...
<a name="FilesystemXenbus"></a>

This condition is indicated by a system log similar to the one shown below.

```
XENBUS: Device with no driver: device/vbd/2048
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
Initializing network drop monitor service
Freeing unused kernel memory: 508k freed
:: Starting udevd...
done.
:: Running Hook [udev]
:: Triggering uevents...<30>udevd[65]: starting version 173
done.
Waiting 10 seconds for device /dev/xvda1 ...
Root device '/dev/xvda1' doesn't exist. Attempting to create it.
ERROR: Unable to determine major/minor number of root device '/dev/xvda1'.
You are being dropped to a recovery shell
    Type 'exit' to try and continue booting
sh: can't access tty; job control turned off
[ramfs /]#
```

### Potential causes
<a name="FilesystemXenbus-potential-cause"></a>
+ Missing or incorrectly configured virtual block device driver
+ Device enumeration clash (sda versus xvda)
+ Incorrect choice of instance kernel

### Suggested actions
<a name="FilesystemXenbus-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## ... days without being checked, check forced (File system check required)
<a name="FilesystemCheck"></a>

This condition is indicated by a system log similar to the one shown below.

```
...
Checking filesystems
Checking all file systems.
[/sbin/fsck.ext3 (1) -- /] fsck.ext3 -a /dev/sda1 
/dev/sda1 has gone 361 days without being checked, check forced
```

### Potential causes
<a name="FilesystemCheck-potential-cause"></a>

Filesystem check time passed; a filesystem check is being forced.

### Suggested actions
<a name="FilesystemCheck-suggested-actions"></a>
+ Wait until the filesystem check completes. A filesystem check can take a long time depending on the size of the root filesystem. 
+  Modify your filesystems to remove the filesystem check (fsck) enforcement using tune2fs or tools appropriate for your filesystem. 

## fsck died with exit status... (Missing device)
<a name="FilesystemFschkDied"></a>

This condition is indicated by a system log similar to the one shown below.

```
Cleaning up ifupdown....
Loading kernel modules...done.
...
Activating lvm and md swap...done.
Checking file systems...fsck from util-linux-ng 2.16.2
/sbin/fsck.xfs: /dev/sdh does not exist
fsck died with exit status 8
[31mfailed (code 8).[39;49m
```

### Potential causes
<a name="FilesystemFschkDied-potential-cause"></a>
+ Ramdisk looking for missing drive
+ Filesystem consistency check forced
+ Drive failed or detached

### Suggested actions
<a name="FilesystemFschkDied-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Try one or more of the following to resolve the issue: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Try one or more of the following to resolve the issue: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## GRUB prompt (grubdom>)
<a name="OpSystemGrub"></a>

This condition is indicated by a system log similar to the one shown below. 

```
    GNU GRUB  version 0.97  (629760K lower / 0K upper memory)

       [ Minimal BASH-like line editing is supported.   For

         the   first   word,  TAB  lists  possible  command

         completions.  Anywhere else TAB lists the possible

         completions of a device/filename. ]

grubdom>
```

### Potential causes
<a name="OpSystem-potential-cause"></a>


| Instance type  | Potential causes | 
| --- | --- | 
|  Amazon EBS-backed  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

### Suggested actions
<a name="OpSystem-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Option 1: Modify the AMI and relaunch the instance: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html) Option 2: Fix the existing instance: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Option 1: Modify the AMI and relaunch the instance: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html) Option 2: Terminate the instance and launch a new instance, specifying the correct kernel.  To recover data from the existing instance, contact [Support](https://aws.amazon.com/premiumsupport/).   | 

## Bringing up interface eth0: Device eth0 has different MAC address than expected, ignoring. (Hard-coded MAC address)
<a name="OpSystemBringing"></a>

This condition is indicated by a system log similar to the one shown below.

```
... 
Bringing up loopback interface:  [  OK  ]

Bringing up interface eth0:  Device eth0 has different MAC address than expected, ignoring.
[FAILED]

Starting auditd: [  OK  ]
```

### Potential causes
<a name="OpSystemBringing-potential-cause"></a>

There is a hardcoded interface MAC in the AMI configuration

### Suggested actions
<a name="OpSystemBringing-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html) OR Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## Unable to load SELinux Policy. Machine is in enforcing mode. Halting now. (SELinux misconfiguration)
<a name="OpSystemUnable"></a>

This condition is indicated by a system log similar to the one shown below.

```
audit(1313445102.626:2): enforcing=1 old_enforcing=0 auid=4294967295
Unable to load SELinux Policy. Machine is in enforcing mode. Halting now.
Kernel panic - not syncing: Attempted to kill init!
```

### Potential causes
<a name="OpSystemUnable-potential-cause"></a>

SELinux has been enabled in error:
+ Supplied kernel is not supported by GRUB
+ Fallback kernel does not exist

### Suggested actions
<a name="OpSystemUnable-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Use the following procedure: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

## XENBUS: Timeout connecting to devices (Xenbus timeout)
<a name="OpSystemXenbus"></a>

This condition is indicated by a system log similar to the one shown below.

```
Linux version 2.6.16-xenU (builder@xenbat.amazonsa) (gcc version 4.0.1 
20050727 (Red Hat 4.0.1-5)) #1 SMP Mon May 28 03:41:49 SAST 2007
...
XENBUS: Timeout connecting to devices!
...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.
```

### Potential causes
<a name="OpSystemXenbus-potential-cause"></a>
+ The block device is not connected to the instance
+ This instance is using an old instance kernel

### Suggested actions
<a name="OpSystemXenbus-suggested-actions"></a>


| For this instance type  | Do this | 
| --- | --- | 
|  Amazon EBS-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 
|  Instance store-backed  |  Do one of the following: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html)  | 

# Troubleshoot an Amazon EC2 Linux instance booting from wrong volume
<a name="instance-booting-from-wrong-volume"></a>

In some situations, a volume other than the volume attached to `/dev/xvda` or `/dev/sda` becomes the root volume of a Linux instance. This can happen when you have attached the root volume of another instance, or a volume created from the snapshot of a root volume, to an instance with an existing root volume.

This is due to how the initial ramdisk in Linux works. It chooses the volume defined as `/` in the `/etc/fstab`, and in some distributions, this is determined by the label attached to the volume partition. Specifically, you find that your `/etc/fstab` looks something like the following: 

```
LABEL=/ / ext4 defaults,noatime 1 1 
tmpfs /dev/shm tmpfs defaults 0 0 
devpts /dev/pts devpts gid=5,mode=620 0 0 
sysfs /sys sysfs defaults 0 0 
proc /proc proc defaults 0 0
```

If you check the label of both volumes, you see that they both contain the `/` label: 

```
[ec2-user ~]$ sudo e2label /dev/xvda1 
/ 
[ec2-user ~]$ sudo e2label /dev/xvdf1 
/
```

In this example, you could end up having `/dev/xvdf1` become the root volume that your instance boots to after the initial ramdisk runs, instead of the `/dev/xvda1` volume from which you had intended to boot. To solve this, use the same **e2label** command to change the label of the attached volume that you do not want to boot from.

In some cases, specifying a UUID in `/etc/fstab` can resolve this. However, if both volumes come from the same snapshot, or the secondary is created from a snapshot of the primary volume, they share a UUID.

```
[ec2-user ~]$ sudo blkid 
/dev/xvda1: LABEL="/" UUID=73947a77-ddbe-4dc7-bd8f-3fe0bc840778 TYPE="ext4" PARTLABEL="Linux" PARTUUID=d55925ee-72c8-41e7-b514-7084e28f7334 
/dev/xvdf1: LABEL="old/" UUID=73947a77-ddbe-4dc7-bd8f-3fe0bc840778 TYPE="ext4" PARTLABEL="Linux" PARTUUID=d55925ee-72c8-41e7-b514-7084e28f7334
```

**To change the label of an attached ext4 volume**

1. Use the **e2label** command to change the label of the volume to something other than `/`.

   ```
   [ec2-user ~]$ sudo e2label /dev/xvdf1 old/ 
   ```

1. Verify that the volume has the new label.

   ```
   [ec2-user ~]$ sudo e2label /dev/xvdf1 
   old/
   ```

**To change the label of an attached xfs volume**
+ Use the **xfs\$1admin** command to change the label of the volume to something other than `/`.

  ```
  [ec2-user ~]$ sudo xfs_admin -L old/ /dev/xvdf1
  writing all SBs
  new label = "old/"
  ```

After changing the volume label as shown, you should be able to reboot the instance and have the proper volume selected by the initial ramdisk when the instance boots.

**Important**  
If you intend to detach the volume with the new label and return it to another instance to use as the root volume, you must perform the above procedure again and change the volume label back to its original value. Otherwise, the other instance does not boot because the ramdisk is unable to find the volume with the label `/`.

# Troubleshoot issues connecting to your Amazon EC2 Windows instance
<a name="troubleshoot-connect-windows-instance"></a>

The following information and common errors can help you troubleshoot issues when connecting to your Windows instance.

**Topics**
+ [Remote Desktop can't connect to the remote computer](#rdp-issues)
+ [Error using the macOS RDP client](#troubleshoot-instance-connect-mac-rdp)
+ [RDP displays a black screen instead of the desktop](#rdp-black-screen)
+ [Unable to remotely log on to an instance with a user that is not an administrator](#remote-failure)
+ [Troubleshooting Remote Desktop issues using AWS Systems Manager](#Troubleshooting-Remote-Desktop-Connection-issues-using-AWS-Systems-Manager)
+ [Enable Remote Desktop on an EC2 instance with remote registry](#troubleshooting-windows-rdp-remote-registry)
+ [I've lost my private key. How can I connect to my Windows instance?](#replacing-lost-key-pair-windows)

## Remote Desktop can't connect to the remote computer
<a name="rdp-issues"></a>

Try the following to resolve issues related to connecting to your instance:
+ Verify that you're using the correct public DNS hostname. (In the Amazon EC2 console, select the instance and check **Public DNS (IPv4)** in the details pane.) If your instance is in a VPC and you do not see a public DNS name, you must enable DNS hostnames. For more information, see [DNS attributes for your VPC](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html) in the *Amazon VPC User Guide*.
+ Verify that your instance has a public IPv4 address. If not, you can associate an Elastic IP address with your instance. For more information, see [Elastic IP addresses](elastic-ip-addresses-eip.md). 
+ To connect to your instance using an IPv6 address, check that your local computer has an IPv6 address and is configured to use IPv6. For more information, see [Configure IPv6 on your instances](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-migrate-ipv6.html#vpc-migrate-ipv6-dhcpv6) in the *Amazon VPC User Guide*.
+ Verify that your security group has a rule that allows RDP access on port 3389.
+ If you copied the password but get the error `Your credentials did not work`, try typing them manually when prompted. It's possible that you missed a character or got an extra white space character when you copied the password.
+ Verify that the instance has passed status checks. For more information, see [Status checks for Amazon EC2 instances](monitoring-system-instance-status-check.md) and [Troubleshoot Amazon EC2 Linux instances with failed status checks](TroubleshootingInstances.md).
+ Verify that the route table for the subnet has a route that sends all traffic destined outside the VPC to the internet gateway for the VPC. For more information, see [Creating a custom route table](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html#Add_IGW_Routing) (Internet Gateways) in the *Amazon VPC User Guide*.
+ Verify that Windows Firewall, or other firewall software, is not blocking RDP traffic to the instance. We recommend that you disable Windows Firewall and control access to your instance using security group rules. Try one of the following options:
  + Use [AWSSupport-TroubleshootRDP](#AWSSupport-TroubleshootRDP) to [disable the Windows Firewall profiles using SSM Agent](#disable-firewall). This option requires that the instance is configured for AWS Systems Manager.
  + Use [AWSSupport-ExecuteEC2Rescue](#AWSSupport-ExecuteEC2Rescue).
  + Stop the instance, detach the root volume, and attach the volume to a temporary instance as a data volume. Connect to the temporary instance and bring the volume online. Load the registry hive from the data volume. Under `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicyStandardProfile`, set `EnableFirewall` to 0. Unload the registry hive and then bring the volume offline. Detach the volume from the temporary instance and attach it to the original instance as the root volume. Start the original instance.
+  Verify that Network Level Authentication is disabled on instances that are not part of an Active Directory domain (use [AWSSupport-TroubleshootRDP](#AWSSupport-TroubleshootRDP) to [disable NLA](#disable-nla)). 
+ Verify that the Remote Desktop Service (TermService) Startup Type is Automatic and the service is started (use [AWSSupport-TroubleshootRDP](#AWSSupport-TroubleshootRDP) to [enable and start the RDP service](#rdp-auto)). 
+ Verify that you are connecting to the correct Remote Desktop Protocol port, which by default is 3389 (use [AWSSupport-TroubleshootRDP](#AWSSupport-TroubleshootRDP) to [read the current RDP port](#check-rdp) and [change it back to 3389](#restore-3389)).
+  Verify that Remote Desktop connections are allowed on your instance (use [AWSSupport-TroubleshootRDP](#AWSSupport-TroubleshootRDP) to [enable Remote Desktop connections](#allow-rdp)).
+ Verify that the password has not expired. If the password has expired, you can reset it. For more information, see [Reset the Windows administrator password for an Amazon EC2 Windows instance](ResettingAdminPassword.md).
+ If you attempt to connect using a user that you created on the instance and receive the error `The user cannot connect to the server due to insufficient access privileges`, verify that you granted the user the right to log on locally. For more information, see [Grant a Member the Right to Logon Locally](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-r2-and-2008/ee957044(v%3dws.10)).
+ If you attempt more than the maximum allowed concurrent RDP sessions, your session is terminated with the message `Your Remote Desktop Services session has ended. Another user connected to the remote computer, so your connection was lost.` By default, you are allowed two concurrent RDP sessions to your instance.

## Error using the macOS RDP client
<a name="troubleshoot-instance-connect-mac-rdp"></a>

If you are connecting to a Windows Server instance using the Remote Desktop Connection client from the Microsoft website, you may get the following error:

```
Remote Desktop Connection cannot verify the identity of the computer that you want to connect to.
```

Download the Microsoft Remote Desktop app from the Mac App Store and use the app to connect to your instance.

## RDP displays a black screen instead of the desktop
<a name="rdp-black-screen"></a>

Try the following to resolve this issue:
+ Check the console output for additional information. To get the console output for your instance using the Amazon EC2 console, select the instance, and then choose **Actions**, **Monitor and troubleshoot**, **Get system log**.
+ Verify that you are running the latest version of your RDP client.
+ Try the default settings for the RDP client.
+ If you are using Remote Desktop Connection, try starting it with the `/admin` option as follows.

  ```
  mstsc /v:instance /admin
  ```
+ If the server is running a full-screen application, it might have stopped responding. Use Ctrl\$1Shift\$1Esc to start Windows Task Manager, and then close the application.
+ If the server is over-utilized, it might have stopped responding. To monitor the instance using the Amazon EC2 console, select the instance and then select the **Monitoring** tab. If you need to change the instance type to a larger size, see [Amazon EC2 instance type changes](ec2-instance-resize.md).

## Unable to remotely log on to an instance with a user that is not an administrator
<a name="remote-failure"></a>

If you are not able to remotely log on to a Windows instance with a user that is not an administrator account, ensure that you have granted the user the right to log on locally. See [Grant a user or group the right to log on locally to the domain controllers in the domain](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee957044(v=ws.10)#grant-a-user-or-group-the-right-to-log-on-locally-to-the-domain-controllers-in-the-domain). 

## Troubleshooting Remote Desktop issues using AWS Systems Manager
<a name="Troubleshooting-Remote-Desktop-Connection-issues-using-AWS-Systems-Manager"></a>

You can use AWS Systems Manager to troubleshoot issues connecting to your Windows instance using RDP.

### AWSSupport-TroubleshootRDP
<a name="AWSSupport-TroubleshootRDP"></a>

The AWSSupport-TroubleshootRDP automation document allows the user to check or modify common settings on the target instance that can impact Remote Desktop Protocol (RDP) connections, such as the **RDP Port**, **Network Layer Authentication (NLA)**, and **Windows Firewall** profiles. By default, the document reads and outputs the values of these settings.

The AWSSupport-TroubleshootRDP automation document can be used with EC2 instances, on-premises instances, and virtual machines (VMs) that are enabled for use with AWS Systems Manager (managed instances). In addition, it can also be used with EC2 instances for Windows Server that are *not* enabled for use with Systems Manager. For information about enabling instances for use with AWS Systems Manager, see [Managed nodes](https://docs.aws.amazon.com/systems-manager/latest/userguide/fleet-manager-managed-nodes.html) in the*AWS Systems Manager User Guide*.

**To troubleshoot using the AWSSupport-TroubleshootRDP document**

1. Log in to the [Systems Manager Console](https://console.aws.amazon.com/systems-manager/).

1.  Verify that you are in the same Region as the impaired instance.

1. Choose **Documents** from the left navigation pane. 

1. On the **Owned by Amazon** tab, enter `AWSSupport-TroubleshootRDP` in the search field. When the `AWSSupport-TroubleshootRDP` document appears, select it.

1. Choose **Execute automation**.

1. For **Execution Mode**, choose **Simple execution**.

1. For **Input parameters**, **InstanceId**, enable **Show interactive instance picker**.

1. Choose your Amazon EC2 instance.

1. Review the [examples](#AWSSupport-TroubleshootRDP-Examples), then choose **Execute**.

1. To monitor the execution progress, for **Execution status**, wait for the status to change from **Pending** to **Success**. Expand **Outputs** to view the results. To view the output of individual steps, in **Executed Steps**, choose an item from **Step ID.**

#### AWSSupport-TroubleshootRDP examples
<a name="AWSSupport-TroubleshootRDP-Examples"></a>

The following examples show you how to accomplish common troubleshooting tasks using AWSSupport-TroubleshootRDP. You can use either the example AWS CLI [https://docs.aws.amazon.com/cli/latest/reference/ssm/start-automation-execution.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/start-automation-execution.html) command or the provided link to the AWS Management Console.

**Example: Check the current RDP status**  <a name="check-rdp"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region#documentVersion=$LATEST
```

**Example: Disable the Windows Firewall**  <a name="disable-firewall"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom, Firewall=Disable" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region_code#documentVersion=$LATEST&Firewall=Disable
```

**Example: Disable Network Level Authentication**  <a name="disable-nla"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom, NLASettingAction=Disable" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region_code#documentVersion
```

**Example: Set RDP Service Startup Type to Automatic and start the RDP service**  <a name="rdp-auto"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom, RDPServiceStartupType=Auto, RDPServiceAction=Start" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region_code#documentVersion=$LATEST&RDPServiceStartupType=Auto&RDPServiceAction=Start
```

**Example: Restore the default RDP Port (3389)**  <a name="restore-3389"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom, RDPPortAction=Modify" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region_code#documentVersion=$LATEST&RDPPortAction=Modify
```

**Example: Allow remote connections**  <a name="allow-rdp"></a>
AWS CLI:  

```
aws ssm start-automation-execution --document-name "AWSSupport-TroubleshootRDP" --parameters "InstanceId=i-1234567890abcdef0, Action=Custom, RemoteConnections=Enable" --region region_code
```
AWS Systems Manager console:  

```
https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootRDP?region=region_code#documentVersion=$LATEST&RemoteConnections=Enable
```

### AWSSupport-ExecuteEC2Rescue
<a name="AWSSupport-ExecuteEC2Rescue"></a>

The AWSSupport-ExecuteEC2Rescue automation document uses EC2Rescue for Windows Server to automatically troubleshoot and restore EC2 instance connectivity and RDP issues. For more information, see [Run the EC2Rescue tool on unreachable instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2rescue.html).

The AWSSupport-ExecuteEC2Rescue automation document requires a stop and restart of the instance. Systems Manager Automation stops the instance and creates an Amazon Machine Image (AMI). Data stored in instance store volumes is lost. The public IP address changes if you are not using an Elastic IP address. For more information, see [Run the EC2Rescue tool on unreachable instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2rescue.html) in the *AWS Systems Manager User Guide*.

**To troubleshoot using the AWSSupport-ExecuteEC2Rescue document**

1. Open the [Systems Manager console](https://console.aws.amazon.com/systems-manager/).

1. Verify that you are in the same Region as the impaired Amazon EC2 instance.

1. In the navigation panel, choose **Documents**.

1. Search for and select the `AWSSupport-ExecuteEC2Rescue` document, and then choose **Execute automation**.

1. In **Execution Mode**, choose **Simple execution**.

1.  In the **Input parameters** section, for **UnreachableInstanceId**, enter the Amazon EC2 instance ID of the unreachable instance.

1.  (Optional) For **LogDestination**, enter the Amazon Simple Storage Service (Amazon S3) bucket name if you want to collect operating system logs for troubleshooting your Amazon EC2 instance. Logs are automatically uploaded to the specified bucket.

1. Choose **Execute**.

1.  To monitor the execution progress, in **Execution status**, wait for the status to change from **Pending** to **Success**. Expand **Outputs** to view the results. To view the output of individual steps, in **Executed Steps**, choose the **Step ID**.

## Enable Remote Desktop on an EC2 instance with remote registry
<a name="troubleshooting-windows-rdp-remote-registry"></a>

If your unreachable instance is not managed by AWS Systems Manager Session Manager, then you can use remote registry to enable Remote Desktop. 

1. From the EC2 console, stop the unreachable instance.

1. Detach the root volume of the unreachable instance and attach it to a reachable instance in the same Availability Zone as a storage volume. If you don't have a reachable instance in the same Availability Zone, launch one. Note the device name of the root volume on the unreachable instance.

1. On the reachable instance, open Disk Management. You can do so by running the following command in the Command Prompt window.

   ```
   diskmgmt.msc
   ```

1. Right click the newly attached volume that came from the unreachable instance, and then choose **Online**.

1. Open the Windows Registry Editor. You can do so by running the following command in the Command Prompt window.

   ```
   regedit
   ```

1. In Registry Editor, choose **HKEY\$1LOCAL\$1MACHINE**, then select **File**, **Load Hive**.

1. Select the drive of the attached volume, navigate to `\Windows\System32\config\`, select `SYSTEM`, and then choose **Open**.

1. For **Key Name**, enter a unique name for the hive and choose **OK**.

1. Back up the registry hive before making any changes to the registry. 

   1. In the Registry Editor console tree, select the hive that you loaded: **HKEY\$1LOCAL\$1MACHINE**\$1*your-key-name*.

   1. Choose **File**, **Export**.

   1. In the Export Registry File dialog box, choose the location to which you want to save the backup copy, and then type a name for the backup file in the **File name** field.

   1. Choose **Save**.

1. In Registry Editor, navigate to `HKEY_LOCAL_MACHINE\your key name\ControlSet001\Control\Terminal Server`, and then, in the details pane, double-click **fDenyTSConnections**.

1. In the **Edit DWORD** value box, enter `0` in the **Value data** field. 

1. Choose **OK**.
**Note**  
If the value in the **Value data** field is `1`, then the instance will deny remote desktop connections. A value of `0` allows remote desktop connections.

1. In Registry Editor, choose **HKEY\$1LOCAL\$1MACHINE**\$1*your-key-name*, then select **File**, **Unload Hive**.

1. Close Registry Editor and Disk Management.

1. From the EC2 console, detach the volume from the reachable instance and then reattach it to the unreachable instance. When attaching the volume to the unreachable instance, enter the device name that you saved earlier in the **device** field.

1. Restart the unreachable instance. 

## I've lost my private key. How can I connect to my Windows instance?
<a name="replacing-lost-key-pair-windows"></a>

When you connect to a newly-launched Windows instance, you decrypt the password for the Administrator account using the private key for the key pair that you specified when you launched the instance.

If you lose the Administrator password and you no longer have the private key, you must reset the password or create a new instance. For more information, see [Reset the Windows administrator password for an Amazon EC2 Windows instance](ResettingAdminPassword.md). For steps to reset the password using an Systems Manager document, see [Reset passwords and SSH keys on EC2 instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html) in the *AWS Systems Manager User Guide*.

# Troubleshoot Amazon EC2 Windows instance start issues
<a name="common-messages"></a>

The following are troubleshooting tips to help you solve password and activation issues with Amazon EC2 Windows instances.

**Topics**
+ ["Password is not available"](#password-not-available)
+ ["Password not available yet"](#password-not-ready)
+ ["Cannot retrieve Windows password"](#cannot-retrieve-password)
+ ["Waiting for the metadata service"](#metadata-unavailable)
+ ["Unable to activate Windows"](#activate-windows)
+ ["Windows is not genuine (0x80070005)"](#windows-not-genuine)
+ ["No Terminal Server License Servers available to provide a license"](#no-license-servers)
+ ["Some settings are managed by your organization"](#some-settings-managed-by-org)

## "Password is not available"
<a name="password-not-available"></a>

To connect to a Windows instance using Remote Desktop, you must specify an account and password. The accounts and passwords provided are based on the AMI that you used to launch the instance. You can either retrieve the auto-generated password for the Administrator account, or use the account and password that were in use in the original instance from which the AMI was created.

You can generate a password for the Administrator account for instances launched using a custom Windows AMI. To generate the password, you will need to configure some settings in the operating system before the AMI is created. For more information, see [Create an Amazon EBS-backed AMI](creating-an-ami-ebs.md).

If your Windows instance isn't configured to generate a random password, you'll receive the following message when you retrieve the auto-generated password using the console:

```
Password is not available.
The instance was launched from a custom AMI, or the default password has changed. A
password cannot be retrieved for this instance. If you have forgotten your password, you can
reset it using the Amazon EC2 configuration service. For more information, see Passwords for a
Windows Server instance.
```

Check the console output for the instance to see whether the AMI that you used to launch it was created with password generation disabled. If password generation is disabled, the console output contains the following:

```
Ec2SetPassword: Disabled
```

If password generation is disabled and you don't remember the password for the original instance, you can reset the password for this instance. For more information, see [Reset the Windows administrator password for an Amazon EC2 Windows instance](ResettingAdminPassword.md).

## "Password not available yet"
<a name="password-not-ready"></a>

To connect to a Windows instance using Remote Desktop, you must specify an account and password. The accounts and passwords provided are based on the AMI that you used to launch the instance. You can either retrieve the auto-generated password for the Administrator account, or use the account and password that were in use in the original instance from which the AMI was created.

Your password should be available within a few minutes. If the password isn't available, you'll receive the following message when you retrieve the auto-generated password using the console:

```
Password not available yet.
Please wait at least 4 minutes after launching an instance before trying to retrieve the 
auto-generated password.
```

If it's been longer than four minutes and you still can't get the password, it's possible that the launch agent for your instance is not configured to generate a password. Verify by checking whether the console output is empty. For more information, see [Unable to get console output](win-ts-common-issues.md#no-console-output).

Also verify that the AWS Identity and Access Management (IAM) account being used to access the Management Portal has the `ec2:GetPasswordData` action allowed. For more information about IAM permissions, see [What is IAM?](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html).

## "Cannot retrieve Windows password"
<a name="cannot-retrieve-password"></a>

To retrieve the auto-generated password for the Administrator account, you must use the private key for the key pair that you specified when you launched the instance. If you didn't specify a key pair when you launched the instance, you'll receive the following message.

```
Cannot retrieve Windows password
```

You can terminate this instance and launch a new instance using the same AMI, making sure to specify a key pair.

## "Waiting for the metadata service"
<a name="metadata-unavailable"></a>

A Windows instance must obtain information from its instance metadata before it can activate itself. By default, the `WaitForMetaDataAvailable` setting ensures that the EC2Config service waits for the instance metadata to be accessible before continuing with the boot process. For more information, see [Use instance metadata to manage your EC2 instance](ec2-instance-metadata.md).

If the instance is failing the instance reachability test, try the following to resolve this issue.
+ Check the CIDR block for your VPC. A Windows instance cannot boot correctly if it's launched into a VPC that has an IP address range from `224.0.0.0` to `255.255.255.255` (Class D and Class E IP address ranges). These IP address ranges are reserved, and should not be assigned to host devices. We recommend that you create a VPC with a CIDR block from the private (non-publicly routable) IP address ranges as specified in [RFC 1918](http://www.faqs.org/rfcs/rfc1918.html).
+ It's possible that the system has been configured with a static IP address. Try [creating a network interface](create-network-interface.md) and [attaching it to the instance](network-interface-attachments.md#attach_eni).
+ 

**To enable DHCP on a Windows instance that you can't connect to**

  1. Stop the affected instance and detach its root volume.

  1. Launch a temporary instance in the same Availability Zone as the affected instance.
**Warning**  
If your temporary instance is based on the same AMI that the original instance is based on, you must complete additional steps or you won't be able to boot the original instance after you restore its root volume because of a disk signature collision. Alternatively, select a different AMI for the temporary instance. For example, if the original instance uses the AWS Windows AMI for Windows Server 2016, launch the temporary instance using the AWS Windows AMI for Windows Server 2019.

  1. Attach the root volume from the affected instance to this temporary instance. Connect to the temporary instance, open the **Disk Management** utility, and bring the drive online.

  1. From the temporary instance, open **Regedit** and select **HKEY\$1LOCAL\$1MACHINE**. From the **File** menu, choose **Load Hive**. Select the drive, open the file `Windows\System32\config\SYSTEM`, and specify a key name when prompted (you can use any name).

  1. Select the key that you just loaded and navigate to `ControlSet001\Services\Tcpip\Parameters\Interfaces`. Each network interface is listed by a GUID. Select the correct network interface. If DHCP is disabled and a static IP address assigned, `EnableDHCP` is set to 0. To enable DHCP, set `EnableDHCP` to 1, and delete the following keys if they exist: `NameServer`, `SubnetMask`, `IPAddress`, and `DefaultGateway`. Select the key again, and from the **File** menu, choose **Unload Hive**.
**Note**  
If you have multiple network interfaces, you'll need to identify the correct interface to enable DHCP. To identify the correct network interface, review the following key values `NameServer`, `SubnetMask`, `IPAddress`, and `DefaultGateway`. These values display the static configuration of the previous instance. 

  1. (Optional) If DHCP is already enabled, it's possible that you don't have a route to the metadata service. Updating EC2Config can resolve this issue.

     1. [Download](https://s3.amazonaws.com/ec2-downloads-windows/EC2Config/EC2Install.zip) and install the latest version of the EC2Config service. For more information about installing this service, see [Install the latest version of EC2Config](UsingConfig_Install.md).

     1. Extract the files from the `.zip` file to the `Temp` directory on the drive you attached.

     1. Open **Regedit** and select **HKEY\$1LOCAL\$1MACHINE**. From the **File** menu, choose **Load Hive**. Select the drive, open the file `Windows\System32\config\SOFTWARE`, and specify a key name when prompted (you can use any name).

     1. Select the key that you just loaded and navigate to `Microsoft\Windows\CurrentVersion`. Select the `RunOnce` key. (If this key doesn't exist, right-click `CurrentVersion`, point to **New**, select **Key**, and name the key `RunOnce`.) Right-click, point to **New**, and select **String Value**. Enter `Ec2Install` as the name and `C:\Temp\Ec2Install.exe -q` as the data.

     1. Select the key again, and from the **File** menu, choose **Unload Hive**.

  1. (Optional) If your temporary instance is based on the same AMI that the original instance is based on, you must complete the following steps or you won't be able to boot the original instance after you restore its root volume because of a disk signature collision.
**Warning**  
The following procedure describes how to edit the Windows Registry using Registry Editor. If you are not familiar with the Windows Registry or how to safely make changes using Registry Editor, see [Configure the Registry](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc725612(v=ws.11)).

     1. Open a command prompt, type **regedit.exe**, and press Enter.

     1. In the **Registry Editor**, choose **HKEY\$1LOCAL\$1MACHINE** from the context menu (right-click), and then choose **Find**.

     1. Type **Windows Boot Manager** and then choose **Find Next**.

     1. Choose the key named `11000001`. This key is a sibling of the key you found in the previous step.

     1. In the right pane, choose `Element` and then choose **Modify** from the context menu (right-click).

     1. Locate the four-byte disk signature at offset 0x38 in the data. Reverse the bytes to create the disk signature, and write it down. For example, the disk signature represented by the following data is `E9EB3AA5`:

        ```
        ...
        0030  00 00 00 00 01 00 00 00
        0038  A5 3A EB E9 00 00 00 00
        0040  00 00 00 00 00 00 00 00
        ...
        ```

     1. In a Command Prompt window, run the following command to start Microsoft DiskPart.

        ```
        diskpart
        ```

     1. Run the following DiskPart command to select the volume. (You can verify that the disk number is 1 using the **Disk Management** utility.)

        ```
        DISKPART> select disk 1
        
        Disk 1 is now the selected disk.
        ```

     1. Run the following DiskPart command to get the disk signature.

        ```
        DISKPART>  uniqueid disk
        
        Disk ID: 0C764FA8
        ```

     1. If the disk signature shown in the previous step doesn't match the disk signature from BCD that you wrote down earlier, use the following DiskPart command to change the disk signature so that it matches:

        ```
        DISKPART> uniqueid disk id=E9EB3AA5
        ```

  1. Using the **Disk Management** utility, bring the drive offline.
**Note**  
The drive is automatically offline if the temporary instance is running the same operating system as the affected instance, so you won't need to bring it offline manually.

  1. Detach the volume from the temporary instance. You can terminate the temporary instance if you have no further use for it.

  1. Restore the root volume of the affected instance by attaching the volume as `/dev/sda1`.

  1. Start the affected instance.

If you are connected to the instance, open an Internet browser from the instance and enter the following URL for the metadata server:

```
http://169.254.169.254/latest/meta-data/
```

If you can't contact the metadata server, try the following to resolve the issue:
+ [Download](https://s3.amazonaws.com/ec2-downloads-windows/EC2Config/EC2Install.zip) and install the latest version of the EC2Config service. For more information about installing this service, see [Install the latest version of EC2Config](UsingConfig_Install.md).
+ Check whether the Windows instance is running Red Hat PV drivers. If so, update to Citrix PV drivers. For more information, see [Upgrade PV drivers on EC2 Windows instances](Upgrading_PV_drivers.md).
+ Verify that the firewall, IPSec, and proxy settings do not block outgoing traffic to the metadata service (`169.254.169.254`) or the AWS KMS servers (the addresses are specified in `TargetKMSServer` elements in `C:\Program Files\Amazon\Ec2ConfigService\Settings\ActivationSettings.xml`).
+ Verify that you have a route to the metadata service (`169.254.169.254`) using the following command.

  ```
  route print
  ```
+ Check for network issues that might affect the Availability Zone for your instance. Go to [http://status.aws.amazon.com/](http://status.aws.amazon.com/).

## "Unable to activate Windows"
<a name="activate-windows"></a>

Windows instances use Windows AWS KMS activation. You can receive this message: `A problem occurred when Windows tried to activate. Error Code 0xC004F074`, if your instance can't reach the AWS KMS server. Windows must be activated every 180 days. EC2Config attempts to contact the AWS KMS server before the activation period expires to ensure that Windows remains activated.

If you encounter a Windows activation issue, use the following procedure to resolve the issue.

**For EC2Config (Windows Server 2012 R2 AMIs and earlier)**

1. [Download](https://s3.amazonaws.com/ec2-downloads-windows/EC2Config/EC2Install.zip) and install the latest version of the EC2Config service. For more information about installing this service, see [Install the latest version of EC2Config](UsingConfig_Install.md).

1. Log onto the instance and open the following file: `C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml`.

1. Locate the **Ec2WindowsActivate** plugin in the `config.xml` file. Change the state to **Enabled** and save your changes.

1. In the Windows Services snap-in, restart the EC2Config service or reboot the instance.

If this does not resolve the activation issue, follow these additional steps.

1. Set the AWS KMS target: **C:\$1> slmgr.vbs /skms 169.254.169.250:1688**

1. Activate Windows: **C:\$1> slmgr.vbs /ato**

**For EC2Launch (Windows Server 2016 AMIs and later)**

1. From a PowerShell prompt with administrative rights, import the EC2Launch module:

   ```
   PS C:\> Import-Module "C:\ProgramData\Amazon\EC2-Windows\Launch\Module\Ec2Launch.psd1"
   ```

1. Call the Add-Routes function to see the list of new routes:

   ```
   PS C:\> Add-Routes
   ```

1. Call the Set-ActivationSettings function:

   ```
   PS C:\> Set-Activationsettings
   ```

1. Then, run the following script to activate Windows:

   ```
   PS C:\> cscript "${env:SYSTEMROOT}\system32\slmgr.vbs" /ato
   ```

 For both EC2Config and EC2Launch, if you are still receiving an activation error, verify the following information.
+ Verify that you have routes to the AWS KMS servers. Open `C:\Program Files\Amazon\Ec2ConfigService\Settings\ActivationSettings.xml` and locate the `TargetKMSServer` elements. Run the following command and check whether the addresses for these AWS KMS servers are listed.

  ```
  route print
  ```
+ Verify that the AWS KMS client key is set. Run the following command and check the output.

  ```
  C:\Windows\System32\slmgr.vbs /dlv
  ```

  If the output contains Error: product key not found, the AWS KMS client key isn't set. If the AWS KMS client key isn't set, look up the client key as described in this Microsoft article: [AWS KMS client activation and product keys](https://learn.microsoft.com/en-us/windows-server/get-started/kms-client-activation-keys), and then run the following command to set the AWS KMS client key.

  ```
  C:\Windows\System32\slmgr.vbs /ipk client_key
  ```
+ Verify that the system has the correct time and time zone. If you are using a time zone other than UTC, add the following registry key and set it to `1` to ensure that the time is correct: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal`.
+ If Windows Firewall is enabled, temporarily disable it using the following command.

  ```
  netsh advfirewall set allprofiles state off
  ```

## "Windows is not genuine (0x80070005)"
<a name="windows-not-genuine"></a>

Windows instances use Windows AWS KMS activation. If an instance is unable to complete the activation process, it reports that the copy of Windows is not genuine.

Try the suggestions for ["Unable to activate Windows"](#activate-windows).

## "No Terminal Server License Servers available to provide a license"
<a name="no-license-servers"></a>

By default, Windows Server is licensed for two simultaneous users through Remote Desktop. If you need to provide more than two users with simultaneous access to your Windows instance through Remote Desktop, you can purchase a Remote Desktop Services client access license (CAL) and install the Remote Desktop Session Host and Remote Desktop Licensing Server roles.

Check for the following issues:
+ You've exceeded the maximum number of concurrent RDP sessions.
+ You've installed the Windows Remote Desktop Services role.
+ Licensing has expired. If the licensing has expired, you can't connect to your Windows instance as a user. You can try the following: 
  + Connect to the instance from the command line using an `/admin` parameter, for example: 

    ```
    mstsc /v:instance /admin
    ```

    For more information, see the following Microsoft article: [Access Remote Desktop Via Command Line](https://learn.microsoft.com/en-us/archive/technet-wiki/4487.access-remote-desktop-via-commandline).
  + Stop the instance, detach its Amazon EBS volumes, and attach them to another instance in the same Availability Zone to recover your data.

## "Some settings are managed by your organization"
<a name="some-settings-managed-by-org"></a>

Instances launched from the latest Windows Server AMIs might show a Windows Update dialog message stating "Some settings are managed by your organization." This message appears as a result of changes in Windows Server and does not impact the behavior of Windows Update or your ability to manage update settings.

**To remove the warning**

1. Open `gpedit.msc` and navigate to **Computer Configuration**, **Administrative Templates**, **Windows Components**, **Windows updates**. Edit **Configure Automatic Update**, and set it to **enabled**.

1. In a command prompt, update group policy using **gpupdate /force**.

1. Close and reopen the Windows Update Settings. You will see the above message about your settings being managed by your organization, followed by "We'll automatically download updates, except on metered connections (where charges may apply). In that case, we'll automatically download those updates required to keep Windows running smoothly."

1. Return to `gpedit.msc` and set the group policy back to **not configured**. Run **gpupdate /force** again.

1. Close the command prompt and wait a few minutes.

1. Reopen the Windows Update Settings. You should not see the message "Some settings are managed by your organization."

# Troubleshoot issues with Amazon EC2 Windows instances
<a name="win-ts-common-issues"></a>

The following are troubleshooting tips to help you solve the issues with Amazon EC2 Windows instances.

**Topics**
+ [Unable to connect AWS Systems Manager Sessions Manager to a Windows Server 2025 instance](#connect-sysmgr-win2025)
+ [EBS volumes don't initialize on Windows Server 2016 and 2019](#init-disks-win2k16)
+ [Boot an EC2 Windows instance into Directory Services Restore Mode (DSRM)](#boot-dsrm)
+ [Instance loses network connectivity or scheduled tasks don't run when expected](#instance-loses-network-connectivity)
+ [Unable to get console output](#no-console-output)
+ [Windows Server 2012 R2 not available on the network](#server-2012-network-loss)
+ [Disk signature collision](#disk-signature-collision)

## Unable to connect AWS Systems Manager Sessions Manager to a Windows Server 2025 instance
<a name="connect-sysmgr-win2025"></a>

You may encounter an issue connecting AWS Systems Manager Sessions Manager to a Windows Server 2025 instance. To address this issue, log onto the instance, then navigate to `Settings > Apps > Optional Features`, and add `WMIC`. Restart the SSM Agent service or reboot the instance, and Sessions Manager should connect.

You can also use the following PowerShell command to perform the same action:

```
Start-Process -FilePath "$env:SystemRoot\system32\Dism.exe" -ArgumentList @('/Online', '/Add-Capability', '/CapabilityName:WMIC~~~~') -Wait; Restart-Service -Name AmazonSSMAgent
```

## EBS volumes don't initialize on Windows Server 2016 and 2019
<a name="init-disks-win2k16"></a>

Instances created from Amazon Machine Images (AMIs) for Windows Server 2016 and 2019 use the EC2Launch v1 agent for a variety of startup tasks, including initializing EBS volumes. By default, EC2Launch v1 doesn't initialize secondary volumes. However, you can configure EC2Launch v1 to initialize these disks automatically, as follows.

**Map drive letters to volumes**

1. Connect to the instance to configure and open the `C:\ProgramData\Amazon\EC2-Windows\Launch\Config\DriveLetterMappingConfig.json` file in a text editor.

1. Specify the volume settings as follows:

   ```
   {
   "driveLetterMapping": [
   	{
   	  "volumeName": "sample volume",
   	  "driveLetter": "H"
   	}]
   }
   ```

1. Save your changes and close the file.

1. Open Windows PowerShell and use the following command to run the EC2Launch v1 script that initializes the disks:

   ```
   PS C:\>  C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1
   ```

   To initialize the disks each time the instance boots, add the `-Schedule` flag as follows:

   ```
   PS C:\>  C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1 -Schedule
   ```

   The EC2Launch v1 agent can run instance initialization scripts such as `initializeDisks.ps1` in parallel with the `InitializeInstance.ps1` script. If the `InitializeInstance.ps1` script reboots the instance, it might interrupt other scheduled tasks that run at instance startup. To avoid any potential conflicts, we recommend that you add logic to your `initializeDisks.ps1` script to ensure that instance initialization has finished first.
**Note**  
If the EC2Launch script does not initialize the volumes, ensure that the volumes are online. If the volumes are offline, run the following command to bring all disks online.  

   ```
   PS C:\> Get-Disk | Where-Object IsOffline -Eq $True | Set-Disk -IsOffline $False
   ```

## Boot an EC2 Windows instance into Directory Services Restore Mode (DSRM)
<a name="boot-dsrm"></a>

If an instance running Microsoft Active Directory experiences a system failure or other critical issues you can troubleshoot the instance by booting into a special version of Safe Mode called *Directory Services Restore Mode* (DSRM). In DSRM you can repair or recover Active Directory.

### Driver support for DSRM
<a name="boot-dsrm-driver"></a>

How you enable DSRM and boot into the instance depends on the drivers the instance is running. In the EC2 console you can view driver version details for an instance from the System Log. The following table shows which drivers are supported for DSRM.


| Driver Versions | DSRM Supported? | Next Steps | 
| --- | --- | --- | 
| Citrix PV 5.9 | No | Restore the instance from a backup. You cannot enable DSRM. | 
| AWS PV 7.2.0 | No | Though DSRM is not supported for this driver, you can still detach the root volume from the instance, take a snapshot of the volume or create an AMI from it, and attach it to another instance in the same Availability Zone as a secondary volume. You can then enable DSRM (as described in this section). | 
| AWS PV 7.2.2 and later | Yes | Detach the root volume, attach it to another instance, and enable DSRM (as described in this section). | 
| Enhanced Networking | Yes | Detach the root volume, attach it to another instance, and enable DSRM (as described in this section). | 

For information about how to enable enhanced networking, see [Enable enhanced networking with ENA on your EC2 instances](enhanced-networking-ena.md). For information about upgrading AWS PV drivers, see [Upgrade PV drivers on Windows instances](Upgrading_PV_drivers.md).

### Configure an instance to boot into DSRM
<a name="configure-boot-dsrm"></a>

EC2 Windows instances do not have network connectivity before the operating system is running. For this reason, you cannot press the F8 button on your keyboard to select a boot option. You must use one of the following procedures to boot an EC2 Windows Server instance into DSRM.

If you suspect that Active Directory has been corrupted and the instance is still running, you can configure the instance to boot into DSRM using either the System Configuration dialog box or the command prompt.

**To boot an online instance into DSRM using the System Configuration dialog box**

1. In the **Run** dialog box, type `msconfig` and press Enter.

1. Choose the **Boot** tab.

1. Under **Boot options** choose **Safe boot**.

1. Choose **Active Directory repair** and then choose **OK**. The system prompts you to reboot the server.

**To boot an online instance into DSRM using the command line**  
From a Command Prompt window, run the following command:

```
bcdedit /set safeboot dsrepair
```

If an instance is offline and unreachable, you must detach the root volume and attach it to another instance to enable DSRM mode.

**To boot an offline instance into DSRM**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**.

1. Locate and select the affected instance. Choose **Instance state**, **Stop instance**.

1. Choose **Launch instances** and create a temporary instance in the same Availability Zone as the affected instance. Choose an instance type that uses a different version of Windows. For example, if your instance is Windows Server 2016, then choose a Windows Server 2019 instance.
**Important**  
If you do not create the instance in the same Availability Zone as the affected instance you will not be able to attach the root volume of the affected instance to the new instance.

1. In the navigation pane, choose **Volumes**.

1. Locate the root volume of the affected instance. [Detach](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-detaching-volume.html) the volume and [attach](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-attaching-volume.html) it to the temporary instance you created earlier. Attach it with the default device name (xvdf).

1. Use Remote Desktop to connect to the temporary instance, and then use the Disk Management utility to [make the volume available for use](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-using-volumes.html).

1. Open a command prompt and run the following command. Replace *D* with the actual drive letter of the secondary volume you just attached:

   ```
   bcdedit /store D:\Boot\BCD /set {default} safeboot dsrepair
   ```

1. In the Disk Management Utility, choose the drive you attached earlier, open the context (right-click) menu, and choose **Offline**.

1. In the EC2 console, detach the affected volume from the temporary instance and reattach it to your original instance with the device name `/dev/sda1`. You must specify this device name to designate the volume as a root volume.

1. [Start](Stop_Start.md) the instance.

1. After the instance passes the health checks in the EC2 console, connect to the instance using Remote Desktop and verify that it boots into DSRM mode.

1. (Optional) Delete or stop the temporary instance you created in this procedure.

## Instance loses network connectivity or scheduled tasks don't run when expected
<a name="instance-loses-network-connectivity"></a>

If you restart your instance and it loses network connectivity, it's possible that the instance has the wrong time.

By default, Windows instances use Coordinated Universal Time (UTC). If you set the time for your instance to a different time zone and then restart it, the time becomes offset and the instance temporarily loses its IP address. The instance regains network connectivity eventually, but this can take several hours. The amount of time that it takes for the instance to regain network connectivity depends on the difference between UTC and the other time zone.

This same time issue can also result in scheduled tasks not running when you expect them to. In this case, the scheduled tasks do not run when expected because the instance has the incorrect time.

To use a time zone other than UTC persistently, you must set the **RealTimeIsUniversal** registry key. Without this key, an instance uses UTC after you restart it.

**To resolve time issues that cause a loss of network connectivity**

1. Ensure that you are running the recommended PV drivers. For more information, see [Upgrade PV drivers on EC2 Windows instances](Upgrading_PV_drivers.md).

1. Verify that the following registry key exists and is set to `1`: **HKEY\$1LOCAL\$1MACHINE\$1SYSTEM\$1CurrentControlSet\$1Control\$1TimeZoneInformation\$1RealTimeIsUniversal**

## Unable to get console output
<a name="no-console-output"></a>

For Windows instances, the instance console displays the output from tasks performed during the Windows boot process. If Windows boots successfully, the last message logged is `Windows is Ready to use`. You can also display event log messages in the console, but this feature might not be enabled by default depending on your version of Windows. For more information, see [Windows launch agents on Amazon EC2 Windows instances](configure-launch-agents.md).

To get the console output for your instance using the Amazon EC2 console, select the instance, and then choose **Actions**, **Monitor and troubleshoot**, **Get system log**. To get the console output using the command line, use one of the following commands: [get-console-output](https://docs.aws.amazon.com/cli/latest/reference/ec2/get-console-output.html) (AWS CLI) or [Get-EC2ConsoleOutput](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ConsoleOutput.html) (AWS Tools for Windows PowerShell).

For instances running Windows Server 2012 R2 and earlier, if the console output is empty, it could indicate an issue with the EC2Config service, such as a misconfigured configuration file, or that Windows failed to boot properly. To fix the issue, download and install the latest version of EC2Config. For more information, see [Install the latest version of EC2Config](UsingConfig_Install.md).

## Windows Server 2012 R2 not available on the network
<a name="server-2012-network-loss"></a>

For information about troubleshooting a Windows Server 2012 R2 instance that is not available on the network, see [ Windows Server 2012 R2 loses network and storage connectivity after an instance reboot](pvdrivers-troubleshooting.md#server2012R2-instance-unavailable).

## Disk signature collision
<a name="disk-signature-collision"></a>

You can check for and resolve disk signature collisions using [EC2Rescue for Windows Server](Windows-Server-EC2Rescue.md). Or, you can manually resolve disk signature issues by performing the following steps.
**Warning**  
The following procedure describes how to edit the Windows Registry using Registry Editor. If you are not familiar with the Windows Registry or how to safely make changes using Registry Editor, see [Configure the Registry](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc725612(v=ws.11)).

1. Open a command prompt, type **regedit.exe**, and press Enter.

1. In the **Registry Editor**, choose **HKEY\$1LOCAL\$1MACHINE** from the context menu (right-click), and then choose **Find**.

1. Type **Windows Boot Manager** and then choose **Find Next**.

1. Choose the key named `11000001`. This key is a sibling of the key you found in the previous step.

1. In the right pane, choose `Element` and then choose **Modify** from the context menu (right-click).

1. Locate the four-byte disk signature at offset 0x38 in the data. This is the Boot Configuration Database signature (BCD). Reverse the bytes to create the disk signature, and write it down. For example, the disk signature represented by the following data is `E9EB3AA5`:

   ```
   ...
   0030  00 00 00 00 01 00 00 00
   0038  A5 3A EB E9 00 00 00 00
   0040  00 00 00 00 00 00 00 00
   ...
   ```

1. In a Command Prompt window, run the following command to start Microsoft DiskPart.

   ```
   diskpart
   ```

1. Run the `select disk` DiskPart command and specify the disk number for the volume with the disk signature collision.
**Tip**  
To check the disk number for the volume with the disk signature collision, use the **Disk Management** utility. Open a command prompt, type `compmgmt.msc` and press **Enter**. In the left-hand navigation panel, double-click **Disk Management**. In the **Disk Management** utility, check the disk number for the offline volume with the disk signature collision.

   ```
   DISKPART> select disk 1
   Disk 1 is now the selected disk.
   ```

1. Run the following DiskPart command to get the disk signature.

   ```
   DISKPART>  uniqueid disk
   Disk ID: 0C764FA8
   ```

1. If the disk signature shown in the previous step doesn't match the disk signature that you wrote down earlier, use the following DiskPart command to change the disk signature so that it matches:

   ```
   DISKPART> uniqueid disk id=E9EB3AA5
   ```

# Kernel debugging for Windows instances over the network
<a name="troubleshoot-windows-with-kdnet"></a>

The KDNET Extensibility Module for Elastic Network Adapter (ENA) is a hardware driver support layer that enables Windows kernel debugging over the network through ENA on Amazon Elastic Compute Cloud instances. You can use the extensibility module with the Windows Debugger (WinDbg) to perform kernel-level debugging on EC2 instances running Windows.

Kernel debugging helps you diagnose and troubleshoot low-level operating system issues such as blue screen errors (BSODs), driver failures, and boot problems on your EC2 Windows instances.

**Topics**
+ [Prerequisites](#kdnet-prerequisites)
+ [Step 1: Install Windows Debugging Tools on the debug host](#kdnet-step1-install-debugging-tools)
+ [Step 2: Set up the debug target](#kdnet-step2-setup-debug-target)
+ [Step 3: Start the debugging session on the debug host](#kdnet-step3-start-debugging-session)
+ [Step 4: Reboot the debug target](#kdnet-step4-reboot-debug-target)
+ [Clean up debug settings after debugging](#kdnet-clean-up)
+ [Limitations](#kdnet-limitations)
+ [Additional notes](#kdnet-additional-notes)

## Prerequisites
<a name="kdnet-prerequisites"></a>

Before you begin, make sure you have the following:

Two EC2 Windows instances, in the same subnet:
+ A **debug host** instance — runs the Windows Debugger (WinDbg).
+ A **debug target** instance — the instance you want to debug.

For more information about launching instances, see [Get started with Amazon EC2](EC2_GetStarted.md).

Security groups for the host and target instances must allow inbound and outbound UDP traffic on the port used for KDNET debugging (recommended range: 50000–50039). The simplest way to set this up is to create a security group with an inbound rule that allows UDP traffic from itself as the source, and then attach that security group to both instances. For more information, see [Security group rules](https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html) in the *Amazon VPC User Guide*.

The debug target instance must run one of these Windows versions (or later):
+ Windows Server 2025 with build number 26100.7462 (December 2025 patch)
+ Windows 11 24H2 with build number 26100.7309
+ Windows 11 25H2 with build number 26200.7309

**Note**  
The KDNET extensibility module for ENA is distributed as part of Windows and can only be updated through Windows monthly cumulative updates. We recommend keeping the latest Windows KB installed on the debug target to ensure you have the most recent version of it.  
To verify that the module is present on the debug target, run the following command in an elevated PowerShell session:  

```
Test-Path C:\Windows\system32\kd_02_1d0f.dll
```
If the command returns `True`, the module is available.

## Step 1: Install Windows Debugging Tools on the debug host
<a name="kdnet-step1-install-debugging-tools"></a>

Install the Windows Debugging Tools on the debug host instance by running the following command in a PowerShell session:

```
winget install microsoft.windbg
```

For detailed installation instructions, see [Install the Windows Debugger](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/) in the Microsoft documentation.

After installation, verify that the debugger is working by running the following command in a PowerShell session:

```
windbgx
```

The WinDbg window should open. If it does, the installation was successful and you can close the window.

## Step 2: Set up the debug target
<a name="kdnet-step2-setup-debug-target"></a>

**Note**  
When kernel debugging is active, the ENA device used for the debugging session is dedicated to debugger traffic only. If you need to maintain internet access on the debug target instance during debugging, attach a second ENA to the instance before you begin.

On the debug target, open an elevated PowerShell session and configure kernel debugging using the following steps.

Run the following command to list the bus, device, and function number of the ENA adapter attached to the instance:

```
Get-NetAdapter -Physical |
    Where-Object -Property PnPDeviceID -Match -Value '^PCI\\VEN_1D0F&DEV_EC2[01]&' |
    Get-NetAdapterHardwareInfo |
    Select-Object InterfaceDescription, BusNumber, DeviceNumber, FunctionNumber |
    Format-List
```

### If multiple ENA adapters are attached to the instance
<a name="kdnet-multiple-ena-adapters"></a>

If multiple ENA adapters are attached to the instance, use the following command to map each physical adapter to its private IP address. You can cross-reference these details in the AWS Management Console under **EC2 → Instances → [Instance ID] → Networking → Network interfaces**. This helps you correlate specific Network Interface IDs, private IPs, and security groups with the OS-level adapter for targeted debugging.

```
Get-NetAdapter -Physical |
    Where-Object PnPDeviceID -Match '^PCI\\VEN_1D0F&DEV_EC2[01]&' |
    ForEach-Object {
        $adapter = $_
        $hwInfo = $adapter | Get-NetAdapterHardwareInfo
        $ipInfo = Get-NetIPAddress -InterfaceIndex $adapter.InterfaceIndex -AddressFamily IPv4
        [PSCustomObject]@{
            InterfaceDescription = $adapter.InterfaceDescription
            IPAddress            = $ipInfo.IPAddress
            BusNumber            = $hwInfo.BusNumber
            DeviceNumber         = $hwInfo.DeviceNumber
            FunctionNumber       = $hwInfo.FunctionNumber
        }
    } | Format-List
```

Note the `BusNumber`, `DeviceNumber`, and `FunctionNumber` values of the ENA adapter to be used for debugging from the output.

Run the following commands to configure kernel debugging. Replace the placeholder values with your specific configuration:

```
bcdedit /debug on
bcdedit /set loadoptions FORCEHVTONOTSHAREDEBUGDEVICE
bcdedit /dbgsettings net hostip:host-private-ip port:port-number key:encryption-key busparams:b.d.f
```

**Note**  
Check for existing `loadoptions` by running the following command. If a value is returned, copy that string and append `;FORCEHVTONOTSHAREDEBUGDEVICE` to it.  

```
(bcdedit /enum) -match "loadoptions"
```

Where:
+ *host-private-ip* — The private IPv4 address of the debug host instance. If your instances are launched in an IPv6-only subnet, see [Setting up KDNET with IPv6](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection#ipv6) in the Microsoft documentation to learn more about using IPv6 with KDNET.
+ *port-number* — The port to use for the debugging session. The recommended range is 50000–50039 (for example, `50000`).
+ *encryption-key* — A 256-bit key used to encrypt the debugging connection, specified as four 64-bit values separated by periods. Each 64-bit value can be up to 13 characters long using only lowercase letters a–z and digits 0–9. Special characters are not allowed. Example encryption key: `1kdnet2keys3.4kdnet5keys6.7kdnet8keys9.10kdnet11ke`.
+ *b.d.f* — The bus, device, and function numbers for the ENA device, formatted as `bus.device.function` (for example, `0.3.0`), used for debugging.

**Tip**  
To debug the Windows boot process, also run the following command:  

```
bcdedit /bootdebug on
```

## Step 3: Start the debugging session on the debug host
<a name="kdnet-step3-start-debugging-session"></a>

To allow debugging traffic on the host, you can create a firewall rule for either the WinDbg application or a specific UDP port.

**Option 1: Allow the WinDbg application**  
Run the following commands to authorize the WinDbg executable:

```
$WinDbgxPath = "$env:LocalAppData\Microsoft\WindowsApps\WinDbgX.exe"
New-NetFirewallRule -DisplayName "Allow Inbound KDNET Connection" -Action Allow -Program $WinDbgxPath
```

**Option 2: Allow a specific UDP port**  
Alternatively, you can allow inbound UDP traffic to the port configured for kernel debugging. Replace *port-number* with your chosen KDNET port:

```
$DebugPort = port-number
New-NetFirewallRule -DisplayName "Allow Inbound KDNET Connection" -Direction Inbound -LocalPort $DebugPort -Protocol UDP -Action Allow
```

**Note**  
Firewall configurations may be restricted by Domain Group Policy (GPO) or require elevated Administrator permissions. If the command fails, contact your network administrator.

Start WinDbg with the port and key that match the debug target configuration. You can specify additional kernel debugging options documented in the [Microsoft WinDbg command line reference](https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/windbg-command-line-preview#kernel-options) to suit your use case.

```
windbgx -k net:port=port-number,key=encryption-key
```

WinDbg opens and waits for the debug target to connect.

## Step 4: Reboot the debug target
<a name="kdnet-step4-reboot-debug-target"></a>

On the debug target, restart the instance to initiate the debugging connection:

```
shutdown -r -t 0
```

After the debug target restarts, WinDbg on the debug host connects to the target automatically. You can now use WinDbg to inspect the kernel state, set breakpoints, and diagnose issues.

## Clean up debug settings after debugging
<a name="kdnet-clean-up"></a>

**On the debug target**  
After you finish debugging, remove the kernel debugging configuration from the debug target to restore normal boot behavior. On the debug target, open an elevated PowerShell session and run the following commands:

```
bcdedit /debug off
bcdedit /dbgsettings LOCAL
bcdedit /deletevalue loadoptions
```

If you have existing `loadoptions` other than `FORCEHVTONOTSHAREDEBUGDEVICE`, you should restore the setting by running `bcdedit /set loadoptions` with the original `loadoptions`.

If you enabled boot debugging, also run:

```
bcdedit /bootdebug off
```

Restart the instance for the changes to take effect.

**On the debug host**  
Remove the firewall rule by running:

```
Remove-NetFirewallRule -DisplayName "Allow Inbound KDNET Connection"
```

## Limitations
<a name="kdnet-limitations"></a>

The KDNET extensibility module for ENA does not currently support:
+ 8th generation non-metal x86\$164 instance types (for example, `m8a.xlarge`)
+ 7th generation 48xlarge non-metal x86\$164 instance types (for example, `m7a.48xlarge`)
+ u7i instance types

The module does not currently support instances with Secure Boot enabled. You can verify the status by running `Confirm-SecureBootUEFI` in an elevated PowerShell session. If the output is `True`, Secure Boot is active. Note that all Amazon-provided images with a 'TPM' prefix have Secure Boot enabled by default.

## Additional notes
<a name="kdnet-additional-notes"></a>

If you encounter issues connecting the debugger to the target instance, verify the following:
+ All prerequisites listed in this guide are met, including the required Windows Server build version and the presence of the extensibility module.
+ The security groups attached to both instances are configured correctly to allow traffic between them on the configured debugging port.
+ Windows Firewall rules on the host instances do not block network traffic between the two instances on the configured port.

For additional guidance, see [Set up KDNET network kernel debugging manually](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection) in the Microsoft documentation.

# Reset the Windows administrator password for an Amazon EC2 Windows instance
<a name="ResettingAdminPassword"></a>

If you are no longer able to connect to your Amazon EC2 Windows instance because the Windows administrator password is lost or expired, you can reset the password.

**Note**  
There is an AWS Systems Manager Automation document that automatically applies the manual steps necessary to reset the local administrator password. For more information, see [Reset passwords and SSH keys on EC2 instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html) in the *AWS Systems Manager User Guide*.

The manual methods to reset the administrator password use EC2Launch v2, EC2Config, or EC2Launch.
+ For all supported Windows AMIs that include the EC2Launch v2 agent, use EC2Launch v2.
+ For Windows AMIs before Windows Server 2016, use the EC2Config service.
+ For Windows Server 2016 and later AMIs, use the EC2Launch service.

These procedures also describe how to connect to an instance if you lost the key pair that was used to create the instance. Amazon EC2 uses a public key to encrypt a piece of data, such as a password, and a private key to decrypt the data. The public and private keys are known as a *key pair*. With Windows instances, you use a key pair to obtain the administrator password and then log in using RDP.

**Note**  
If you have disabled the local administrator account on the instance and your instance is configured for Systems Manager, you can also re-enable and reset your local administrator password by using EC2Rescue and Run Command. For more information, see [Use EC2Rescue for Windows Server with Systems Manager Run Command](ec2rw-ssm.md).

**Topics**
+ [Reset Windows admin password for EC2 instance using EC2Launch v2](ResettingAdminPassword_EC2Launchv2.md)
+ [Reset Windows admin password for EC2 instance using EC2Launch](ResettingAdminPassword_EC2Launch.md)
+ [Reset Windows admin password for EC2 instance using EC2Config](ResettingAdminPassword_EC2Config.md)

# Reset Windows admin password for EC2 instance using EC2Launch v2
<a name="ResettingAdminPassword_EC2Launchv2"></a>

If you have lost your Windows administrator password and are using a supported Windows AMI that includes the EC2Launch v2 agent, you can use EC2Launch v2 to generate a new password.

If you are using a Windows Server 2016 or later AMI that does not include the EC2Launch v2 agent, see [Reset Windows admin password for EC2 instance using EC2Launch](ResettingAdminPassword_EC2Launch.md).

If you are using a Windows Server AMI earlier than Windows Server 2016 that does not include the EC2Launch v2 agent, see [Reset Windows admin password for EC2 instance using EC2Config](ResettingAdminPassword_EC2Config.md).

**Note**  
If you have disabled the local administrator account on the instance and your instance is configured for Systems Manager, you can also re-enable and reset your local administrator password by using EC2Rescue and Run Command. For more information, see [Use EC2Rescue for Windows Server with Systems Manager Run Command](ec2rw-ssm.md).

**Note**  
There is an AWS Systems Manager Automation document that automatically applies the manual steps necessary to reset the local administrator password. For more information, see [Reset passwords and SSH keys on EC2 instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html) in the *AWS Systems Manager User Guide*.

To reset your Windows administrator password using EC2Launch v2, you need to do the following:
+ [Step 1: Verify that the EC2Launch v2 agent is running](#resetting-password-ec2launchv2-step1)
+ [Step 2: Detach the root volume from the instance](#resetting-password-ec2launchv2-step2)
+ [Step 3: Attach the volume to a temporary instance](#resetting-password-ec2launchv2-step3)
+ [Step 4: Delete the .run-once file](#resetting-password-ec2launchv2-step4)
+ [Step 5: Restart the original instance](#resetting-password-ec2launchv2-step5)

## Step 1: Verify that the EC2Launch v2 agent is running
<a name="resetting-password-ec2launchv2-step1"></a>

Before you attempt to reset the administrator password, verify that the EC2Launch v2 agent is installed and running. You use the EC2Launch v2 agent to reset the administrator password later in this section.

**To verify that the EC2Launch v2 agent is running**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and then select the instance that requires a password reset. This instance is referred to as the *original* instance in this procedure.

1. Choose **Actions**, **Monitor and troubleshoot**, **Get system log**.

1. Locate the EC2 Launch entry, for example, **Launch: EC2Launch v2 service v2.0.124**. If you see this entry, the EC2Launch v2 service is running.

   If the system log output is empty, or if the EC2Launch v2 agent is not running, troubleshoot the instance using the Instance Console Screenshot service. For more information, see [Capture a screenshot of an unreachable instance](troubleshoot-unreachable-instance.md#instance-console-screenshot).

## Step 2: Detach the root volume from the instance
<a name="resetting-password-ec2launchv2-step2"></a>

You can't use EC2Launch v2 to reset an administrator password if the volume on which the password is stored is attached to an instance as the root volume. You must detach the volume from the original instance before you can attach it to a temporary instance as a secondary volume.

**To detach the root volume from the instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**.

1. Select the instance that requires a password reset and choose **Instance state**, **Stop instance**. After the status of the instance changes to **Stopped**, continue with the next step.

1. (Optional) If you have the private key that you specified when you launched this instance, continue with the next step. Otherwise, use the following steps to replace the instance with a new instance that you launch with a new key pair.

   1. Create a new key pair using the Amazon EC2 console. To give your new key pair the same name as the one for which you lost the private key, you must first delete the existing key pair.

   1. Select the instance to replace. Note the instance type, VPC, subnet, security group, and IAM role of the instance.

   1. With the instance selected, choose **Actions**, **Image and templates**, **Create image**. Type a name and a description for the image and choose **Create image**.

   1. In the navigation pane, choose **AMIs**. Wait for the image status to change to **available**. Then, select the image and choose **Launch instance from AMI**.

   1. Complete the fields to launch an instance, making sure to select the same instance type, VPC, subnet, security group, and IAM role as the instance to replace, and then choose **Launch instance**.

   1. When prompted, choose the key pair that you created for the new instance, and then choose **Launch instance**.

   1. (Optional) If the original instance has an associated Elastic IP address, transfer it to the new instance. If the original instance has EBS volumes in addition to the root volume, transfer them to the new instance.

1. Detach the root volume from the original instance as follows:

   1. Select the original instance and choose the **Storage** tab. Note the name of the root device under **Root device name**. Find the volume with this device name under **Block devices**, and note the volume ID.

   1. In the navigation pane, choose **Volumes**.

   1. In the list of volumes, select the volume that you noted as the root device, and choose **Actions**, **Detach Volume**. After the volume status changes to **available**, continue with the next step.

1. If you created a new instance to replace your original instance, you can terminate the original instance now. It's no longer needed. For the remainder of this procedure, all references to the original instance apply to the new instance that you created.

## Step 3: Attach the volume to a temporary instance
<a name="resetting-password-ec2launchv2-step3"></a>

Next, launch a temporary instance and attach the volume to it as a secondary volume. This is the instance you use to modify the configuration file.

**To launch a temporary instance and attach the volume**

1. Launch the temporary instance as follows:

   1. In the navigation pane, choose **Instances**, choose **Launch instances**, and then select an AMI.
**Important**  
To avoid disk signature collisions, you must select an AMI for a different version of Windows. For example, if the original instance runs Windows Server 2019, launch the temporary instance using the base AMI for Windows Server 2016.

   1. Leave the default instance type and choose **Next: Configure Instance Details**.

   1. On the **Configure Instance Details** page, for **Subnet**, select the same Availability Zone as the original instance and choose **Review and Launch**.
**Important**  
The temporary instance must be in the same Availability Zone as the original instance. If your temporary instance is in a different Availability Zone, you can't attach the original instance's root volume to it.

   1. On the **Review Instance Launch** page, choose **Launch**.

   1. When prompted, create a new key pair, download it to a safe location on your computer, and then choose **Launch Instances**.

1. Attach the volume to the temporary instance as a secondary volume as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the original instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your temporary instance and select the instance from the list.

   1. For **Device**, type **xvdf** (if it isn't already there), and choose **Attach**.

## Step 4: Delete the .run-once file
<a name="resetting-password-ec2launchv2-step4"></a>

You must now delete the `.run-once` file from the offline volume attached to the instance. This directs EC2Launch v2 to run all tasks with a frequency of `once`, which includes setting the administrator password. The file path in the secondary volume that you attached will be similar to `D:\ProgramData\Amazon\EC2Launch\state\.run-once`.

**To delete the .run-once file**

1. Open the **Disk Management** utility, and bring the drive online using these instructions: [Make an Amazon EBS volume available for use](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-using-volumes.html).

1. Locate the `.run-once` file in the disk you brought online.

1. Delete the .run-once file.

**Important**  
Any scripts set to run once will be triggered by this action.

## Step 5: Restart the original instance
<a name="resetting-password-ec2launchv2-step5"></a>

After you have deleted the `.run-once` file, reattach the volume to the original instance as the root volume and connect to the instance using its key pair to retrieve the administrator password.

1. Reattach the volume to the original instance as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the temporary instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your original instance and then select the instance.

   1. For **Device**, type **/dev/sda1**.

   1. Choose **Attach**. After the volume status changes to `in-use`, continue to the next step.

1. In the navigation pane, choose **Instances**. Select the original instance and choose **Instance state**, **Start instance**. After the instance state changes to `Running`, continue to the next step.

1. Retrieve your new Windows administrator password using the private key for the new key pair and connect to the instance. For more information, see [Connect to your Windows instance using RDP](connecting_to_windows_instance.md).
**Important**  
The instance gets a new public IP address after you stop and start it. Make sure to connect to the instance using its current public DNS name. For more information, see [Amazon EC2 instance state changes](ec2-instance-lifecycle.md).

1. (Optional) If you have no further use for the temporary instance, you can terminate it. Select the temporary instance, and choose **Instance State**, **Terminate instance**.

# Reset Windows admin password for EC2 instance using EC2Launch
<a name="ResettingAdminPassword_EC2Launch"></a>

If you have lost your Windows administrator password and are using a Windows Server 2016 or later AMI, you can use the [EC2Rescue tool](Windows-Server-EC2Rescue.md), which uses the EC2Launch service to generate a new password.

If you are using a Windows Server 2016 or later AMI that does not include the EC2Launch v2 agent, you can use EC2Launch v2 to generate a new password.

If you are using a Windows Server AMI earlier than Windows Server 2016, see [Reset Windows admin password for EC2 instance using EC2Config](ResettingAdminPassword_EC2Config.md).

**Warning**  
When you stop an instance, the data on instance store volumes is lost. To preserve this data, back it up to persistent storage.

**Note**  
If you have disabled the local administrator account on the instance and your instance is configured for Systems Manager, you can also re-enable and reset your local administrator password by using EC2Rescue and Run Command. For more information, see [Use EC2Rescue for Windows Server with Systems Manager Run Command](ec2rw-ssm.md).

**Note**  
There is an AWS Systems Manager Automation document that automatically applies the manual steps necessary to reset the local administrator password. For more information, see [Reset passwords and SSH keys on EC2 instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html) in the *AWS Systems Manager User Guide*.

To reset your Windows administrator password using EC2Launch, you need to do the following:
+ [Step 1: Detach the root volume from the instance](#resetting-password-ec2launch-step1)
+ [Step 2: Attach the volume to a temporary instance](#resetting-password-ec2launch-step2)
+ [Step 3: Reset the administrator password](#resetting-password-ec2launch-step3)
+ [Step 4: Restart the original instance](#resetting-password-ec2launch-step4)

## Step 1: Detach the root volume from the instance
<a name="resetting-password-ec2launch-step1"></a>

You can't use EC2Launch to reset an administrator password if the volume on which the password is stored is attached to an instance as the root volume. You must detach the volume from the original instance before you can attach it to a temporary instance as a secondary volume.

**To detach the root volume from the instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**.

1. Select the instance that requires a password reset and choose **Instance state**, **Stop instance**. After the status of the instance changes to **Stopped**, continue with the next step.

1. (Optional) If you have the private key that you specified when you launched this instance, continue with the next step. Otherwise, use the following steps to replace the instance with a new instance that you launch with a new key pair.

   1. Create a new key pair using the Amazon EC2 console. To give your new key pair the same name as the one for which you lost the private key, you must first delete the existing key pair.

   1. Select the instance to replace. Note the instance type, VPC, subnet, security group, and IAM role of the instance.

   1. With the instance selected, choose **Actions**, **Image and templates**, **Create image**. Type a name and a description for the image and choose **Create image**.

   1. In the navigation pane, choose **AMIs**. Wait for the image status to change to **available**. Then, select the image and choose **Launch instance from AMI**.

   1. Complete the fields to launch an instance, making sure to select the same instance type, VPC, subnet, security group, and IAM role as the instance to replace, and then choose **Launch instance**.

   1. When prompted, choose the key pair that you created for the new instance, and then choose **Launch instance**.

   1. (Optional) If the original instance has an associated Elastic IP address, transfer it to the new instance. If the original instance has EBS volumes in addition to the root volume, transfer them to the new instance.

1. Detach the root volume from the original instance as follows:

   1. Select the original instance and choose the **Storage** tab. Note the name of the root device under **Root device name**. Find the volume with this device name under **Block devices**, and note the volume ID.

   1. In the navigation pane, choose **Volumes**.

   1. In the list of volumes, select the volume that you noted as the root device, and choose **Actions**, **Detach Volume**. After the volume status changes to **available**, continue with the next step.

1. If you created a new instance to replace your original instance, you can terminate the original instance now. It's no longer needed. For the remainder of this procedure, all references to the original instance apply to the new instance that you created.

## Step 2: Attach the volume to a temporary instance
<a name="resetting-password-ec2launch-step2"></a>

Next, launch a temporary instance and attach the volume to it as a secondary volume. This is the instance you use to run EC2Launch.

**To launch a temporary instance and attach the volume**

1. Launch the temporary instance as follows:

   1. In the navigation pane, choose **Instances**, choose **Launch instances**, and then select an AMI.
**Important**  
To avoid disk signature collisions, you must select an AMI for a different version of Windows. For example, if the original instance runs Windows Server 2019, launch the temporary instance using the base AMI for Windows Server 2016.

   1. Leave the default instance type and choose **Next: Configure Instance Details**.

   1. On the **Configure Instance Details** page, for **Subnet**, select the same Availability Zone as the original instance and choose **Review and Launch**.
**Important**  
The temporary instance must be in the same Availability Zone as the original instance. If your temporary instance is in a different Availability Zone, you can't attach the original instance's root volume to it.

   1. On the **Review Instance Launch** page, choose **Launch**.

   1. When prompted, create a new key pair, download it to a safe location on your computer, and then choose **Launch Instances**.

1. Attach the volume to the temporary instance as a secondary volume as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the original instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your temporary instance and select the instance from the list.

   1. For **Device**, type **xvdf** (if it isn't already there), and choose **Attach**.

## Step 3: Reset the administrator password
<a name="resetting-password-ec2launch-step3"></a>

Next, connect to the temporary instance and use EC2Launch to reset the administrator password.

**To reset the administrator password**

1. Connect to the temporary instance and use the EC2Rescue for Windows Server tool on the instance to reset the administrator password as follows:

   1. Download the [EC2Rescue for Windows Server](https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip) zip file, extract the contents, and run **EC2Rescue.exe**.

   1. On the **License Agreement** screen, read the license agreement, and, if you accept the terms, choose **I Agree**.

   1. On the **Welcome to EC2Rescue for Windows Server** screen, choose **Next**.

   1. On the **Select mode** screen, choose **Offline instance**.

   1. On the **Select a disk** screen, select the **xvdf** device and choose **Next**.

   1. Confirm the disk selection and choose **Yes**.

   1. After the volume has loaded, choose **OK**.

   1. On the **Select Offline Instance Option** screen, choose **Diagnose and Rescue**.

   1. On the **Summary** screen, review the information and choose **Next**.

   1. On the **Detected possible issues** screen, select **Reset Administrator Password** and choose **Next**.

   1. On the **Confirm** screen, choose **Rescue**, **OK**.

   1. On the **Done** screen, choose **Finish**.

   1. Close the EC2Rescue for Windows Server tool, disconnect from the temporary instance, and then return to the Amazon EC2 console.

1. Detach the secondary (`xvdf`) volume from the temporary instance as follows:

   1. In the navigation pane, choose **Instances** and select the temporary instance.

   1. On the **Storage** tab for the temporary instance, note the ID of the EBS volume listed as **xvdf**.

   1. In the navigation pane, choose **Volumes**.

   1. In the list of volumes, select the volume noted in the previous step, and choose **Actions**, **Detach Volume**. After the volume status changes to **available**, continue with the next step.

## Step 4: Restart the original instance
<a name="resetting-password-ec2launch-step4"></a>

After you have reset the administrator password using EC2Launch, reattach the volume to the original instance as the root volume and connect to the instance using its key pair to retrieve the administrator password.

**To restart the original instance**

1. Reattach the volume to the original instance as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the temporary instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your original instance and then select the instance.

   1. For **Device**, type **/dev/sda1**.

   1. Choose **Attach**. After the volume status changes to `in-use`, continue to the next step.

1. In the navigation pane, choose **Instances**. Select the original instance and choose **Instance state**, **Start instance**. After the instance state changes to `Running`, continue to the next step.

1. Retrieve your new Windows administrator password using the private key for the new key pair and connect to the instance. For more information, see [Connect to your Windows instance using RDP](connecting_to_windows_instance.md).

1. (Optional) If you have no further use for the temporary instance, you can terminate it. Select the temporary instance, and choose **Instance State**, **Terminate instance**.

# Reset Windows admin password for EC2 instance using EC2Config
<a name="ResettingAdminPassword_EC2Config"></a>

If you have lost your Windows administrator password and are using a Windows AMI before Windows Server 2016, you can use the EC2Config agent to generate a new password.

If you are using a Windows Server 2016 or later AMI, see [Reset Windows admin password for EC2 instance using EC2Launch](ResettingAdminPassword_EC2Launch.md) or, you can use the [EC2Rescue tool](Windows-Server-EC2Rescue.md), which uses the EC2Launch service to generate a new password.

**Note**  
If you have disabled the local administrator account on the instance and your instance is configured for Systems Manager, you can also re-enable and reset your local administrator password by using EC2Rescue and Run Command. For more information, see [Use EC2Rescue for Windows Server with Systems Manager Run Command](ec2rw-ssm.md).

**Note**  
There is an AWS Systems Manager Automation document that automatically applies the manual steps necessary to reset the local administrator password. For more information, see [Reset passwords and SSH keys on EC2 instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-ec2reset.html) in the *AWS Systems Manager User Guide*.

To reset your Windows administrator password using EC2Config, you need to do the following:
+ [Step 1: Verify that the EC2Config service is running](#resetting-password-ec2config-step1)
+ [Step 2: Detach the root volume from the instance](#resetting-password-ec2config-step2)
+ [Step 3: Attach the volume to a temporary instance](#resetting-password-ec2config-step3)
+ [Step 4: Modify the configuration file](#resetting-password-ec2config-step4)
+ [Step 5: Restart the original instance](#resetting-password-ec2config-step5)

## Step 1: Verify that the EC2Config service is running
<a name="resetting-password-ec2config-step1"></a>

Before you attempt to reset the administrator password, verify that the EC2Config service is installed and running. You use the EC2Config service to reset the administrator password later in this section.

**To verify that the EC2Config service is running**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances** and then select the instance that requires a password reset. This instance is referred to as the *original* instance in this procedure.

1. Choose **Actions**, **Monitor and troubleshoot**, **Get system log**.

1. Locate the EC2 Agent entry, for example, **EC2 Agent: Ec2Config service v3.18.1118**. If you see this entry, the EC2Config service is running.

   If the system log output is empty, or if the EC2Config service is not running, troubleshoot the instance using the Instance Console Screenshot service. For more information, see [Capture a screenshot of an unreachable instance](troubleshoot-unreachable-instance.md#instance-console-screenshot).

## Step 2: Detach the root volume from the instance
<a name="resetting-password-ec2config-step2"></a>

You can't use EC2Config to reset an administrator password if the volume on which the password is stored is attached to an instance as the root volume. You must detach the volume from the original instance before you can attach it to a temporary instance as a secondary volume.

**To detach the root volume from the instance**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**.

1. Select the instance that requires a password reset and choose **Instance state**, **Stop instance**. After the status of the instance changes to **Stopped**, continue with the next step.

1. (Optional) If you have the private key that you specified when you launched this instance, continue with the next step. Otherwise, use the following steps to replace the instance with a new instance that you launch with a new key pair.

   1. Create a new key pair using the Amazon EC2 console. To give your new key pair the same name as the one for which you lost the private key, you must first delete the existing key pair.

   1. Select the instance to replace. Note the instance type, VPC, subnet, security group, and IAM role of the instance.

   1. With the instance selected, choose **Actions**, **Image and templates**, **Create image**. Type a name and a description for the image and choose **Create image**.

   1. In the navigation pane, choose **AMIs**. Wait for the image status to change to **available**. Then, select the image and choose **Launch instance from AMI**.

   1. Complete the fields to launch an instance, making sure to select the same instance type, VPC, subnet, security group, and IAM role as the instance to replace, and then choose **Launch instance**.

   1. When prompted, choose the key pair that you created for the new instance, and then choose **Launch instance**.

   1. (Optional) If the original instance has an associated Elastic IP address, transfer it to the new instance. If the original instance has EBS volumes in addition to the root volume, transfer them to the new instance.

1. Detach the root volume from the original instance as follows:

   1. Select the original instance and choose the **Storage** tab. Note the name of the root device under **Root device name**. Find the volume with this device name under **Block devices**, and note the volume ID.

   1. In the navigation pane, choose **Volumes**.

   1. In the list of volumes, select the volume that you noted as the root device, and choose **Actions**, **Detach Volume**. After the volume status changes to **available**, continue with the next step.

1. If you created a new instance to replace your original instance, you can terminate the original instance now. It's no longer needed. For the remainder of this procedure, all references to the original instance apply to the new instance that you created.

## Step 3: Attach the volume to a temporary instance
<a name="resetting-password-ec2config-step3"></a>

Next, launch a temporary instance and attach the volume to it as a secondary volume. This is the instance you use to modify the configuration file.

**To launch a temporary instance and attach the volume**

1. Launch the temporary instance as follows:

   1. In the navigation pane, choose **Instances**, choose **Launch instances**, and then select an AMI.
**Important**  
To avoid disk signature collisions, you must select an AMI for a different version of Windows. For example, if the original instance runs Windows Server 2019, launch the temporary instance using the base AMI for Windows Server 2016.

   1. Leave the default instance type and choose **Next: Configure Instance Details**.

   1. On the **Configure Instance Details** page, for **Subnet**, select the same Availability Zone as the original instance and choose **Review and Launch**.
**Important**  
The temporary instance must be in the same Availability Zone as the original instance. If your temporary instance is in a different Availability Zone, you can't attach the original instance's root volume to it.

   1. On the **Review Instance Launch** page, choose **Launch**.

   1. When prompted, create a new key pair, download it to a safe location on your computer, and then choose **Launch Instances**.

1. Attach the volume to the temporary instance as a secondary volume as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the original instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your temporary instance and select the instance from the list.

   1. For **Device**, type **xvdf** (if it isn't already there), and choose **Attach**.

## Step 4: Modify the configuration file
<a name="resetting-password-ec2config-step4"></a>

After you have attached the volume to the temporary instance as a secondary volume, modify the `Ec2SetPassword` plugin in the configuration file.

**To modify the configuration file**

1. From the temporary instance, modify the configuration file on the secondary volume as follows:

   1. Launch and connect to the temporary instance.

   1. Use the following instructions to bring the drive online: [Make an Amazon EBS volume available for use](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-using-volumes.html).

   1. Navigate to the secondary volume, and open `\Program Files\Amazon\Ec2ConfigService\Settings\config.xml` using a text editor, such as Notepad.

   1. At the top of the file, find the plugin with the name `Ec2SetPassword`, as shown in the screenshot. Change the state from `Disabled` to `Enabled` and save the file.  
![\[The area of the Config.xml file to change\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/pwreset_config.png)

1. After you have modified the configuration file, detach the secondary volume from the temporary instance as follows:

   1. Using the **Disk Management** utility, bring the volume offline.

   1. Disconnect from the temporary instance and return to the Amazon EC2 console.

   1. In the navigation pane, choose **Volumes**, select the volume, and then choose **Actions**, **Detach Volume**. After the volume's status changes to **available**, continue with the next step.

## Step 5: Restart the original instance
<a name="resetting-password-ec2config-step5"></a>

After you have modified the configuration file, reattach the volume to the original instance as the root volume and connect to the instance using its key pair to retrieve the administrator password.

1. Reattach the volume to the original instance as follows:

   1. In the navigation pane, choose **Volumes**, select the volume that you detached from the temporary instance, and then choose **Actions**, **Attach Volume**.

   1. In the **Attach Volume** dialog box, for **Instances**, start typing the name or ID of your original instance and then select the instance.

   1. For **Device**, type **/dev/sda1**.

   1. Choose **Attach**. After the volume status changes to `in-use`, continue to the next step.

1. In the navigation pane, choose **Instances**. Select the original instance and choose **Instance state**, **Start instance**. After the instance state changes to `Running`, continue to the next step.

1. Retrieve your new Windows administrator password using the private key for the new key pair and connect to the instance. For more information, see [Connect to your Windows instance using RDP](connecting_to_windows_instance.md).
**Important**  
The instance gets a new public IP address after you stop and start it. Make sure to connect to the instance using its current public DNS name. For more information, see [Amazon EC2 instance state changes](ec2-instance-lifecycle.md).

1. (Optional) If you have no further use for the temporary instance, you can terminate it. Select the temporary instance, and choose **Instance State**, **Terminate instance**.

# Troubleshoot Sysprep issues with Amazon EC2 Windows instances
<a name="sysprep-troubleshoot"></a>

If you experience problems or receive error messages during image preparations, review the following logs. Log location varies depending on whether you are running EC2Config, EC2Launch v1, or EC2Launch v2 with Sysprep.
+ `%WINDIR%\Panther\Unattendgc` (EC2Config, EC2Launch v1, and EC2Launch v2)
+ `%WINDIR%\System32\Sysprep\Panther` (EC2Config, EC2Launch v1, and EC2Launch v2)
+ `C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt` (EC2Config only)
+ `C:\ProgramData\Amazon\Ec2Config\Logs` (EC2Config only)
+ `C:\ProgramData\Amazon\EC2-Windows\Launch\Log\EC2Launch.log` (EC2Launch v1 only)
+ `%ProgramData%\Amazon\EC2Launch\log\agent.log` (EC2Launch v2 only)

If you receive an error message during image preparation with Sysprep, the OS might not be reachable. To review the log files, you must stop the instance, attach its root volume to another healthy instance as a secondary volume, and then review the logs mentioned earlier on the secondary volume. For more information about the purpose of the log files by name, see [Windows Setup-Related Log Files](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/deployment-troubleshooting-and-log-files#windows-setup-related-log-files) in the Microsoft documentation.

If you locate errors in the Unattendgc log file, use the [Microsoft Error Lookup Tool](https://www.microsoft.com/en-us/download/details.aspx?id=100432) to get more details about the error. The following issue reported in the Unattendgc log file is typically the result of one or more corrupted user profiles on the instance:

```
Error [Shell Unattend] _FindLatestProfile failed (0x80070003) [gle=0x00000003]
Error [Shell Unattend] CopyProfile failed (0x80070003) [gle=0x00000003]
```

There are two options for resolving this issue:

**Option 1**

Use Regedit on the instance to search for the following key. Verify that there are no profile registry keys for a deleted user.

`[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\`

**Option 2**

1. Edit the relevant file, as follows:
   + Windows Server 2012 R2 and earlier – Edit the EC2Config answer file (`C:\Program Files\Amazon\Ec2ConfigService\sysprep2008.xml`).
   + Windows Server 2016 and 2019 – Edit the unattend.xml answer file (`C:\ProgramData\Amazon\EC2-Windows\Launch\Sysprep\Unattend.xml`).
   + Windows Server 2022 – Edit the unattend.xml answer file (`C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml`). 

1. Change `<CopyProfile>true</CopyProfile>` to `<CopyProfile>false</CopyProfile>`.

1. Run Sysprep again. Note that this configuration change will delete the built-in administrator user profile after Sysprep completes.

# Troubleshoot impaired Amazon EC2 Linux instance using EC2Rescue
<a name="Linux-Server-EC2Rescue"></a>

EC2Rescue for Linux is an easy-to-use, open-source tool that can be run on an Amazon EC2 Linux instance to diagnose, troubleshoot, and remediate common issues using its library of over 100 *modules*. Modules are YAML files that contain either a BASH or a Python script and the necessary metadata.

Some generalized use cases for EC2Rescue for Linux instances include:
+ Gathering syslog and package manager logs
+ Collecting resource utilization data
+ Diagnosing and remediating known problematic kernel parameters and common OpenSSH issues

**Note**  
The `AWSSupport-TroubleshootSSH` AWS Systems Manager Automation runbook installs EC2Rescue for Linux and then uses the tool to check or attempt to fix common issues that prevent an SSH connection to a Linux instance. For more information, see [AWSSupport-TroubleshootSSH](https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshootssh.html).

If you are using a Windows instance, see [Troubleshoot impaired Amazon EC2 Windows instance using EC2Rescue](Windows-Server-EC2Rescue.md).

**Topics**
+ [Install EC2Rescue](ec2rl_install.md)
+ [Run EC2Rescue commands](ec2rl_working.md)
+ [Develop EC2Rescue modules](ec2rl_moduledev.md)

# Install EC2Rescue on an Amazon EC2 Linux instance
<a name="ec2rl_install"></a>

The EC2Rescue for Linux tool can be installed on an Amazon EC2 Linux instance that meets the following prerequisites.

**Prerequisites**
+ Supported operating systems:
  + Amazon Linux 2
  + Amazon Linux 2016.09\$1
  + SUSE Linux Enterprise Server 12\$1
  + RHEL 7\$1
  + Ubuntu 16.04\$1
+ Software requirements:
  + Python 2.7.9\$1 or 3.2\$1

## Install EC2Rescue
<a name="ec2rl-install"></a>

The `AWSSupport-TroubleshootSSH` runbook installs EC2Rescue for Linux and then uses the tool to check or attempt to fix common issues that prevent a remote connection to a Linux machine via SSH. For more information, and to run this automation, see [Support-TroubleshootSSH](https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-troubleshootssh.html).

If your system has the required Python version, you can install the standard build. Otherwise, you can install the bundled build, which includes a minimal copy of Python.

**To install the standard build**

1. From a working Linux instance, download the [EC2Rescue for Linux](https://s3.amazonaws.com/ec2rescuelinux/ec2rl.tgz) tool:

   ```
   curl -O https://s3.amazonaws.com/ec2rescuelinux/ec2rl.tgz
   ```

1. (*Optional*) Verify the signature of the EC2Rescue for Linux installation file. For more information, see [(Optional) Verify the signature of EC2Rescue for Linux](#ec2rl_verify).

1. Download the sha256 hash file:

   ```
   curl -O https://s3.amazonaws.com/ec2rescuelinux/ec2rl.tgz.sha256
   ```

1. Verify the integrity of the tarball:

   ```
   sha256sum -c ec2rl.tgz.sha256
   ```

1. Unpack the tarball:

   ```
   tar -xzvf ec2rl.tgz
   ```

1. Verify the installation by listing out the help file:

   ```
   cd ec2rl-<version_number>
   ./ec2rl help
   ```

**To install the bundled build**  
For a link to the download and a list of limitations, see [EC2Rescue for Linux](https://github.com/awslabs/aws-ec2rescue-linux/blob/master/README.md) on github.

## (Optional) Verify the signature of EC2Rescue for Linux
<a name="ec2rl_verify"></a>

The following is the recommended process of verifying the validity of the EC2Rescue for Linux package for Linux-based operating systems.

When you download an application from the internet, we recommend that you authenticate the identity of the software publisher and check that the application has not been altered or corrupted after it was published. This protects you from installing a version of the application that contains a virus or other malicious code.

If, after running the steps in this topic, you determine that the software for EC2Rescue for Linux is altered or corrupted, do not run the installation file. Instead, contact Amazon Web Services.

EC2Rescue for Linux files for Linux-based operating systems are signed using GnuPG, an open-source implementation of the Pretty Good Privacy (OpenPGP) standard for secure digital signatures. GnuPG (also known as GPG) provides authentication and integrity checking through a digital signature. AWS publishes a public key and signatures that you can use to verify the downloaded EC2Rescue for Linux package. For more information about PGP and GnuPG (GPG), see [https://www.gnupg.org/](https://www.gnupg.org/).

The first step is to establish trust with the software publisher. Download the public key of the software publisher, check that the owner of the public key is who they claim to be, and then add the public key to your keyring. Your keyring is a collection of known public keys. After you establish the authenticity of the public key, you can use it to verify the signature of the application.

**Topics**
+ [Authenticate and import the public key](#ec2rl_authenticate)
+ [Verify the signature of the package](#ec2rl_verify_signature)

### Authenticate and import the public key
<a name="ec2rl_authenticate"></a>

The next step in the process is to authenticate the EC2Rescue for Linux public key and add it as a trusted key in your GPG keyring.

**To authenticate and import the EC2Rescue for Linux public key**

1. At a command prompt, use the following command to obtain a copy of our public GPG build key:

   ```
   curl -O https://s3.amazonaws.com/ec2rescuelinux/ec2rl.key
   ```

1. At a command prompt in the directory where you saved `ec2rl.key`, use the following command to import the EC2Rescue for Linux public key into your keyring:

   ```
   gpg2 --import ec2rl.key
   ```

   The command returns results similar to the following:

   ```
   gpg: /home/ec2-user/.gnupg/trustdb.gpg: trustdb created
   gpg: key 2FAE2A1C: public key "ec2autodiag@amazon.com <EC2 Rescue for Linux>" imported
   gpg: Total number processed: 1
   gpg:               imported: 1  (RSA: 1)
   ```
**Tip**  
If you see an error stating that the command cannot be found, install the GnuPG utility with `apt-get install gnupg2` (Debian-based Linux) or `yum install gnupg2` (Red Hat- based Linux).

### Verify the signature of the package
<a name="ec2rl_verify_signature"></a>

After you've installed the GPG tools, authenticated and imported the EC2Rescue for Linux public key, and verified that the EC2Rescue for Linux public key is trusted, you are ready to verify the signature of the EC2Rescue for Linux installation script.

**To verify the EC2Rescue for Linux installation script signature**

1. At a command prompt, run the following command to download the signature file for the installation script:

   ```
   curl -O https://s3.amazonaws.com/ec2rescuelinux/ec2rl.tgz.sig
   ```

1. Verify the signature by running the following command at a command prompt in the directory where you saved `ec2rl.tgz.sig` and the EC2Rescue for Linux installation file. Both files must be present.

   ```
   gpg2 --verify ./ec2rl.tgz.sig
   ```

   The output should look something like the following:

   ```
   gpg: Signature made Thu 12 Jul 2018 01:57:51 AM UTC using RSA key ID 6991ED45
   gpg: Good signature from "ec2autodiag@amazon.com <EC2 Rescue for Linux>"
   gpg: WARNING: This key is not certified with a trusted signature!
   gpg:          There is no indication that the signature belongs to the owner.
   Primary key fingerprint: E528 BCC9 0DBF 5AFA 0F6C  C36A F780 4843 2FAE 2A1C
        Subkey fingerprint: 966B 0D27 85E9 AEEC 1146  7A9D 8851 1153 6991 ED45
   ```

   If the output contains the phrase `Good signature from "ec2autodiag@amazon.com <EC2 Rescue for Linux>"`, it means that the signature has successfully been verified, and you can proceed to run the EC2Rescue for Linux installation script.

   If the output includes the phrase `BAD signature`, check whether you performed the procedure correctly. If you continue to get this response, contact Amazon Web Services and do not run the installation file that you downloaded previously.

The following are details about the warnings that you might see:
+ **WARNING: This key is not certified with a trusted signature\$1 There is no indication that the signature belongs to the owner.** This refers to your personal level of trust in your belief that you possess an authentic public key for EC2Rescue for Linux. In an ideal world, you would visit an Amazon Web Services office and receive the key in person. However, more often you download it from a website. In this case, the website is an Amazon Web Services website.
+ **gpg2: no ultimately trusted keys found.** This means that the specific key is not "ultimately trusted" by you (or by other people whom you trust).

For more information, see [https://www.gnupg.org/](https://www.gnupg.org/).

# Run EC2Rescue commands on an Amazon EC2 Linux instance
<a name="ec2rl_working"></a>

EC2Rescue is a command line tool. After you have installed EC2Rescue on your Linux instance, you can get general help on how to use the tool by running `./ec2rl help`. You can view the available modules by running `./ec2rl list`, and you can get help on a specific module by running `./ec2rl help module_name`.

The following are common tasks you can perform to get started using this tool.

**Topics**
+ [Run EC2Rescue modules](#ec2rl_running_module)
+ [Upload the EC2Rescue module results](#ec2rl_uploading_results)
+ [Create backups of an Amazon EC2 Linux instance](#ec2rl_creating_backups)

## Run EC2Rescue modules
<a name="ec2rl_running_module"></a>

**To run all EC2Rescue modules**  
Use the **./ec2rl run** command without specifying any additional parameters. Some modules require root access. If you are not a root user, use **sudo** when you run the command.

```
./ec2rl run
```

**To run a specific EC2Rescue module**  
Use the **./ec2rl run** command and for `--only-modules`, specify the name of the module to run. Some modules require *arguments* to use them.

```
./ec2rl run --only-modules=module_name --arguments
```

For example, to run the **dig** module to query the `amazon.com` domain, use the following command.

```
./ec2rl run --only-modules=dig --domain=amazon.com
```

**To view the results of an EC2Rescue module**  
Run the module then view the log file in `cat /var/tmp/ec2rl/logfile_location`. For example, the log file for the **dig** module can be found in the following location:

```
cat /var/tmp/ec2rl/timestamp/mod_out/run/dig.log
```

## Upload the EC2Rescue module results
<a name="ec2rl_uploading_results"></a>

If Support has requested the results for a EC2Rescue module, you can upload the log file using the EC2Rescue tool. You can upload the results either to a location provided by Support or to an Amazon S3 bucket that you own.

**To upload results to a location provided by Support**  
Use the **./ec2rl upload** command. For `--upload-directory`, specify the location of the log file. For `--support-url`, specify the URL provided by Support.

```
./ec2rl upload --upload-directory=/var/tmp/ec2rl/logfile_location --support-url="url_provided_by_aws_support"
```

**To upload results to an Amazon S3 bucket**  
Use the **./ec2rl upload** command. For `--upload-directory`, specify the location of the log file. For `--presigned-url`, specify a presigned URL for the S3 bucket. For more information about generating pre-signed URLs for Amazon S3, see [Uploading Objects Using Pre-Signed URLs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html).

```
./ec2rl upload --upload-directory=/var/tmp/ec2rl/logfile_location --presigned-url="presigned_s3_url"
```

## Create backups of an Amazon EC2 Linux instance
<a name="ec2rl_creating_backups"></a>

You can use EC2Rescue to backup your Linux instance by creating an AMI or by creating snapshots of it's attached volumes.

**To create an AMI**  
Use the `./ec2rl run` command and for --`backup`, specify `ami`.

```
./ec2rl run --backup=ami
```

**To create multi-volume snapshots of all attached volumes**  
Use the `./ec2rl run` command and for --`backup`, specify `allvolumes`.

```
./ec2rl run --backup=allvolumes
```

**To create a snapshot of a specific attached volume**  
Use the `./ec2rl run` command and for --`backup`, specify the ID of the volume to back up.

```
./ec2rl run --backup=vol-01234567890abcdef
```

# Develop EC2Rescue modules for Amazon EC2 Linux instances
<a name="ec2rl_moduledev"></a>

Modules are written in YAML, a data serialization standard. A module's YAML file consists of a single document, representing the module and its attributes.

## Add module attributes
<a name="ec2rl-adding-modules"></a>

The following table lists the available module attributes.


| Attribute | Description | 
| --- | --- | 
| name | The name of the module. The name should be less than or equal to 18 characters in length. | 
| version | The version number of the module. | 
| title | A short, descriptive title for the module. This value should be less than or equal to 50 characters in length. | 
| helptext |  The extended description of the module. Each line should be less than or equal to 75 characters in length. If the module consumes arguments, required or optional, include them in the helptext value. For example: <pre>helptext: !!str |<br />  Collect output from ps for system analysis<br />  Consumes --times= for number of times to repeat<br />  Consumes --period= for time period between repetition</pre> | 
| placement | The stage in which the module should be run. Supported values: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html)  | 
| language | The language that the module code is written in. Supported values: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html)  Python code must be compatible with both Python 2.7.9\$1 and Python 3.2\$1.   | 
| remediation |  Indicates whether the module supports remediation. Supported values are `True` or `False`. The module defaults to `False` if this is absent, making it an optional attribute for those modules that do not support remediation.  | 
| content | The entirety of the script code. | 
| constraint | The name of the object containing the constraint values. | 
| domain | A descriptor of how the module is grouped or classified. The set of included modules uses the following domains:  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html) | 
| class | A descriptor of the type of task performed by the module. The set of included modules uses the following classes: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html) | 
| distro | The list of Linux distributions that this module supports. The set of included modules uses the following distributions: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html) | 
| required | The required arguments that the module is consuming from the CLI options. | 
| optional | The optional arguments that the module can use. | 
| software | The software executables used in the module. This attribute is intended to specify software that is not installed by default. The EC2Rescue for Linux logic ensures that these programs are present and executable before running the module. | 
| package | The source software package for an executable. This attribute is intended to provide extended details on the package with the software, including a URL for downloading or getting further information. | 
| sudo | Indicates whether root access is required to run the module.  You do not need to implement sudo checks in the module script. If the value is true, then the EC2Rescue for Linux logic only runs the module when the executing user has root access. | 
| perfimpact | Indicates whether the module can have significant performance impact upon the environment in which it is run. If the value is true and the `--perfimpact=true` argument is not present, then the module is skipped. | 
| parallelexclusive | Specifies a program that requires mutual exclusivity. For example, all modules specifying "bpf" run in a serial manner. | 

## Add environment variables
<a name="ec2rl_adding_envvars"></a>

The following table lists the available environment variables.


| Environment Variable | Description | 
| --- | --- | 
|  `EC2RL_CALLPATH`  | The path to ec2rl.py. This path can be used to locate the lib directory and use vendored Python modules. | 
|  `EC2RL_WORKDIR`  |  The main tmp directory for the diagnostic tool. Default value: `/var/tmp/ec2rl`. | 
|  `EC2RL_RUNDIR`  |  The directory where all output is stored. Default value: `/var/tmp/ec2rl/<date&timestamp>`.  | 
|  `EC2RL_GATHEREDDIR`  |  The root directory for placing gathered module data. Default value:`/var/tmp/ec2rl/<date&timestamp>/mod_out/gathered/`.  | 
|  `EC2RL_NET_DRIVER`  |  The driver in use for the first, alphabetically ordered, non-virtual network interface on the instance. Examples: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html)  | 
|  `EC2RL_SUDO`  |  True if EC2Rescue for Linux is running as root; otherwise, false.  | 
|  `EC2RL_VIRT_TYPE`  |  The virtualization type as provided by the instance metadata. Examples: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rl_moduledev.html)  | 
|  `EC2RL_INTERFACES`  |  An enumerated list of interfaces on the system. The value is a string containing names, such as `eth0`, `eth1`, etc. This is generated via the `functions.bash` and is only available for modules that have sourced it.  | 

## Use YAML syntax
<a name="ec2rl_yamlsyntax"></a>

The following should be noted when constructing your module YAML files:
+ The triple hyphen (`---`) denotes the explicit start of a document.
+ The `!ec2rlcore.module.Module` tag tells the YAML parser which constructor to call when creating the object from the data stream. You can find the constructor inside the `module.py` file.
+ The `!!str` tag tells the YAML parser to not attempt to determine the type of data, and instead interpret the content as a string literal.
+ The pipe character (`|`) tells the YAML parser that the value is a literal-style scalar. In this case, the parser includes all whitespace. This is important for modules because indentation and newline characters are kept.
+ The YAML standard indent is two spaces, which can be seen in the following examples. Ensure that you maintain standard indentation (for example, four spaces for Python) for your script and then indent the entire content two spaces inside the module file.

## Example modules
<a name="ec2rl_example"></a>

Example one (`mod.d/ps.yaml`):

```
--- !ec2rlcore.module.Module
# Module document. Translates directly into an almost-complete Module object
name: !!str ps
path: !!str
version: !!str 1.0
title: !!str Collect output from ps for system analysis
helptext: !!str |
  Collect output from ps for system analysis
  Requires --times= for number of times to repeat
  Requires --period= for time period between repetition
placement: !!str run
package: 
  - !!str
language: !!str bash
content: !!str |
  #!/bin/bash
  error_trap()
  {
      printf "%0.s=" {1..80}
      echo -e "\nERROR:	"$BASH_COMMAND" exited with an error on line ${BASH_LINENO[0]}"
      exit 0
  }
  trap error_trap ERR

  # read-in shared function
  source functions.bash
  echo "I will collect ps output from this $EC2RL_DISTRO box for $times times every $period seconds."
  for i in $(seq 1 $times); do
      ps auxww
      sleep $period
  done
constraint:
  requires_ec2: !!str False
  domain: !!str performance
  class: !!str collect
  distro: !!str alami ubuntu rhel suse
  required: !!str period times
  optional: !!str
  software: !!str
  sudo: !!str False
  perfimpact: !!str False
  parallelexclusive: !!str
```

# Troubleshoot impaired Amazon EC2 Windows instance using EC2Rescue
<a name="Windows-Server-EC2Rescue"></a>

EC2Rescue for Windows Server is an easy-to-use tool that you run on an Amazon EC2 Windows Server instance to diagnose and troubleshoot possible problems. It is valuable for collecting log files and troubleshooting issues and also proactively searching for possible areas of concern. It can even examine Amazon EBS root volumes from other instances and collect relevant logs for troubleshooting Windows Server instances using that volume. The following are some common issues that EC2Rescue can address:
+ Instance connectivity issues due to firewall, Remote Desktop Protocol (RDP), or network interface configuration
+ Operating system boot issues due to a stop error, boot loop, or corrupted registry
+ Issues that might need advanced log analysis and troubleshooting

EC2Rescue for Windows Server has two different modules:
+ A **data collector module** that collects data from all different sources
+ An **analyzer module** that parses the data collected against a series of predefined rules to identify issues and provide suggestions

The EC2Rescue for Windows Server tool only runs on Amazon EC2 instances running Windows Server 2012 and later. When the tool starts, it checks whether it is running on an Amazon EC2 instance.

**Note**  
The `AWSSupport-ExecuteEC2Rescue` AWS Systems Manager Automation runbook uses the EC2Rescue tool to troubleshoot and, where possible, fix common connectivity issues with the specified EC2 instance. For more information, and to run this automation, see [ >AWSSupport-ExecuteEC2Rescue](https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-executeec2rescue.html).

If you are using a Linux instance, see [Troubleshoot impaired Amazon EC2 Linux instance using EC2Rescue](Linux-Server-EC2Rescue.md).

**Topics**
+ [Troubleshoot using EC2Rescue GUI](ec2rw-gui.md)
+ [Troubleshoot using EC2Rescue CLI](ec2rw-cli.md)
+ [Troubleshoot using EC2Rescue and Systems Manager](ec2rw-ssm.md)

# Troubleshoot impaired Windows instance with the EC2Rescue GUI
<a name="ec2rw-gui"></a>

EC2Rescue for Windows Server can perform the following analysis on ** offline instances**:


| Option | Description | 
| --- | --- | 
| Diagnose and Rescue | EC2Rescue for Windows Server can detect and address issues with the following service settings: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) | 
| Restore | Perform one of the following actions: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-gui.html) | 
| Capture Logs | Allows you to capture logs on the instance for analysis. | 

EC2Rescue for Windows Server can collect the following data from **active and offline instances**:


| Item | Description | 
| --- | --- | 
| Event Log | Collects application, system, and EC2Config event logs. | 
| Registry | Collects SYSTEM and SOFTWARE hives. | 
| Windows Update Log | Collects log files generated by Windows Update. In Windows Server 2016 and later, the log is collected in Event Tracing for Windows (ETW) format. | 
| Sysprep Log | Collects log files generated by the Windows System Preparation tool. | 
| Driver Setup Log | Collects Windows SetupAPI logs (setupapi.dev.log and setupapi.setup.log). | 
| Boot Configuration | Collects HKEY\$1LOCAL\$1MACHINE\$1BCD00000000 hive. | 
| Memory Dump | Collects any memory dump files that exist on the instance. | 
| EC2Config File | Collects log files generated by the EC2Config service. | 
| EC2Launch File | Collects log files generated by the EC2Launch scripts. | 
| SSM Agent File | Collects log files generated by SSM Agent and Patch Manager logs. | 
| EC2 ElasticGPUs File | Collects event logs related to elastic GPUs. | 
| ECS | Collects logs related to Amazon ECS. | 
| CloudEndure | Collects log files related to CloudEndure Agent. | 
| AWS Replication Agent for MGN or DRS Log Files | Collects log files related to AWS Application Migration Service or AWS Elastic Disaster Recovery. | 

EC2Rescue for Windows Server can collect the following additional data from **active instances**:


| Item | Description | 
| --- | --- | 
| System Information | Collects MSInfo32. | 
| Group Policy Result | Collects a Group Policy report. | 

## Analyze an offline instance
<a name="ec2rescue-offline"></a>

The **Offline Instance** option is useful for debugging boot issues with Windows instances.

**To perform an action on an offline instance**

1. From a working Windows Server instance, download the [EC2Rescue for Windows Server](https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip?x-download-source=docs) tool and extract the files.

   You can run the following PowerShell command to download EC2Rescue without changing your Internet Explorer Enhanced Security Configuration (ESC):

   ```
   Invoke-WebRequest https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip -OutFile $env:USERPROFILE\Desktop\EC2Rescue_latest.zip
   ```

   This command will download the EC2Rescue .zip file to the desktop of the currently logged in user.
**Note**  
If you receive an error when downloading the file, and you are using Windows Server 2016 or earlier, TLS 1.2 might need to be enabled for your PowerShell terminal. You can enable TLS 1.2 for the current PowerShell session with the following command and then try again:  

   ```
   [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
   ```

1. Stop the faulty instance, if it is not stopped already.

1. Detach the EBS root volume from the faulty instance and attach the volume to a working Windows instance that has EC2Rescue for Windows Server installed.

1. Run the EC2Rescue for Windows Server tool on the working instance and choose **Offline Instance**.

1. Select the disk of the newly mounted volume and choose **Next**.

1. Confirm the disk selection and choose **Yes**.

1. Choose the offline instance option to perform and choose **Next**.

The EC2Rescue for Windows Server tool scans the volume and collects troubleshooting information based on the selected log files.

## Collect data from an active instance
<a name="ec2rescue-active"></a>

You can collect logs and other data from an active instance.

**To collect data from an active instance**

1. Connect to your Windows instance.

1. Download the [EC2Rescue for Windows Server](https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip?x-download-source=docs) tool to your Windows instance and extract the files.

   You can run the following PowerShell command to download EC2Rescue without changing your Internet Explorer Enhanced Security Configuration (ESC):

   ```
   Invoke-WebRequest https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip -OutFile $env:USERPROFILE\Desktop\EC2Rescue_latest.zip
   ```

   This command will download the EC2Rescue .zip file to the desktop of the currently logged in user.
**Note**  
If you receive an error when downloading the file, and you are using Windows Server 2016 or earlier, TLS 1.2 might need to be enabled for your PowerShell terminal. You can enable TLS 1.2 for the current PowerShell session with the following command and then try again:  

   ```
   [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
   ```

1. Open the EC2Rescue for Windows Server application and accept the license agreement.

1. Choose **Next**, **Current instance**, **Capture logs**.

1. Select the data items to collect and choose **Collect...**. Read the warning and choose **Yes** to continue.

1. Choose a file name and location for the ZIP file and choose **Save**.

1. After EC2Rescue for Windows Server completes, choose **Open Containing Folder** to view the ZIP file.

1. Choose **Finish**.

# Troubleshoot impaired Windows instance with the EC2Rescue CLI
<a name="ec2rw-cli"></a>

The EC2Rescue for Windows Server command line interface (CLI) allows you to run an EC2Rescue for Windows Server plugin (referred as an "action") programmatically.

The EC2Rescue for Windows Server tool has two execution modes:
+ **/online**—This allows you to take action on the instance that EC2Rescue for Windows Server is installed on, such as collect log files.
+ **/offline:<device\$1id>**—This allows you to take action on the offline root volume that is attached to a separate Amazon EC2 Windows instance, on which you have installed EC2Rescue for Windows Server.

Download the [EC2Rescue for Windows Server](https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip?x-download-source=docs) tool to your Windows instance and extract the files. You can view the help file using the following command:

```
EC2RescueCmd.exe /help
```

EC2Rescue for Windows Server can perform the following actions on an Amazon EC2 Windows instance:
+ [Collect action](#ec2rw-collect)
+ [Rescue action](#ec2rw-rescue)
+ [Restore action](#ec2rw-restore)

## Collect action
<a name="ec2rw-collect"></a>

**Note**  
You can collect all logs, an entire log group, or an individual log within a group.

EC2Rescue for Windows Server can collect the following data from **active and offline instances**.


| Log group | Available logs | Description | 
| --- | --- | --- | 
| all |  | Collects all available logs. | 
| eventlog |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects application, system, and EC2Config event logs. | 
| memory-dump |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects any memory dump files that exist on the instance. | 
| ec2config |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects log files generated by the EC2Config service. | 
| ec2launch |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects log files generated by the EC2Launch scripts. | 
| ssm-agent |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects log files generated by SSM Agent and Patch Manager logs. | 
| sysprep | 'Log Files' | Collects log files generated by the Windows System Preparation tool. | 
| driver-setup |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects Windows SetupAPI logs (setupapi.dev.log and setupapi.setup.log). | 
| registry |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects SYSTEM and SOFTWARE hives. | 
| egpu |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects event logs related to elastic GPUs. | 
| boot-config | 'BCDEDIT Output' | Collects HKEY\$1LOCAL\$1MACHINE\$1BCD00000000 hive. | 
| windows-update | 'Log Files' | Collects log files generated by Windows Update. In Windows Server 2016 and later, the log is collected in Event Tracing for Windows (ETW) format. | 
| cloudendure |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | Collects log files related to CloudEndure Agent. | 

EC2Rescue for Windows Server can collect the following additional data from **active instances**.


| Log group | Available logs | Description | 
| --- | --- | --- | 
| system-info | 'MSInfo32 Output' | Collects MSInfo32. | 
| gpresult | 'GPResult Output' |  Collects a Group Policy report.  | 

The following are the available options:
+ **/output:<outputFilePath>** ‐ Required destination file path location to save collected log files in zip format.
+ **/no-offline** ‐ Optional attribute used in offline mode. Does not set the volume offline after completing the action.
+ **/no-fix-signature** ‐ Optional attribute used in offline mode. Does not fix a possible disk signature collision after completing the action.

### Examples
<a name="ec2rw-collect-examples"></a>

The following are examples using the EC2Rescue for Windows Server CLI.

#### Online mode examples
<a name="ec2rw-collect-examples-online"></a>

Collect all available logs:

```
EC2RescueCmd /accepteula /online /collect:all /output:<outputFilePath>
```

Collect only a specific log group:

```
EC2RescueCmd /accepteula /online /collect:ec2config /output:<outputFilePath>
```

Collect individual logs within a log group:

```
EC2RescueCmd /accepteula /online /collect:'ec2config.Log Files,driver-setup.SetupAPI Log Files' /output:<outputFilePath>
```

#### Offline mode examples
<a name="ec2rw-collect-examples-offline"></a>

Collect all available logs from an EBS volume. The volume is specified by the device\$1id value.

```
EC2RescueCmd /accepteula /offline:xvdf /collect:all /output:<outputFilePath>
```

Collect only a specific log group:

```
EC2RescueCmd /accepteula /offline:xvdf /collect:ec2config /output:<outputFilePath>
```

## Rescue action
<a name="ec2rw-rescue"></a>

EC2Rescue for Windows Server can detect and address issues with the following service settings:


|  Service group  | Available actions |  Description  | 
| --- | --- | --- | 
| all |  |  | 
| system-time | 'RealTimeIsUniversal' | System Time[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html) | 
| firewall |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  |  Windows Firewall [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | 
| rdp |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  |  Remote Desktop [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | 
| ec2config |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  |  EC2Config [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | 
| ec2launch | 'Reset Administrator Password' | Generates a new Windows administrator password. | 
| network | 'DHCP Service Startup' |  Network Interface [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2rw-cli.html)  | 

The following are the available options:
+ **/level:<level>** ‐ Optional attribute for the check level that the action should trigger. Allowed values are: `information`, `warning`, `error`, `all`. By default, it is set to `error`.
+ **/check-only** ‐ Optional attribute that generates a report but makes no modifications to the offline volume.
**Note**  
If EC2Rescue for Windows Server detects a possible disk signature collision, it corrects the signature after the offline process completes by default, even when you use the `/check-only` option. You must use the `/no-fix-signature` option to prevent the correction.
+ **/no-offline** ‐ Optional attribute that prevents the volume from being set offline after completing the action.
+ **/no-fix-signature** ‐ Optional attribute that does not fix a possible disk signature collision after completing the action.

### Rescue examples
<a name="ec2rw-rescue-examples"></a>

The following are examples using the EC2Rescue for Windows Server CLI. The volume is specified using the device\$1id value.

Attempt to fix all identified issues on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /rescue:all
```

Attempt to fix all issues within a service group on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /rescue:firewall
```

Attempt to fix a specific item within a service group on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /rescue:rdp.'Service Start'
```

Specify multiple issues to attempt to fix on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /rescue:'system-time.RealTimeIsUniversal,ec2config.Service Start'
```

## Restore action
<a name="ec2rw-restore"></a>

EC2Rescue for Windows Server can detect and address issues with the following service settings:


|  Service Group  | Available Actions |  Description  | 
| --- | --- | --- | 
|  Restore Last Known Good Configuration  | lkgc | Last Known Good Configuration ‐ Attempts to boot the instance into the last known bootable state. | 
| Restore Windows registry from latest backup | regback | Restore registry from backup ‐ Restores the registry from \$1Windows\$1System32\$1config\$1RegBack. | 

The following are the available options:
+ **/no-offline**—Optional attribute that prevents the volume from being set offline after completing the action.
+ **/no-fix-signature**—Optional attribute that does not fix a possible disk signature collision after completing the action.

### Restore examples
<a name="ec2rw-restore-examples"></a>

The following are examples using the EC2Rescue for Windows Server CLI. The volume is specified using the device\$1id value.

Restore last known good configuration on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /restore:lkgc
```

Restore the last Windows registry backup on a volume:

```
EC2RescueCmd /accepteula /offline:xvdf /restore:regback
```

# Troubleshoot impaired Windows instance with EC2Rescue and Systems Manager
<a name="ec2rw-ssm"></a>

Support provides you with a Systems Manager Run Command document to interface with your Systems Manager-enabled instance to run EC2Rescue for Windows Server. The Run Command document is called `AWSSupport-RunEC2RescueForWindowsTool`.

This Systems Manager Run Command document performs the following tasks:
+ Downloads and verifies EC2Rescue for Windows Server.
+ Imports a PowerShell module to ease your interaction with the tool.
+ Runs EC2RescueCmd with the provided command and parameters.

The Systems Manager Run Command document accepts three parameters:
+ **Command**—The EC2Rescue for Windows Server action. The current allowed values are:
  + **ResetAccess**—Resets the local Administrator password. The local Administrator password of the current instance will be reset and the randomly generated password will be securely stored in Parameter Store as `/EC2Rescue/Password/<INSTANCE_ID>`. If you select this action and provide no parameters, passwords are encrypted automatically with the default KMS key. Optionally, you can specify a KMS key ID in Parameters to encrypt the password with your own key.
  + **CollectLogs**—Runs EC2Rescue for Windows Server with the `/collect:all` action. If you select this action, `Parameters` must include an Amazon S3 bucket name to upload the logs to.
  + **FixAll**—Runs EC2Rescue for Windows Server with the `/rescue:all` action. If you select this action, `Parameters` must include the block device name to rescue.
+ **Parameters**—The PowerShell parameters to pass for the specified command.

## Requirements
<a name="ec2rw-requirements"></a>

To run the **ResetAccess** action, your Amazon EC2 instance must have the a policy attached that grants permissions to write the encrypted password to Parameter Store. After attaching the policy, wait a few minutes before attempting to reset the password of an instance after you have attached this policy to the related IAM role.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:PutParameter"
      ],
      "Resource": [
        "arn:aws:ssm:us-east-1:111122223333:parameter/EC2Rescue/Passwords/<instanceid>"
      ]
    }
  ]
}
```

------

If you are using a custom KMS key, not the default KMS key, use this policy instead.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:PutParameter"
      ],
      "Resource": [
        "arn:aws:ssm:us-east-1:111122223333:parameter/EC2Rescue/Passwords/<instanceid>"
      ] 
    }, 
    { 
      "Effect": "Allow",
      "Action": [
        "kms:Encrypt"
      ],
      "Resource": [
        "arn:aws:kms:us-east-1:111122223333:key/<kmskeyid>"
      ]
    }
  ]
}
```

------

## View the JSON for the document
<a name="ec2rw-view-json"></a>

The following procedure describes how to view the JSON for this document.

**To view the JSON for the Systems Manager Run Command document**

1. Open the AWS Systems Manager console at [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/).

1. In the navigation pane, expand **Change Management Tools** and choose **Documents**.

1. In the search bar, enter `AWSSupport-RunEC2RescueForWindowsTool`, and then select the `AWSSupport-RunEC2RescueForWindowsTool` document.

1. Choose the **Content** tab.

## Examples
<a name="ec2rw-ssm-examples"></a>

Here are some examples on how to use the Systems Manager Run Command document to run EC2Rescue for Windows Server, using the AWS CLI. For more information about sending commands using the AWS CLI, see [send-command](https://docs.aws.amazon.com/cli/latest/reference/ssm/send-command.html).

**Topics**
+ [Attempt to fix all identified issues on an offline root volume](#ec2rw-ssm-exam1)
+ [Collect logs from the current Amazon EC2 Windows instance](#ec2rw-ssm-exam2)
+ [Reset the local Administrator password](#ec2rw-ssm-exam4)

### Attempt to fix all identified issues on an offline root volume
<a name="ec2rw-ssm-exam1"></a>

Attempt to fix all identified issues on an offline root volume attached to an Amazon EC2 Windows instance:

```
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --parameters "Command=FixAll, Parameters='xvdf'" --output text
```

### Collect logs from the current Amazon EC2 Windows instance
<a name="ec2rw-ssm-exam2"></a>

Collect all logs from the current online Amazon EC2 Windows instance and upload them to an Amazon S3 bucket:

```
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --parameters "Command=CollectLogs, Parameters='amzn-s3-demo-bucket'" --output text
```

### Reset the local Administrator password
<a name="ec2rw-ssm-exam4"></a>

The following examples show methods you can use to reset the local Administrator password. The output provides a link to Parameter Store, where you can find the randomly generated secure password you can then use to RDP to your Amazon EC2 Windows instance as the local Administrator.

Reset the local Administrator password of an online instance using the default AWS KMS key alias/aws/ssm:

```
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --parameters "Command=ResetAccess" --output text
```

Reset the local Administrator password of an online instance using a KMS key:

```
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --parameters "Command=ResetAccess, Parameters=a133dc3c-a2g4-4fc6-a873-6c0720104bf0" --output text
```

**Note**  
In this example, the KMS key is `a133dc3c-a2g4-4fc6-a873-6c0720104bf0`.

# EC2 Serial Console for instances
<a name="ec2-serial-console"></a>

With the EC2 serial console, you have access to your Amazon EC2 instance's serial port, which you can use to troubleshoot boot, network configuration, and other issues. The serial console does not require your instance to have any networking capabilities. With the serial console, you can enter commands to an instance as if your keyboard and monitor are directly attached to the instance's serial port. The serial console session lasts during instance reboot and stop. During reboot, you can view all of the boot messages from the start.

Access to the serial console is not available by default. Your organization must grant account access to the serial console and configure IAM policies to grant your users access to the serial console. Serial console access can be controlled at a granular level by using instance IDs, resource tags, and other IAM levers. For more information, see [Configure access to the EC2 Serial Console](configure-access-to-serial-console.md).

The serial console can be accessed by using the EC2 console or the AWS CLI.

The serial console is available at no additional cost.

**Topics**
+ [Prerequisites for the EC2 Serial Console](ec2-serial-console-prerequisites.md)
+ [Configure access to the EC2 Serial Console](configure-access-to-serial-console.md)
+ [Connect to the EC2 Serial Console](connect-to-serial-console.md)
+ [Disconnect from the EC2 Serial Console](disconnect-serial-console-session.md)
+ [Troubleshoot your Amazon EC2 instance using the EC2 Serial Console](troubleshoot-using-serial-console.md)

# Prerequisites for the EC2 Serial Console
<a name="ec2-serial-console-prerequisites"></a>

**Topics**
+ [AWS Regions](#sc-prereqs-regions)
+ [Wavelength Zones and AWS Outposts](#sc-prereqs-wavelength-zones-outposts)
+ [Local Zones](#sc-prereqs-local-zones)
+ [Instance types](#sc-prereqs-instance-types)
+ [Grant access](#sc-prereqs-configure-ec2-serial-console)
+ [Support for browser-based client](#sc-prereqs-for-browser-based-connection)
+ [Instance state](#sc-prereqs-instance-state)
+ [Amazon EC2 Systems Manager](#sc-prereqs-ssm)
+ [Configure your chosen troubleshooting tool](#sc-prereqs-configure-troubleshooting-tool)

## AWS Regions
<a name="sc-prereqs-regions"></a>

Supported in all AWS Regions.

## Wavelength Zones and AWS Outposts
<a name="sc-prereqs-wavelength-zones-outposts"></a>

Not supported.

## Local Zones
<a name="sc-prereqs-local-zones"></a>

Supported in all Local Zones.

## Instance types
<a name="sc-prereqs-instance-types"></a>

Supported instance types:
+ **Linux**
  + All virtualized instances built on the Nitro System.
  + All bare metal instances except:
    + General purpose: `a1.metal`, `mac1.metal`, `mac2.metal`
    + Accelerated computing: `g5g.metal`
    + Memory optimized: `u-6tb1.metal`, `u-9tb1.metal`, `u-12tb1.metal`, `u-18tb1.metal`, `u-24tb1.metal`
+ **Windows**

  All virtualized instances built on the Nitro System. Not supported on bare metal instances.

## Grant access
<a name="sc-prereqs-configure-ec2-serial-console"></a>

You must complete the configuration tasks to grant access to the EC2 Serial Console. For more information, see [Configure access to the EC2 Serial Console](configure-access-to-serial-console.md).

## Support for browser-based client
<a name="sc-prereqs-for-browser-based-connection"></a>

To connect to the serial console [using the browser-based client](connect-to-serial-console.md#sc-connect-browser-based-client), your browser must support WebSocket. If your browser does not support WebSocket, connect to the serial console [using your own key and an SSH client.](connect-to-serial-console.md#sc-connect-SSH)

## Instance state
<a name="sc-prereqs-instance-state"></a>

Must be `running`.

You can't connect to the serial console if the instance is in the `pending`, `stopping`, `stopped`, `shutting-down`, or `terminated` state.

For more information about the instance states, see [Amazon EC2 instance state changes](ec2-instance-lifecycle.md).

## Amazon EC2 Systems Manager
<a name="sc-prereqs-ssm"></a>

If the instance uses Amazon EC2 Systems Manager, then SSM Agent version 3.0.854.0 or later must be installed on the instance. For information about SSM Agent, see [Working with SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html) in the *AWS Systems Manager User Guide*.

## Configure your chosen troubleshooting tool
<a name="sc-prereqs-configure-troubleshooting-tool"></a>

To troubleshoot your instance using the serial console, you can use GRUB or SysRq on Linux instances, and Special Admin Console (SAC) on Windows instances. Before you can use these tools, you must first perform configuration steps on every instance on which you'll use them.

Use the instructions for your instance's operating system to configure your chosen troubleshooting tool.

### (Linux instances) Configure GRUB
<a name="configure-grub"></a>

To configure GRUB, choose one of the following procedures based on the AMI that was used to launch the instance.

------
#### [ Amazon Linux 2 ]

**To configure GRUB on an Amazon Linux 2 instance**

1. [Connect to your Linux instance using SSH](connect-to-linux-instance.md)

1. Add or change the following options in `/etc/default/grub`:
   + Set `GRUB_TIMEOUT=1`.
   + Add `GRUB_TERMINAL="console serial"`.
   + Add `GRUB_SERIAL_COMMAND="serial --speed=115200"`.

   The following is an example of `/etc/default/grub`. You might need to change the configuration based on your system setup.

   ```
   GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.shell=0"
   GRUB_TIMEOUT=1
   GRUB_DISABLE_RECOVERY="true"
   GRUB_TERMINAL="console serial"
   GRUB_SERIAL_COMMAND="serial --speed=115200"
   ```

1. Apply the updated configuration by running the following command.

   ```
   [ec2-user ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
   ```

------
#### [ Ubuntu ]

**To configure GRUB on an Ubuntu instance**

1. [Connect](connect-to-linux-instance.md) to your instance.

1. Add or change the following options in `/etc/default/grub.d/50-cloudimg-settings.cfg`:
   + Set `GRUB_TIMEOUT=1`.
   + Add `GRUB_TIMEOUT_STYLE=menu`.
   + Add `GRUB_TERMINAL="console serial"`.
   + Remove `GRUB_HIDDEN_TIMEOUT`.
   + Add `GRUB_SERIAL_COMMAND="serial --speed=115200"`.

   The following is an example of `/etc/default/grub.d/50-cloudimg-settings.cfg`. You might need to change the configuration based on your system setup.

   ```
   # Cloud Image specific Grub settings for Generic Cloud Images
   # CLOUD_IMG: This file was created/modified by the Cloud Image build process
   
   # Set the recordfail timeout
   GRUB_RECORDFAIL_TIMEOUT=0
   
   # Do not wait on grub prompt
   GRUB_TIMEOUT=1
   GRUB_TIMEOUT_STYLE=menu
   
   # Set the default commandline
   GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 nvme_core.io_timeout=4294967295"
   
   # Set the grub console type
   GRUB_TERMINAL="console serial"
   GRUB_SERIAL_COMMAND="serial --speed 115200"
   ```

1. Apply the updated configuration by running the following command.

   ```
   [ec2-user ~]$ sudo update-grub
   ```

------
#### [ RHEL ]

**To configure GRUB on a RHEL instance**

1. [Connect](connect-to-linux-instance.md) to your instance.

1. Add or change the following options in `/etc/default/grub`:
   + Remove `GRUB_TERMINAL_OUTPUT`.
   + Add `GRUB_TERMINAL="console serial"`.
   + Add `GRUB_SERIAL_COMMAND="serial --speed=115200"`.

   The following is an example of `/etc/default/grub`. You might need to change the configuration based on your system setup.

   ```
   GRUB_TIMEOUT=1
   GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
   GRUB_DEFAULT=saved
   GRUB_DISABLE_SUBMENU=true
   GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8 net.ifnames=0 rd.blacklist=nouveau nvme_core.io_timeout=4294967295 crashkernel=auto"
   GRUB_DISABLE_RECOVERY="true"
   GRUB_ENABLE_BLSCFG=true
   GRUB_TERMINAL="console serial"
   GRUB_SERIAL_COMMAND="serial --speed=115200"
   ```

1. Apply the updated configuration by running the following command.

   ```
   [ec2-user ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline
   ```

   For RHEL 9.2 and earlier, use the following command.

   ```
   [ec2-user ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
   ```

------
#### [ CentOS ]

For instances that are launched using a CentOS AMI, GRUB is configured for the serial console by default.

The following is an example of `/etc/default/grub`. Your configuration might be different based on your system setup.

```
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"
```

------

### (Linux instances) Configure SysRq
<a name="configure-sysrq"></a>

To configure SysRq, you enable the SysRq commands for the current boot cycle. To make the configuration persistent, you can also enable the SysRq commands for subsequent boots.

**To enable all SysRq commands for the current boot cycle**

1. [Connect](connect-to-linux-instance.md) to your instance.

1. Run the following command.

   ```
   [ec2-user ~]$ sudo sysctl -w kernel.sysrq=1
   ```

   This setting will clear on the next reboot.

**To enable all SysRq commands for subsequent boots**

1. Create the file `/etc/sysctl.d/99-sysrq.conf` and open it in your favorite editor.

   ```
   [ec2-user ~]$ sudo vi /etc/sysctl.d/99-sysrq.conf
   ```

1. Add the following line.

   ```
   kernel.sysrq=1
   ```

1. Reboot the instance to apply the changes.

   ```
   [ec2-user ~]$ sudo reboot
   ```

1. At the `login` prompt, enter the username of the password-based user that you [set up previously](configure-access-to-serial-console.md#set-user-password), and then press **Enter**.

1. At the `Password` prompt, enter the password, and then press **Enter**.

### (Windows instances) Enable SAC and the boot menu
<a name="configure-sac-bootmenu"></a>

**Note**  
If you enable SAC on an instance, the EC2 services that rely on password retrieval will not work from the Amazon EC2 console. Windows on Amazon EC2 launch agents (EC2Config, EC2Launch v1, and EC2Launch v2) rely on the serial console to execute various tasks. These tasks do not perform successfully when you enable SAC on an instance. For more information about Windows on Amazon EC2 launch agents, see [Configure your Amazon EC2 Windows instance](ec2-windows-instances.md). If you enable SAC, you can disable it later. For more information, see [Disable SAC and the boot menu](troubleshoot-using-serial-console.md#disable-sac-bootmenu).

Use one of the following methods to enable SAC and the boot menu on an instance.

------
#### [ PowerShell ]

**To enable SAC and the boot menu on a Windows instance**

1. [Connect](connecting_to_windows_instance.md) to your instance and perform the following steps from an elevated PowerShell command line.

1. Enable SAC.

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

1. Enable the boot menu.

   ```
   bcdedit /set '{bootmgr}' displaybootmenu yes
   bcdedit /set '{bootmgr}' timeout 15
   bcdedit /set '{bootmgr}' bootems yes
   ```

1. Apply the updated configuration by rebooting the instance.

   ```
   shutdown -r -t 0
   ```

------
#### [ Command prompt ]

**To enable SAC and the boot menu on a Windows instance**

1. [Connect](connecting_to_windows_instance.md) to your instance and perform the following steps from the command prompt.

1. Enable SAC.

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

1. Enable the boot menu.

   ```
   bcdedit /set {bootmgr} displaybootmenu yes
   bcdedit /set {bootmgr} timeout 15
   bcdedit /set {bootmgr} bootems yes
   ```

1. Apply the updated configuration by rebooting the instance.

   ```
   shutdown -r -t 0
   ```

------

# Configure access to the EC2 Serial Console
<a name="configure-access-to-serial-console"></a>

To configure access to the serial console, you must grant serial console access at the account level and then configure IAM policies to grant access to your users. For Linux instances you must also configure a password-based user on every instance so that your users can use the serial console for troubleshooting.

EC2 Serial Console uses a virtual serial port connection to interact with an instance. This connection is independent of the instance VPC, so that you can work with the instance operating system and run troubleshooting tools even if there are boot failures or network configuration issues. Because this connection is outside of the VPC network, EC2 Serial Console does not use the instance security group or the subnet network ACL to authorize traffic to the instance.

**Before you begin**  
Verify that the [prerequisites](ec2-serial-console-prerequisites.md) are met.

**Topics**
+ [Levels of access to the EC2 Serial Console](#serial-console-access-levels)
+ [Manage account access to the EC2 Serial Console](#serial-console-account-access)
+ [Configure IAM policies for EC2 Serial Console access](#serial-console-iam)
+ [Set an OS user password on a Linux instance](#set-user-password)

## Levels of access to the EC2 Serial Console
<a name="serial-console-access-levels"></a>

By default, there is no access to the serial console at the account level. You need to explicitly grant access to the serial console at the account level. For more information, see [Manage account access to the EC2 Serial Console](#serial-console-account-access).

You can use a service control policy (SCP) to allow access to the serial console within your organization. You can then have granular access control at the user level by using an IAM policy to control access. By using a combination of SCP and IAM policies, you have different levels of access control to the serial console.

**Organization level**  
You can use a service control policy (SCP) to allow access to the serial console for member accounts within your organization. For more information about SCPs, see [Service control policies](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html) in the *AWS Organizations User Guide*.

**Instance level**  
You can configure the serial console access policies by using IAM PrincipalTag and ResourceTag constructions and by specifying instances by their ID. For more information, see [Configure IAM policies for EC2 Serial Console access](#serial-console-iam).

**User level**  
You can configure access at the user level by configuring an IAM policy to allow or deny a specified user the permission to push the SSH public key to the serial console service of a particular instance. For more information, see [Configure IAM policies for EC2 Serial Console access](#serial-console-iam).

**OS level** (Linux instances only)  
You can set a user password at the guest OS level. This provides access to the serial console for some use cases. However, to monitor the logs, you don't need a password-based user. For more information, see [Set an OS user password on a Linux instance](#set-user-password).

## Manage account access to the EC2 Serial Console
<a name="serial-console-account-access"></a>

By default, there is no access to the serial console at the account level. You need to explicitly grant access to the serial console at the account level.

This setting is configured at the account level, either directly in the account or by using a declarative policy. It must be configured in each AWS Region where you want to grant access to the serial console. Using a declarative policy allows you to apply the setting across multiple Regions simultaneously, as well as across multiple accounts simultaneously. When a declarative policy is in use, you can't modify the setting directly within an account. This topic describes how to configure the setting directly within an account. For information about using declarative policies, see [Declarative policies](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_declarative.html) in the *AWS Organizations User Guide.*

**Contents**
+ [Grant permission to users to manage account access](#sc-account-access-permissions)
+ [View account access status to the serial console](#sc-view-account-access)
+ [Grant account access to the serial console](#sc-grant-account-access)
+ [Deny account access to the serial console](#sc-deny-account-access)

### Grant permission to users to manage account access
<a name="sc-account-access-permissions"></a>

To allow your users to manage account access to the EC2 serial console, you need to grant them the required IAM permissions.

The following policy grants permissions to view the account status, and to allow and prevent account access to the EC2 serial console.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:GetSerialConsoleAccessStatus",
                "ec2:EnableSerialConsoleAccess",
                "ec2:DisableSerialConsoleAccess"
            ],
            "Resource": "*"
        }
    ]
}
```

------

For more information, see [Creating IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) in the *IAM User Guide*.

### View account access status to the serial console
<a name="sc-view-account-access"></a>

------
#### [ Console ]

**To view account access to the serial console**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Dashboard**.

1. On the **Account attributes** card, under **Settings**, choose **EC2 Serial Console**.

1. On the **EC2 Serial Console** tab, the value of **EC2 Serial Console access** is either **Allowed** or **Prevented**.

------
#### [ AWS CLI ]

**To view account access to the serial console**  
Use the [get-serial-console-access-status](https://docs.aws.amazon.com/cli/latest/reference/ec2/get-serial-console-access-status.html) command.

```
aws ec2 get-serial-console-access-status
```

The following is example output. A value of `true` indicates that the account is allowed access to the serial console.

```
{
    "SerialConsoleAccessEnabled": true,
    "ManagedBy": "account"
}
```

The `ManagedBy` field indicates the entity that configured the setting. The possible values are `account` (configured directly) or `declarative-policy`. For more information, see [Declarative policies](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_declarative.html) in the *AWS Organizations User Guide*.

------
#### [ PowerShell ]

**To view account access to the serial console**  
Use the [Get-EC2SerialConsoleAccessStatus](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2SerialConsoleAccessStatus.html) cmdlet.

```
Get-EC2SerialConsoleAccessStatus -Select *
```

The following is example output. A value of `True` indicates that the account is allowed access to the serial console.

```
ManagedBy SerialConsoleAccessEnabled
--------- --------------------------
account   True
```

The `ManagedBy` field indicates the entity that configured the setting. The possible values are `account` (configured directly) or `declarative-policy`. For more information, see [Declarative policies](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_declarative.html) in the *AWS Organizations User Guide*.

------

### Grant account access to the serial console
<a name="sc-grant-account-access"></a>

------
#### [ Console ]

**To grant account access to the serial console**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Dashboard**.

1. On the **Account attributes** card, under **Settings**, choose **EC2 Serial Console**.

1. Choose **Manage**.

1. To allow access to the EC2 serial console of all instances in the account, select the **Allow** checkbox.

1. Choose **Update**.

------
#### [ AWS CLI ]

**To grant account access to the serial console**  
Use the [enable-serial-console-access](https://docs.aws.amazon.com/cli/latest/reference/ec2/enable-serial-console-access.html) command.

```
aws ec2 enable-serial-console-access
```

The following is example output.

```
{
    "SerialConsoleAccessEnabled": true
}
```

------
#### [ PowerShell ]

**To grant account access to the serial console**  
Use the [Enable-EC2SerialConsoleAccess](https://docs.aws.amazon.com/powershell/latest/reference/items/Enable-EC2SerialConsoleAccess.html) cmdlet.

```
Enable-EC2SerialConsoleAccess
```

The following is example output.

```
True
```

------

### Deny account access to the serial console
<a name="sc-deny-account-access"></a>

------
#### [ Console ]

**To deny account access to the serial console**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Dashboard**.

1. On the **Account attributes** card, under **Settings**, choose **EC2 Serial Console**.

1. Choose **Manage**.

1. To prevent access to the EC2 serial console of all instances in the account, clear the **Allow** checkbox.

1. Choose **Update**.

------
#### [ AWS CLI ]

**To deny account access to the serial console**  
Use the [disable-serial-console-access](https://docs.aws.amazon.com/cli/latest/reference/ec2/disable-serial-console-access.html) command.

```
aws ec2 disable-serial-console-access
```

The following is example output.

```
{
    "SerialConsoleAccessEnabled": false
}
```

------
#### [ PowerShell ]

**To deny account access to the serial console**  
Use the [Disable-EC2SerialConsoleAccess](https://docs.aws.amazon.com/powershell/latest/reference/items/Disable-EC2SerialConsoleAccess.html) cmdlet.

```
Disable-EC2SerialConsoleAccess
```

The following is example output.

```
False
```

------

## Configure IAM policies for EC2 Serial Console access
<a name="serial-console-iam"></a>

By default, your users do not have access to the serial console. Your organization must configure IAM policies to grant your users the required access. For more information, see [Creating IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) in the *IAM User Guide*.

For serial console access, create a JSON policy document that includes the `ec2-instance-connect:SendSerialConsoleSSHPublicKey` action. This action grants a user permission to push the public key to the serial console service, which starts a serial console session. We recommend restricting access to specific EC2 instances. Otherwise, all users with this permission can connect to the serial console of all EC2 instances.

**Topics**
+ [Explicitly allow access to the serial console](#iam-explicitly-allow-access)
+ [Explicitly deny access to the serial console](#serial-console-IAM-policy)
+ [Use resource tags to control access to the serial console](#iam-resource-tags)

### Explicitly allow access to the serial console
<a name="iam-explicitly-allow-access"></a>

By default, no one has access to the serial console. To grant access to the serial console, you need to configure a policy to explicitly allow access. We recommend configuring a policy that restricts access to specific instances.

The following policy allows access to the serial console of a specific instance, identified by its instance ID.

Note that the `DescribeInstances`, `DescribeInstanceTypes`, and `GetSerialConsoleAccessStatus` actions do not support resource-level permissions, and therefore all resources, indicated by the `*` (asterisk), must be specified for these actions.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowDescribeInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceTypes",
                "ec2:GetSerialConsoleAccessStatus"
            ],
             "Resource": "*"
        },
        {
            "Sid": "AllowinstanceBasedSerialConsoleAccess",
            "Effect": "Allow",
            "Action": [
                "ec2-instance-connect:SendSerialConsoleSSHPublicKey"
            ],
            "Resource": "arn:aws:ec2:us-east-1:111122223333:instance/i-0598c7d356eba48d7"
        }
    ]
}
```

------

### Explicitly deny access to the serial console
<a name="serial-console-IAM-policy"></a>

The following IAM policy allows access to the serial console of all instances, denoted by the `*` (asterisk), and explicitly denies access to the serial console of a specific instance, identified by its ID.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowSerialConsoleAccess",
            "Effect": "Allow",
            "Action": [
                "ec2-instance-connect:SendSerialConsoleSSHPublicKey",
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceTypes",
                "ec2:GetSerialConsoleAccessStatus"
            ],
            "Resource": "*"
        },
        {
            "Sid": "DenySerialConsoleAccess",
            "Effect": "Deny",
            "Action": [
                "ec2-instance-connect:SendSerialConsoleSSHPublicKey"
            ],
            "Resource": "arn:aws:ec2:us-east-1:111122223333:instance/i-0598c7d356eba48d7"
        }
    ]
}
```

------

### Use resource tags to control access to the serial console
<a name="iam-resource-tags"></a>

You can use resource tags to control access to the serial console of an instance.

Attribute-based access control is an authorization strategy that defines permissions based on tags that can be attached to users and AWS resources. For example, the following policy allows a user to initiate a serial console connection for an instance only if that instance's resource tag and the principal's tag have the same `SerialConsole` value for the tag key.

For more information about using tags to control access to your AWS resources, see [Controlling access to AWS resources](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html#access_tags_control-resources) in the *IAM User Guide*.

Note that the `DescribeInstances`, `DescribeInstanceTypes`, and `GetSerialConsoleAccessStatus` actions do not support resource-level permissions, and therefore all resources, indicated by the `*` (asterisk), must be specified for these actions.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowDescribeInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeInstanceTypes",
                "ec2:GetSerialConsoleAccessStatus"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowTagBasedSerialConsoleAccess",
            "Effect": "Allow",
            "Action": [
                "ec2-instance-connect:SendSerialConsoleSSHPublicKey"
            ],
            "Resource": "arn:aws:ec2:us-east-1:111122223333:instance/*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/SerialConsole": "${aws:PrincipalTag/SerialConsole}"
                }
            }
        }
    ]
}
```

------

## Set an OS user password on a Linux instance
<a name="set-user-password"></a>

You can connect to the serial console without a password. However, to *use* the serial console for troubleshooting a Linux instance, the instance must have a password-based OS user.

You can set the password for any OS user, including the root user. Note that the root user can modify all files, while each OS user might have limited permissions.

You must set a user password for every instance for which you will use the serial console. This is a one-time requirement for each instance.

**Note**  
By default, AMIs provided by AWS are not configured with a password-based user. If you launched your instance using an AMI that already has the root user password configured, you can skip these instructions.

**To set an OS user password on a Linux instance**

1. [Connect](connect-to-linux-instance.md) to your instance. You can use any method for connecting to your instance, except the EC2 Serial Console connection method.

1. To set the password for a user, use the **passwd** command. In the following example, the user is `root`.

   ```
   [ec2-user ~]$ sudo passwd root
   ```

   The following is example output.

   ```
   Changing password for user root.
   New password:
   ```

1. At the `New password` prompt, enter the new password.

1. At the prompt, re-enter the password.

# Connect to the EC2 Serial Console
<a name="connect-to-serial-console"></a>

You can connect to the serial console of your EC2 instance by using the Amazon EC2 console or through SSH. After connecting to the serial console, you can use it for troubleshooting boot, network configuration, and other issues. For more information about troubleshooting, see [Troubleshoot your Amazon EC2 instance using the EC2 Serial Console](troubleshoot-using-serial-console.md).

**Considerations**
+ Only 1 active serial console connection is supported per instance.
+ The serial console connection typically lasts for 1 hour unless [you disconnect from it](disconnect-serial-console-session.md). However, during system maintenance, Amazon EC2 will disconnect the serial console session.

  The duration of the connection is not determined by the duration of your IAM credentials. If your IAM credentials expire, the connection continues to persist until the maximum duration of the serial console connection is reached. When using the EC2 Serial Console console experience, if your IAM credentials expire, terminate the connection by closing the browser page.
+ It takes 30 seconds to tear down a session after you've disconnected from the serial console in order to allow a new session.
+ Supported serial console ports: `ttyS0` (Linux instances) and `COM1` (Windows instances)
+ When you connect to the serial console, you might observe a slight drop in your instance’s throughput.

**Topics**
+ [Connect using the browser-based client](#sc-connect-browser-based-client)
+ [Connect using your own key and SSH client](#sc-connect-SSH)
+ [EC2 Serial Console endpoints and fingerprints](#sc-endpoints-and-fingerprints)

## Connect using the browser-based client
<a name="sc-connect-browser-based-client"></a>

You can connect to your EC2 instance's serial console by using the browser-based client. You do this by selecting the instance in the Amazon EC2 console and choosing to connect to the serial console. The browser-based client handles the permissions and provides a successful connection.

EC2 serial console works from most browsers, and supports keyboard and mouse input.

Before connecting, make sure you have completed the [prerequisites](ec2-serial-console-prerequisites.md).

**To connect to your instance's serial port using the browser-based client (Amazon EC2 console)**

1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).

1. In the navigation pane, choose **Instances**.

1. Select the instance and choose **Actions**, **Monitor and troubleshoot**, **EC2 Serial Console**, **Connect**.

   Alternatively, select the instance and choose **Connect**, **EC2 Serial Console**, **Connect**.

   An in-browser terminal window opens.

1. Press **Enter**. If a login prompt returns, you are connected to the serial console.

   If the screen remains black, you can use the following information to help resolve issues with connecting to the serial console:
   + **Check that you have configured access to the serial console.** For more information, see [Configure access to the EC2 Serial Console](configure-access-to-serial-console.md).
   + (Linux instances only) **Use SysRq to connect to the serial console.** SysRq does not require that you connect using the browser-based client. For more information, see [(Linux instances) Use SysRq to troubleshoot your instanceSysRq (Linux)](troubleshoot-using-serial-console.md#SysRq).
   + (Linux instances only) **Restart getty.** If you have SSH access to your instance, then connect to your instance using SSH, and restart getty using the following command.

     ```
     [ec2-user ~]$ sudo systemctl restart serial-getty@ttyS0
     ```
   + **Reboot your instance.** You can reboot your instance by using SysRq (Linux instances), the EC2 console, or the AWS CLI. For more information, see [(Linux instances) Use SysRq to troubleshoot your instanceSysRq (Linux)](troubleshoot-using-serial-console.md#SysRq) (Linux instances) or [Reboot your Amazon EC2 instance](ec2-instance-reboot.md).

1. (Linux instances only) At the `login` prompt, enter the username of the password-based user that you [set up previously](configure-access-to-serial-console.md#set-user-password), and then press **Enter**.

1. (Linux instances only) At the `Password` prompt, enter the password, and then press **Enter**.

## Connect using your own key and SSH client
<a name="sc-connect-SSH"></a>

You can use your own SSH key and connect to your instance from the SSH client of your choice while using the serial console API. This enables you to benefit from the serial console capability to push a public key to the instance.

After pushing the SSH key to the instance, the SSH connection is not subject to the IAM policies that you configured to grant users EC2 Serial Console access.

**Before you begin**  
Verify that the [prerequisites](ec2-serial-console-prerequisites.md) are met.

**To connect to an instance's serial console using SSH**

1. **Push your SSH public key to the instance to start a serial console session**

   Use the [send-serial-console-ssh-public-key](https://docs.aws.amazon.com/cli/latest/reference/ec2-instance-connect/send-serial-console-ssh-public-key.html) command to push your SSH public key to the instance. This starts a serial console session.

   If a serial console session has already been started for this instance, the command fails because you can only have one session open at a time. It takes 30 seconds to tear down a session after you've disconnected from the serial console in order to allow a new session. 

   ```
   aws ec2-instance-connect send-serial-console-ssh-public-key \
       --instance-id i-001234a4bf70dec41EXAMPLE \
       --serial-port 0 \
       --ssh-public-key file://my_key.pub \
       --region us-east-1
   ```

1. 

**Connect to the serial console using your private key**

   Use the **ssh** command to connect to the serial console before the public key is removed from the serial console service. You have 60 seconds before it is removed.

   Use the private key that corresponds to the public key.

   The username format is `instance-id.port0`, which comprises the instance ID and port 0. In the following example, the username is `i-001234a4bf70dec41EXAMPLE.port0`.

   The endpoint of the serial console service is different for each Region. See the [EC2 Serial Console endpoints and fingerprints](#sc-endpoints-and-fingerprints) table for each Region's endpoint. In the following example, the serial console service is in the us-east-1 Region.

   ```
   ssh -i my_key i-001234a4bf70dec41EXAMPLE.port0@serial-console.ec2-instance-connect.us-east-1.aws
   ```

   The following example uses `timeout 3600` to set your SSH session to terminate after 1 hour. Processes started during the session may continue running on your instance after the session terminates.

   ```
   timeout 3600 ssh -i my_key i-001234a4bf70dec41EXAMPLE.port0@serial-console.ec2-instance-connect.us-east-1.aws
   ```

1. 

**(Optional) Verify the fingerprint**

   When you connect for the first time to the serial console, you are prompted to verify the fingerprint. You can compare the serial console fingerprint with the fingerprint that's displayed for verification. If these fingerprints don't match, someone might be attempting a "man-in-the-middle" attack. If they match, you can confidently connect to the serial console.

   The following fingerprint is for the serial console service in the us-east-1 Region. For the fingerprints for each Region, see [EC2 Serial Console endpoints and fingerprints](#sc-endpoints-and-fingerprints).

   ```
   SHA256:dXwn5ma/xadVMeBZGEru5l2gx+yI5LDiJaLUcz0FMmw
   ```

   The fingerprint only appears the first time you connect to the serial console.

1. Press **Enter**. If a prompt returns, you are connected to the serial console.

   If the screen remains black, you can use the following information to help resolve issues with connecting to the serial console:
   + **Check that you have configured access to the serial console.** For more information, see [Configure access to the EC2 Serial Console](configure-access-to-serial-console.md).
   + (Linux instances only) **Use SysRq to connect to the serial console.** SysRq does not require that you connect using SSH. For more information, see [(Linux instances) Use SysRq to troubleshoot your instanceSysRq (Linux)](troubleshoot-using-serial-console.md#SysRq).
   + (Linux instances only) **Restart getty.** If you have SSH access to your instance, then connect to your instance using SSH, and restart getty using the following command.

     ```
     [ec2-user ~]$ sudo systemctl restart serial-getty@ttyS0
     ```
   + **Reboot your instance.** You can reboot your instance by using SysRq (Linux instances only), the EC2 console, or the AWS CLI. For more information, see [(Linux instances) Use SysRq to troubleshoot your instanceSysRq (Linux)](troubleshoot-using-serial-console.md#SysRq) (Linux instances only) or [Reboot your Amazon EC2 instance](ec2-instance-reboot.md).

1. (Linux instances only) At the `login` prompt, enter the username of the password-based user that you [set up previously](configure-access-to-serial-console.md#set-user-password), and then press **Enter**.

1. (Linux instances only) At the `Password` prompt, enter the password, and then press **Enter**.

## EC2 Serial Console endpoints and fingerprints
<a name="sc-endpoints-and-fingerprints"></a>

The following are the service endpoints and fingerprints for EC2 Serial Console. To connect programmatically to an instance's serial console, you use an EC2 Serial Console endpoint. The EC2 Serial Console endpoints and fingerprints are unique for each AWS Region.


| Region Name | Region | Endpoint | Fingerprint | 
| --- | --- | --- | --- | 
| US East (Ohio) | us-east-2 | serial-console.ec2-instance-connect.us-east-2.aws | SHA256:EhwPkTzRtTY7TRSzz26XbB0/HvV9jRM7mCZN0xw/d/0 | 
| US East (N. Virginia) | us-east-1 | serial-console.ec2-instance-connect.us-east-1.aws | SHA256:dXwn5ma/xadVMeBZGEru5l2gx\$1yI5LDiJaLUcz0FMmw | 
| US West (N. California) | us-west-1 | serial-console.ec2-instance-connect.us-west-1.aws | SHA256:OHldlcMET8u7QLSX3jmRTRAPFHVtqbyoLZBMUCqiH3Y | 
| US West (Oregon) | us-west-2 | serial-console.ec2-instance-connect.us-west-2.aws | SHA256:EMCIe23TqKaBI6yGHainqZcMwqNkDhhAVHa1O2JxVUc | 
| Africa (Cape Town) | af-south-1 | ec2-serial-console.af-south-1.api.aws | SHA256:RMWWZ2fVePeJUqzjO5jL2KIgXsczoHlz21Ed00biiWI | 
| Asia Pacific (Hong Kong) | ap-east-1 | ec2-serial-console.ap-east-1.api.aws | SHA256:T0Q1lpiXxChoZHplnAkjbP7tkm2xXViC9bJFsjYnifk | 
| Asia Pacific (Taipei) | ap-east-2 | ec2-serial-console.ap-east-2.api.aws | SHA256:z1rsF5DE8aQqsHwBr/D40tR2GnyMqnScCUa1z1eFwDQ | 
| Asia Pacific (Hyderabad) | ap-south-2 | ec2-serial-console.ap-south-2.api.aws | SHA256:WJgPBSwV4/shN\$1OPITValoewAuYj15DVW845JEhDKRs | 
| Asia Pacific (Jakarta) | ap-southeast-3 | ec2-serial-console.ap-southeast-3.api.aws | SHA256:5ZwgrCh\$1lfns32XITqL/4O0zIfbx4bZgsYFqy3o8mIk | 
| Asia Pacific (Malaysia) | ap-southeast-5 | ec2-serial-console.ap-southeast-5.api.aws | SHA256:cQXTHQMRcqRdIjmAGoAMBSExeoRobYyRwT67yTjnEiA | 
| Asia Pacific (New Zealand) | ap-southeast-6 | ec2-serial-console.ap-southeast-6.api.aws | SHA256:wNltdH0gVfM5uHJKjrw\$1ElFuKoJgalcSKqjCS\$1lLkv4 | 
| Asia Pacific (Melbourne) | ap-southeast-4 | ec2-serial-console.ap-southeast-4.api.aws | SHA256:Avaq27hFgLvjn5gTSShZ0oV7h90p0GG46wfOeT6ZJvM | 
| Asia Pacific (Mumbai) | ap-south-1 | serial-console.ec2-instance-connect.ap-south-1.aws | SHA256:oBLXcYmklqHHEbliARxEgH8IsO51rezTPiSM35BsU40 | 
| Asia Pacific (Osaka) | ap-northeast-3 | ec2-serial-console.ap-northeast-3.api.aws | SHA256:Am0/jiBKBnBuFnHr9aXsgEV3G8Tu/vVHFXE/3UcyjsQ | 
| Asia Pacific (Seoul) | ap-northeast-2 | serial-console.ec2-instance-connect.ap-northeast-2.aws | SHA256:FoqWXNX\$1DZ\$1\$1GuNTztg9PK49WYMqBX\$1FrcZM2dSrqrI | 
| Asia Pacific (Singapore) | ap-southeast-1 | serial-console.ec2-instance-connect.ap-southeast-1.aws | SHA256:PLFNn7WnCQDHx3qmwLu1Gy/O8TUX7LQgZuaC6L45CoY | 
| Asia Pacific (Sydney) | ap-southeast-2 | serial-console.ec2-instance-connect.ap-southeast-2.aws | SHA256:yFvMwUK9lEUQjQTRoXXzuN\$1cW9/VSe9W984Cf5Tgzo4 | 
| Asia Pacific (Thailand) | ap-southeast-7 | ec2-serial-console.ap-southeast-7.api.aws | SHA256:KCAZiRYrR1Q2lqsg7vTwixWmvc2wmjVT31XRgSdEfDY | 
| Asia Pacific (Tokyo) | ap-northeast-1 | serial-console.ec2-instance-connect.ap-northeast-1.aws | SHA256:RQfsDCZTOfQawewTRDV1t9Em/HMrFQe\$1CRlIOT5um4k | 
| Canada (Central) | ca-central-1 | serial-console.ec2-instance-connect.ca-central-1.aws | SHA256:P2O2jOZwmpMwkpO6YW738FIOTHdUTyEv2gczYMMO7s4 | 
| Canada West (Calgary) | ca-west-1 | ec2-serial-console.ca-west-1.api.aws | SHA256:s3rc8lI2xhbhr3iedjJNxGAFLPGOLjx7IxxXrGckk6Q | 
| China (Beijing) | cn-north-1 | ec2-serial-console---cn-north-1---api.amazonwebservices.com.rproxy.govskope.us.cn | SHA256:2gHVFy4H7uU3\$1WaFUxD28v/ggMeqjvSlgngpgLgGT\$1Y | 
| China (Ningxia) | cn-northwest-1 | ec2-serial-console---cn-northwest-1---api.amazonwebservices.com.rproxy.govskope.us.cn | SHA256:TdgrNZkiQOdVfYEBUhO4SzUA09VWI5rYOZGTogpwmiM | 
| Europe (Frankfurt) | eu-central-1 | serial-console.ec2-instance-connect.eu-central-1.aws | SHA256:aCMFS/yIcOdOlkXvOl8AmZ1Toe\$1bBnrJJ3Fy0k0De2c | 
| Europe (Ireland) | eu-west-1 | serial-console.ec2-instance-connect.eu-west-1.aws | SHA256:h2AaGAWO4Hathhtm6ezs3Bj7udgUxi2qTrHjZAwCW6E | 
| Europe (London) | eu-west-2 | serial-console.ec2-instance-connect.eu-west-2.aws | SHA256:a69rd5CE/AEG4Amm53I6lkD1ZPvS/BCV3tTPW2RnJg8 | 
| Europe (Milan) | eu-south-1 | ec2-serial-console.eu-south-1.api.aws | SHA256:lC0kOVJnpgFyBVrxn0A7n99ecLbXSX95cuuS7X7QK30 | 
| Europe (Paris) | eu-west-3 | serial-console.ec2-instance-connect.eu-west-3.aws | SHA256:q8ldnAf9pymeNe8BnFVngY3RPAr/kxswJUzfrlxeEWs | 
| Europe (Spain) | eu-south-2 | ec2-serial-console.eu-south-2.api.aws | SHA256:GoCW2DFRlu669QNxqFxEcsR6fZUz/4F4n7T45ZcwoEc | 
| Europe (Stockholm) | eu-north-1 | serial-console.ec2-instance-connect.eu-north-1.aws | SHA256:tkGFFUVUDvocDiGSS3Cu8Gdl6w2uI32EPNpKFKLwX84 | 
| Europe (Zurich) | eu-central-2 | ec2-serial-console.eu-central-2.api.aws | SHA256:8Ppx2mBMf6WdCw0NUlzKfwM4/IfRz4OaXFutQXWp6mk | 
| Israel (Tel Aviv) | il-central-1 | ec2-serial-console.il-central-1.api.aws | SHA256:JR6q8v6kNNPi8\$1QSFQ4dj5dimNmZPTgwgsM1SNvtYyU | 
| Mexico (Central) | mx-central-1 | ec2-serial-console.mx-central-1.api.aws | SHA256:BCuVl13iQNk\$1CcVnt18Ef4p2ZHUrBBAOxlFetB32GS0 | 
| Middle East (Bahrain) | me-south-1 | ec2-serial-console.me-south-1.api.aws | SHA256:nPjLLKHu2QnLdUq2kVArsoK5xvPJOMRJKCBzCDqC3k8 | 
| Middle East (UAE) | me-central-1 | ec2-serial-console.me-central-1.api.aws | SHA256:zpb5duKiBZ\$1l0dFwPeyykB4MPBYhI/XzXNeFSDKBvLE | 
| South America (São Paulo) | sa-east-1 | serial-console.ec2-instance-connect.sa-east-1.aws | SHA256:rd2\$1/32Ognjew1yVIemENaQzC\$1Botbih62OqAPDq1dI | 
| AWS GovCloud (US-East) | us-gov-east-1 | serial-console.ec2-instance-connect.us-gov-east-1.amazonaws.com | SHA256:tIwe19GWsoyLClrtvu38YEEh\$1DHIkqnDcZnmtebvF28 | 
| AWS GovCloud (US-West) | us-gov-west-1 | serial-console.ec2-instance-connect.us-gov-west-1.amazonaws.com | SHA256:kfOFRWLaOZfB\$1utbd3bRf8OlPf8nGO2YZLqXZiIw5DQ | 

# Disconnect from the EC2 Serial Console
<a name="disconnect-serial-console-session"></a>

If you no longer need to be connected to your instance's EC2 Serial Console, you can disconnect from it. When you disconnect from the serial console, any shell session running on the instance will continue to run. If you want to end the shell session, you'll need to end it before disconnecting from the serial console.

**Considerations**
+ The serial console connection typically lasts for 1 hour unless you disconnect from it. However, during system maintenance, Amazon EC2 will disconnect the serial console session.
+ It takes 30 seconds to tear down a session after you've disconnected from the serial console in order to allow a new session.

The way to disconnect from the serial console depends on the client.

**Browser-based client**  
To disconnect from the serial console, close the serial console in-browser terminal window.

**Standard OpenSSH client**  
To disconnect from the serial console, use the following command to close the SSH connection. This command must be run immediately following a new line.

```
~.
```

The command that you use for closing an SSH connection might be different depending on the SSH client that you're using.

# Troubleshoot your Amazon EC2 instance using the EC2 Serial Console
<a name="troubleshoot-using-serial-console"></a>

By using EC2 Serial Console, you can troubleshoot boot, network configuration, and other issues by connecting to your instance's serial port.

Use the instructions for your instance's operating system and for the tool you've configured on your instance.

**Topics**
+ [GRUB (Linux)](#grub)
+ [SysRq (Linux)](#SysRq)
+ [SAC (Windows)](#troubleshooting-sac)

**Prerequisites**  
Before you begin, make sure you have completed the [ prerequisites](ec2-serial-console-prerequisites.md), including configuring your chosen troubleshooting tool.

## (Linux instances) Use GRUB to troubleshoot your instance
<a name="grub"></a>

GNU GRUB (short for GNU GRand Unified Bootloader, commonly referred to as GRUB) is the default boot loader for most Linux operating systems. From the GRUB menu, you can select which kernel to boot into, or modify menu entries to change how the kernel will boot. This can be useful when troubleshooting a failing instance.

The GRUB menu is displayed during the boot process. The menu is not accessible via normal SSH, but you can access it using the EC2 Serial Console.

You can boot into single user mode or emergency mode. Single user mode will boot the kernel at a lower runlevel. For example, it might mount the filesystem but not activate the network, giving you the opportunity to perform the maintenance necessary to fix the instance. Emergency mode is similar to single user mode except that the kernel runs at the lowest runlevel possible.

**To boot into single user mode**

1. [Connect](connect-to-serial-console.md) to the instance's serial console.

1. Reboot the instance using the following command.

   ```
   [ec2-user ~]$ sudo reboot
   ```

1. During reboot, when the GRUB menu appears, press any key to stop the boot process.

1. In the GRUB menu, use the arrow keys to select the kernel to boot into, and press `e` on your keyboard. 

1. Use the arrow keys to locate your cursor on the line containing the kernel. The line begins with either `linux` or `linux16` depending on the AMI that was used to launch the instance. For Ubuntu, two lines begin with `linux`, which must both be modified in the next step.

1. At the end of the line, add the word `single`.

   The following is an example for Amazon Linux 2.

   ```
   linux /boot/vmlinuz-4.14.193-149.317.amzn2.aarch64 root=UUID=d33f9c9a-\
   dadd-4499-938d-ebbf42c3e499 ro  console=tty0 console=ttyS0,115200n8 net.ifname\
   s=0 biosdevname=0 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.she\
   ll=0 single
   ```

1. Press **Ctrl\$1X** to boot into single user mode.

1. At the `login` prompt, enter the username of the password-based user that you [set up previously](configure-access-to-serial-console.md#set-user-password), and then press **Enter**.

1. At the `Password` prompt, enter the password, and then press **Enter**.

 

**To boot into emergency mode**  
Follow the same steps as single user mode, but at step 6, add the word `emergency` instead of `single`.

## (Linux instances) Use SysRq to troubleshoot your instance
<a name="SysRq"></a>

The System Request (SysRq) key, which is sometimes referred to as "magic SysRq", can be used to directly send the kernel a command, outside of a shell, and the kernel will respond, regardless of what the kernel is doing. For example, if the instance has stopped responding, you can use the SysRq key to tell the kernel to crash or reboot. For more information, see [Magic SysRq key](https://en.wikipedia.org/wiki/Magic_SysRq_key) in Wikipedia.

You can use SysRq commands in the EC2 Serial Console browser-based client or in an SSH client. The command to send a break request is different for each client.

To use SysRq, choose one of the following procedures based on the client that you are using.

------
#### [ Browser-based client ]

**To use SysRq in the serial console browser-based client**

1. [Connect](connect-to-serial-console.md) to the instance's serial console.

1. To send a break request, press `CTRL+0` (zero). If your keyboard supports it, you can also send a break request using the Pause or Break key.

   ```
   [ec2-user ~]$ CTRL+0
   ```

1. To issue a SysRq command, press the key on your keyboard that corresponds to the required command. For example, to display a list of SysRq commands, press `h`.

   ```
   [ec2-user ~]$ h
   ```

   The `h` command outputs something similar to the following.

   ```
   [ 1169.389495] sysrq: HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems
   (j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r
   ) sync(s) show-task-states(t) unmount(u) show-blocked-tasks(w) dump-ftrace-buffer(z)
   ```

------
#### [ SSH client ]

**To use SysRq in an SSH client**

1. [Connect](connect-to-serial-console.md) to the instance's serial console.

1. To send a break request, press `~B` (tilde, followed by uppercase `B`).

   ```
   [ec2-user ~]$ ~B
   ```

1. To issue a SysRq command, press the key on your keyboard that corresponds to the required command. For example, to display a list of SysRq commands, press `h`.

   ```
   [ec2-user ~]$ h
   ```

   The `h` command outputs something similar to the following.

   ```
   [ 1169.389495] sysrq: HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems
   (j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r
   ) sync(s) show-task-states(t) unmount(u) show-blocked-tasks(w) dump-ftrace-buffer(z)
   ```
**Note**  
The command that you use for sending a break request might be different depending on the SSH client that you're using.

------

## (Windows instances) Use SAC to troubleshoot your instance
<a name="troubleshooting-sac"></a>

The Special Admin Console (SAC) capability of Windows provides a way to troubleshoot a Windows instance. By connecting to the instance's serial console and using SAC, you can interrupt the boot process and boot Windows in safe mode.

**Note**  
If you enable SAC on an instance, the EC2 services that rely on password retrieval will not work from the Amazon EC2 console. Windows on Amazon EC2 launch agents (EC2Config, EC2Launch v1, and EC2Launch v2) rely on the serial console to execute various tasks. These tasks do not perform successfully when you enable SAC on an instance. For more information about Windows on Amazon EC2 launch agents, see [Configure your Amazon EC2 Windows instance](ec2-windows-instances.md). If you enable SAC, you can disable it later. For more information, see [Disable SAC and the boot menu](#disable-sac-bootmenu).

**Topics**
+ [Use SAC](#use-sac)
+ [Use the boot menu](#use-boot-menu)
+ [Disable SAC and the boot menu](#disable-sac-bootmenu)

### Use SAC
<a name="use-sac"></a>

**To use SAC**

1. [Connect to the serial console.](connect-to-serial-console.md)

   If SAC is enabled on the instance, the serial console displays the `SAC>` prompt.  
![\[SAC prompt displayed in the serial console.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-3.png)

1. To display the SAC commands, enter ?, and then press **Enter**.

   Expected output  
![\[Enter a question mark to display the SAC commands.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-4.png)

1. To create a command prompt channel (such as `cmd0001` or `cmd0002`), enter cmd, and then press **Enter**.

1. To view the command prompt channel, press **ESC**, and then press **TAB**.

   Expected output  
![\[The command prompt channel.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-5.png)

1. To switch channels, press **ESC\$1TAB\$1channel number** together. For example, to switch to the `cmd0002` channel (if it has been created), press **ESC\$1TAB\$12**.

1. Enter the credentials required by the command prompt channel.  
![\[The command prompt requiring credentials.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-6.png)

   The command prompt is the same full-featured command shell that you get on a desktop, but with the exception that it does not allow the reading of characters that were already output.  
![\[A full-featured command shell.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-7.png)

**PowerShell can also be used from the command prompt.**

Note that you might need to set the progress preference to silent mode.

![\[PowerShell within the command prompt.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-8.png)


### Use the boot menu
<a name="use-boot-menu"></a>

If the instance has the boot menu enabled and is restarted after connecting through SSH, you should see the boot menu, as follows.

![\[Boot menu in the command prompt.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-1.png)


**Boot menu commands**

ENTER  
Starts the selected entry of the operating system.

TAB  
Switches to the Tools menu.

ESC  
Cancels and restarts the instance.

ESC followed by 8  
Equivalent to pressing **F8**. Shows advanced options for the selected item.

ESC key \$1 left arrow  
Goes back to the initial boot menu.  
The ESC key alone does not take you back to the main menu because Windows is waiting to see if an escape sequence is in progress.

![\[Advanced boot options.\]](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/images/win-boot-2.png)


### Disable SAC and the boot menu
<a name="disable-sac-bootmenu"></a>

If you enable SAC and the boot menu, you can disable these features later.

Use one of the following methods to disable SAC and the boot menu on an instance.

------
#### [ PowerShell ]

**To disable SAC and the boot menu on a Windows instance**

1. [Connect](connecting_to_windows_instance.md) to your instance and perform the following steps from an elevated PowerShell command line.

1. First disable the boot menu by changing the value to `no`.

   ```
   bcdedit /set '{bootmgr}' displaybootmenu no
   ```

1. Then disable SAC by changing the value to `off`.

   ```
   bcdedit /ems '{current}' off
   ```

1. Apply the updated configuration by rebooting the instance.

   ```
   shutdown -r -t 0
   ```

------
#### [ Command prompt ]

**To disable SAC and the boot menu on a Windows instance**

1. [Connect](connecting_to_windows_instance.md) to your instance and perform the following steps from the command prompt.

1. First disable the boot menu by changing the value to `no`.

   ```
   bcdedit /set {bootmgr} displaybootmenu no
   ```

1. Then disable SAC by changing the value to `off`.

   ```
   bcdedit /ems {current} off
   ```

1. Apply the updated configuration by rebooting the instance.

   ```
   shutdown -r -t 0
   ```

------

# Send a diagnostic interrupt to debug an unreachable Amazon EC2 instance
<a name="diagnostic-interrupt"></a>

**Warning**  
Diagnostic interrupts are intended for use by advanced users. Incorrect usage could negatively impact your instance. Sending a diagnostic interrupt to an instance could trigger an instance to crash and reboot, which could lead to the loss of data.

You can send a diagnostic interrupt to an unreachable or unresponsive instance to manually trigger a *kernel panic* for a Linux instance, or a *stop error* (commonly referred to as a *blue screen error*) for a Windows instance.

**Linux instances**  
Linux operating systems typically crash and reboot when a kernel panic occurs. The specific behavior of the operating system depends on its configuration. A kernel panic can also be used to cause the instance's operating system kernel to perform tasks, such as generating a crash dump file. You can then use the information in the crash dump file to conduct root cause analysis and debug the instance. The crash dump data is generated locally by the operating system on the instance itself.

**Windows instances**  
In general, Windows operating systems crash and reboot when a stop error occurs, but the specific behavior depends on its configuration. A stop error can also cause the operating system to write debugging information, such as a kernel memory dump, to a file. You can then use this information to conduct root cause analysis to debug the instance. The memory dump data is generated locally by the operating system on the instance itself.

Before sending a diagnostic interrupt to your instance, we recommend that you consult the documentation for your operating system and then make the necessary configuration changes.

**Topics**
+ [Supported instance types](#diagnostic-interrupt-instances)
+ [Prerequisites](#diagnostic-interrupt-prereqs)
+ [Send a diagnostic interrupt](#diagnostic-interrupt-use)

## Supported instance types
<a name="diagnostic-interrupt-instances"></a>

Diagnostic interrupt is supported on all Nitro-based instance types, except those powered by AWS Graviton processors. For more information, see [instances built on the AWS Nitro System](https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-nitro-instances.html) and [AWS Graviton](https://aws.amazon.com/ec2/graviton/).

## Prerequisites
<a name="diagnostic-interrupt-prereqs"></a>

Before using a diagnostic interrupt, you must configure your instance's operating system. This ensures that it performs the actions that you need when a kernel panic (Linux instances) or stop error (Windows instances) occurs.

### Linux instances
<a name="diagnostic-interrupt-prereqs-linux"></a>

**To configure Amazon Linux 2 or Amazon Linux 2023 to generate a crash dump when a kernel panic occurs**

1. Connect to your instance.

1. Install **kexec** and **kdump**.

   ```
   [ec2-user ~]$ sudo yum install kexec-tools -y
   ```

1. Configure the kernel to reserve an appropriate amount of memory for the secondary kernel. The amount of memory to reserve depends on the total available memory of your instance. Open the `/etc/default/grub` file using your preferred text editor, locate the line that starts with `GRUB_CMDLINE_LINUX_DEFAULT`, and then add the `crashkernel` parameter in the following format: `crashkernel=memory_to_reserve`. For example, to reserve `256MB`, modify the `grub` file as follows:

   ```
   GRUB_CMDLINE_LINUX_DEFAULT="crashkernel=256M console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.shell=0"
   GRUB_TIMEOUT=0
   GRUB_DISABLE_RECOVERY="true"
   ```

1. Save the changes and close the `grub` file.

1. Rebuild the GRUB2 configuration file.

   ```
   [ec2-user ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
   ```

1. On instances based on Intel and AMD processors, the `send-diagnostic-interrupt` command sends an *unknown non-maskable interrupt* (NMI) to the instance. You must configure the kernel to crash when it receives the unknown NMI. Open the `/etc/sysctl.conf` file using your preferred text editor and add the following.

   ```
   kernel.unknown_nmi_panic=1
   ```

1. Reboot and reconnect to your instance.

1. Verify that the kernel has been booted with the correct `crashkernel` parameter.

   ```
   $ grep crashkernel /proc/cmdline
   ```

   The following example output indicates successful configuration.

   ```
   BOOT_IMAGE=/boot/vmlinuz-4.14.128-112.105.amzn2.x86_64 root=UUID=a1e1011e-e38f-408e-878b-fed395b47ad6 ro crashkernel=256M console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 nvme_core.io_timeout=4294967295 rd.emergency=poweroff rd.shell=0
   ```

1. Verify that the **kdump** service is running.

   ```
   [ec2-user ~]$ systemctl status kdump.service
   ```

   The following example output shows the result if the **kdump** service is running.

   ```
   kdump.service - Crash recovery kernel arming
      Loaded: loaded (/usr/lib/systemd/system/kdump.service; enabled; vendor preset: enabled)
      Active: active (exited) since Fri 2019-05-24 23:29:13 UTC; 22s ago
     Process: 2503 ExecStart=/usr/bin/kdumpctl start (code=exited, status=0/SUCCESS)
    Main PID: 2503 (code=exited, status=0/SUCCESS)
   ```

**Note**  
By default, the crash dump file is saved to `/var/crash/`. To change the location, modify the `/etc/kdump.conf` file using your preferred text editor.

**To configure SUSE Linux Enterprise, Ubuntu, or Red Hat Enterprise Linux**  
On instances based on Intel and AMD processors, the `send-diagnostic-interrupt` command sends an *unknown non-maskable interrupt* (NMI) to the instance. You must configure the kernel to crash when it receives the unknown NMI by adjusting the configuration file for your operating system. For information about how to configure the kernel to crash, see the documentation for your operating system:
+ [SUSE Linux Enterprise](https://www.suse.com/support/kb/doc/?id=3374462)
+ [Ubuntu](https://ubuntu.com/server/docs/kernel-crash-dump)
+ [ Red Hat Enterprise Linux (RHEL)](https://access.redhat.com/solutions/6038)

### Windows instances
<a name="diagnostic-interrupt-prereqs-windows"></a>

**To configure Windows to generate a memory dump when a stop error occurs**

1. Connect to your instance.

1. Open the **Control Panel** and choose **System**, **Advanced system settings**.

1. In the **System Properties** dialog box, choose the **Advanced** tab.

1. In the **Startup and Recovery** section, choose **Settings...**.

1. In the **System failure** section, configure the settings as needed, and then choose **OK**.

For more information about configuring Windows stop errors, see [ Overview of memory dump file options for Windows](https://support.microsoft.com/en-us/help/254649/overview-of-memory-dump-file-options-for-windows).

## Send a diagnostic interrupt
<a name="diagnostic-interrupt-use"></a>

After you have completed the necessary configuration changes, you can send a diagnostic interrupt to your instance using the AWS CLI or Amazon EC2 API.

------
#### [ AWS CLI ]

**To send a diagnostic interrupt to your instance**  
Use the [send-diagnostic-interrupt](https://docs.aws.amazon.com/cli/latest/reference/ec2/send-diagnostic-interrupt.html) command.

```
aws ec2 send-diagnostic-interrupt --instance-id i-1234567890abcdef0
```

------
#### [ PowerShell ]

**To send a diagnostic interrupt to your instance**  
Use the [Send-EC2DiagnosticInterrupt](https://docs.aws.amazon.com/powershell/latest/reference/items/Send-EC2DiagnosticInterrupt.html) cmdlet.

```
Send-EC2DiagnosticInterrupt -InstanceId i-1234567890abcdef0
```

------