This script is designed to facilitate the initial setup of a newly instantiated AWS EC2 instance. It allows for a secure and swift transition from the default EC2 user setup by automating several setup tasks.
- User and Hostname Setup: Prompts for and sets up a new username and a desired hostname.
- SSH Key Configuration: Dynamically determines the current logged-in user to copy SSH key configurations to the new user.
- Sudo Permissions: Creates a new user and grants it sudo permissions without needing a password.
- Hostname Configuration: Allows setting up a custom hostname for the instance.
- Preserve Hostname Modification: Modifies
/etc/cloud/cloud.cfg
to setpreserve_hostname
.
- Clone this Repository:
git clone https://github.com/HezhaKh/ops345.git
- Navigate to the Script Directory:
cd /path/to/script/directory/
- Make the Script Executable:
chmod +x setup_aws.sh
- Execute the Script with Sudo:
sudo ./setup_aws.sh
- Follow On-Screen Prompts:
- Enter the desired username.
- Enter the desired hostname.
- Follow any additional prompts to complete the setup.
This script is purposed to:
- Verify root/sudo privileges.
- Gather inputs for new username, hostname, and sudoers filename.
- Set up a new user with sudo privileges without a password and with the correct permissions.
- Copy SSH key configurations from the current user to the new user.
- Apply the new hostname.
- Modify
preserve_hostname
in/etc/cloud/cloud.cfg
. - Provide a completion message with further instructions or actions.
Make sure to test the new user setup and configurations after the completion of the script and adjust as necessary.