Linux Bastion Hosts on AWS
Quick Start Deployment Guide
Santiago Cardenas, AWS Serverless Partners
Tony Vattathil, Ian Hill, and Troy Lindsay, AWS Integration & Automation team
|Refer to the GitHub repository to view source files, report bugs, submit feature ideas, and post feedback about this Quick Start. To comment on the documentation, refer to Feedback.|
This Quick Start deploys Linux bastion hosts on the AWS Cloud. This guide covers the steps necessary to deploy this Quick Start.
Costs and licenses
There is no cost to use this Quick Start, but you will be billed for any AWS services or resources that this Quick Start deploys. For more information, refer to the AWS Quick Start General Information Guide.
Deploying this Quick Start with default parameters builds the following Linux Bastion Hosts environment in the AWS Cloud.
|The bastion host no longer has a public IP address assigned for remote access by default. You can connect to your Linux instance using Session Manager, a capability of AWS Systems Manager. If a remote-access CIDR block is configured for the deployment, an Elastic IP address is assigned, and inbound SSH (Secure Shell) access is permitted.|
As shown in Figure 1, this Quick Start sets up the following:
A highly available architecture that spans two Availability Zones.*
A virtual private cloud (VPC) configured with public and private subnets, according to AWS best practices, to provide you with your own virtual network on AWS.*
In the public subnets:
Managed network address translation (NAT) gateways to allow outbound internet access for resources in the private subnets.*
A Linux bastion host in an Auto Scaling group for connecting to Amazon Elastic Compute Cloud (Amazon EC2) instances in public and private subnets.
An Amazon CloudWatch log group to hold the Linux bastion host shell history logs.
AWS Systems Manager for access to the bastion host.
* The template that deploys this Quick Start into an existing VPC skips the components marked by asterisks and prompts you for your existing VPC configuration.
This Quick Start provides the following deployment options:
Deploy Linux Bastion Hosts into a new VPC. This option builds a new AWS environment that consists of a VPC, private and public subnets, NAT gateways, Linux bastion hosts, and other infrastructure components.
Deploy Linux Bastion Hosts into an existing VPC. This option provisions Linux Bastion Hosts in your existing AWS infrastructure.
This Quick Start provides separate templates for these options. It also lets you configure Classless Inter-Domain Routing (CIDR) blocks, instance types, and Linux Bastion Hosts settings.
(Optional) Create a key pair
(Optional) Customize the Linux bastion host banner
This Quick Start provides a banner for the Linux bastion hosts, as illustrated in Figure 2.
To enable the banner, you set the Bastion banner parameter to true during deployment. The banner is disabled by default. We recommend that you enable it during deployment to notify users that all their actions will be monitored and recorded.
To customize the banner, create an ASCII text file with your own banner content. Then upload the file to an S3 bucket or other publicly accessible location, and verify that it is accessible from the host.
Sign in to your AWS account, and launch this Quick Start, as described under Deployment options. The AWS CloudFormation console opens with a prepopulated template. Deployment takes about 5 minutes to complete.
Choose the correct AWS Region, and then choose Next.
On the Create stack page, keep the default setting for the template URL, and then choose Next.
On the Specify stack details page, change the stack name if needed. Review the parameters for the template. Provide values for the parameters that require input. For all other parameters, review the default settings and customize them as necessary. When you finish reviewing and customizing the parameters, choose Next.
Unless you are customizing the Quick Start templates for your own projects, don’t change the default settings for the following Amazon Simple Storage Service (Amazon S3) parameters: Quick Start S3 bucket name, Quick Start S3 bucket Region, and Quick Start S3 key prefix. Changing these settings automatically updates code references to point to a new Quick Start location. For more information, refer to the AWS Quick Start Contributor’s Guide.
On the Review page, review and confirm the template settings. Under Capabilities, select all of the check boxes to acknowledge that the template creates AWS Identity and Access Management (IAM) resources that might require the ability to automatically expand macros.
Choose Create stack to deploy the stack.
Monitor the stack’s status, and when the status is CREATE_COMPLETE, the Linux Bastion Hosts deployment is ready.
To view the created resources, choose the Outputs tab.
Confirm that you can log in to the bastion host
Log in to the bastion host. Use one of the following user names, depending on your choice of Linux distribution:
Amazon Linux / SUSE Linux Enterprise Server (SLES): ec2-user
The Linux distribution is specified in the Bastion AMI operating system parameter when you deploy the templates.
The bastion hosts deployed by this Quick Start provide a command logger in the
This log file contains the date, SSH client connection IP address, user name, working directory, and the commands issued.
For added security, the contents of the
/var/log/audit/audit.log file is also stored in a CloudWatch Logs log group in the AWS Cloud and remains available in case the bastion hosts fail.
The log includes a history of the commands that are run when you log in. Figure 3 shows an example.
bastion.log file is an immutable file that cannot be easily deleted or tampered with.
However, in case this happens, there is a shadow file with a copy of
bastion.log located in
The Quick Start also stores the contents of
bastion.log remotely using the CloudWatch Logs service.
Log files can be found under CloudWatch Logs using the instance ID as the log stream name.
This Quick Start provisions one Linux bastion host in each Availability Zone with a single security group as a virtual firewall. This security group is required for remote access from the Internet if a remote access CIDR block was configured for the deployment. The security group is configured as follows:
Remote access CIDR
Remote access CIDR
For more information, refer to Internetwork traffic privacy in Amazon VPC.
I encountered a CREATE_FAILED error when I launched the Quick Start
If AWS CloudFormation fails to create the stack, relaunch the template with Rollback on failure set to Disabled. This setting is under Advanced in the AWS CloudFormation console on the Configure stack options page. With this setting, the stack’s state is retained, and you can troubleshoot the issue.
|When you set Rollback on failure to Disabled, you continue to incur AWS charges for this stack. Ensure that you delete stack after troubleshooting.|
For more information, refer to Troubleshooting CloudFormation.
I encountered a size-limitation error when I deployed the AWS CloudFormation templates
Launch the Quick Start templates from the links in this guide or from another S3 bucket. If you deploy the templates from a local copy on your computer or from a location other than an S3 bucket, you might encounter template-size limitations. For more information, refer to AWS CloudFormation quotas.
I changed the instance type parameter after deployment and updated the stack, but the instance types did not change or the Elastic IP addresses were not reassociated after the stack update
Terminate your bastion host instances. They will be replaced by Auto Scaling. A bootstrap action is performed on the new instances to configure security settings and CloudWatch logs and associate Elastic IP addresses.
After you deploy a Quick Start, confirm that your resources and services are updated and configured—including any required patches—to meet your security and other needs. For more information, refer to the Shared Responsibility Model.
To submit feature ideas and report bugs, use the Issues section of the GitHub repository for this Quick Start. To submit code, refer to the Quick Start Contributor’s Guide. To submit feedback on this deployment guide, use the following GitHub links:
This document is provided for informational purposes only. It represents current AWS product offerings and practices as of the date of issue of this document, which are subject to change without notice. Customers are responsible for making their own independent assessment of the information in this document and any use of AWS products or services, each of which is provided "as is" without warranty of any kind, whether expressed or implied. This document does not create any warranties, representations, contractual commitments, conditions, or assurances from AWS, its affiliates, suppliers, or licensors. The responsibilities and liabilities of AWS to its customers are controlled by AWS agreements, and this document is not part of, nor does it modify, any agreement between AWS and its customers.
The software included with this paper is licensed under the Apache License, version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the accompanying "license" file. This code is distributed on an "as is" basis, without warranties or conditions of any kind, either expressed or implied. Refer to the License for specific language governing permissions and limitations.