Introduction
The AWS Command Line Interface (AWS CLI) is a powerful tool that enables developers and system administrators to interact with Amazon Web Services directly from the terminal. During setup, users typically configure AWS CLI using the aws configure command, which stores credentials and default settings locally on the system.
There are situations where you may need to remove or update your AWS configuration, such as rotating credentials, switching AWS accounts, decommissioning a development environment, or enhancing security. This guide explains how to safely remove AWS CLI configuration from an Ubuntu system.
Understanding AWS CLI Configuration Files
When you run:
aws configure
AWS CLI stores configuration data in the following files:
~/.aws/credentials
~/.aws/config
credentials file
Contains sensitive authentication information:
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
config file
Contains region and output preferences:
[default]
region = ap-northeast-2
output = json
Method 1: Remove All AWS CLI Configuration
If you want to completely remove all configured AWS credentials and settings, delete both files:
rm -f ~/.aws/credentials ~/.aws/config
This will remove:
- AWS Access Key ID
- AWS Secret Access Key
- Default Region
- Output Format Preferences
Verify Removal
Run:
aws configure list
If the configuration has been removed successfully, AWS CLI will no longer display configured credentials or region information.
Method 2: Remove a Specific AWS Profile
AWS CLI supports multiple profiles for managing different AWS accounts.
View Existing Profiles
Check your configuration files:
cat ~/.aws/credentials
cat ~/.aws/config
Edit the Files
Open the files with a text editor:
nano ~/.aws/credentials
nano ~/.aws/config
Remove the profile section you no longer need.
Example:
[development]
aws_access_key_id = EXAMPLE
aws_secret_access_key = EXAMPLE
Save the file after removing the profile.
Method 3: Uninstall AWS CLI from Ubuntu
If you no longer need AWS CLI, you can uninstall it completely.
Determine Installation Method
First, check the AWS CLI installation path:
which aws
Check the installed version:
aws --version
Remove AWS CLI Installed via APT
sudo apt remove awscli
Remove AWS CLI Installed via AWS Installer
sudo rm -rf /usr/local/aws-cli
sudo rm -f /usr/local/bin/aws
Security Best Practices
When removing AWS credentials:
- Rotate credentials if they were exposed or shared.
- Use IAM roles whenever possible instead of long-term access keys.
- Regularly audit configured AWS profiles.
- Avoid storing credentials in scripts or source code repositories.
- Use AWS Secrets Manager or environment variables for sensitive workloads.
Conclusion
Removing AWS CLI configuration on Ubuntu is a straightforward process. Whether you need to clear credentials, delete a specific profile, or uninstall AWS CLI entirely, understanding where AWS stores its configuration helps maintain a secure and organized development environment. Regular credential management is an essential part of AWS security best practices and helps protect your cloud resources from unauthorized access.
Top comments (0)