A collection of shell scripts and examples.
This script is designed to establish a secure session with a jump-box (EC2 instance) in an AWS environment. It performs several checks and operations to ensure a smooth connection.
- AWS CLI and Session Manager Plugin (SSM) must be installed and configured with the necessary credentials.
- The user must have the required permissions to access AWS STS, Organizations, EC2, and SSM services.
-
Authentication Check:
- The script first checks if the AWS CLI is authenticated by attempting to retrieve the caller identity using
aws sts get-caller-identity
.
- The script first checks if the AWS CLI is authenticated by attempting to retrieve the caller identity using
-
Retrieve AWS Account Information:
- It fetches the AWS account ID and account name using
aws sts get-caller-identity
andaws organizations describe-account
.
- It fetches the AWS account ID and account name using
-
Inform User:
- The script informs the user about the AWS account they are connected to by displaying the account ID and name.
-
Retrieve Jump-Box Instance ID:
- It retrieves the instance ID of the jump-box by filtering EC2 instances with the tag
Name=jump-box
.
- It retrieves the instance ID of the jump-box by filtering EC2 instances with the tag
-
Start SSM Session:
- The script starts an SSM session with the jump-box instance using
aws ssm start-session
.
- The script starts an SSM session with the jump-box instance using
To use the script, set its mode to executable and run it in your terminal:
chmod +x aws-jump-box.sh
./aws-jump-box.sh
This script is designed to establish a secure port forwarding session to a jump-box (EC2 instance) in an AWS environment. It includes several functions to handle authentication, retrieve necessary information, and start the session.
- AWS CLI and Session Manager Plugin (SSM) must be installed and configured with the necessary credentials.
- The user must have the required permissions to access AWS STS, Organizations, EC2, and SSM services.
- Handles errors by printing an error message and exiting the script.
-
Authentication Check:
- Checks if the AWS CLI is authenticated by attempting to retrieve the caller identity using
aws sts get-caller-identity
.
- Checks if the AWS CLI is authenticated by attempting to retrieve the caller identity using
-
Retrieve AWS Account Information:
- Fetches the AWS account ID and account name using
aws sts get-caller-identity
andaws organizations describe-account
.
- Fetches the AWS account ID and account name using
-
Inform User:
- Informs the user about the AWS account they are connected to by displaying the account ID and name.
- Retrieves the instance ID of the jump-box by filtering EC2 instances with the tag
Name=jump-box
.
- Prompts the user to enter the remote hostname and port number for the port forwarding session.
- Starts the port forwarding session using AWS SSM.
To use the script, set its mode to executable and run it in your terminal:
chmod +x aws-port-forward.sh
./aws-port-forward.sh