$ run as a normal user# run as root (or with sudo)
Know it before you install
Every aws command is one signed API call. The CLI needs who you are (credentials), where (region) and how to show the answer (output). These live in a profile.
| Item | Value |
|---|---|
| Version | AWS CLI v2 (v1 is old; do not use the awscli package of the distribution) |
| Install folder | /usr/local/aws-cli/, links in /usr/local/bin/aws and aws_completer |
| Config | ~/.aws/config (profiles, region, SSO) |
| Static keys | ~/.aws/credentials — avoid when you can |
| Environment | AWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID … (they win over the files) |
| Network | HTTPS (443) to the AWS endpoints |
Install on Linux (RHEL and Ubuntu)
AWS ships one installer for all distributions. Install unzip first:
dnf -y install unzip
apt-get update && apt-get install -y unzipThen download, unpack and install:
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip -q awscliv2.zip
./aws/install
You can now run: /usr/local/bin/aws --version
aws --version
aws-cli/2.31.18 Python/3.13.7 Linux/6.12.0 exe/x86_64.rhel.10For ARM servers (Graviton) use awscli-exe-linux-aarch64.zip. On Ubuntu you can also use snap install aws-cli --classic.
Watch out
Do not install awscli with apt or pip for new work — that is version 1. It has no SSO login and different behaviour.
First configuration: log in with SSO
The best way for people: IAM Identity Center (SSO). You get short-lived credentials, no keys on disk. Your admin gives you the start URL and the SSO region.
aws configure sso
SSO session name (Recommended): acme
SSO start URL [None]: https://acme.awsapps.com/start
SSO region [None]: eu-central-1
SSO registration scopes [sso:account:access]:
CLI default client Region [None]: eu-central-1
CLI default output format [None]: json
CLI profile name [AdministratorAccess-123456789012]: prodThis writes your profile:
[sso-session acme]
sso_start_url = https://acme.awsapps.com/start
sso_region = eu-central-1
sso_registration_scopes = sso:account:access
[profile prod]
sso_session = acme
sso_account_id = 123456789012
sso_role_name = ReadOnlyAccess
region = eu-central-1
output = json
cli_pager =Use it — and always check who you are first:
aws sso login --sso-session acme
export AWS_PROFILE=prod
aws sts get-caller-identity
{
"UserId": "AROAEXAMPLE:alice",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/AWSReservedSSO_ReadOnlyAccess_abc/alice"
}| Setting | Why |
|---|---|
| One profile per account and role | prod, dev, audit — you always know where a command goes. |
region | The default region; change one command with --region. |
output = json | Best for scripts (with --query or jq); table is easier to read. |
cli_pager = (empty) | No less pager — scripts and CI do not hang. |
Turn on completion:
echo "complete -C '/usr/local/bin/aws_completer' aws" >> ~/.bashrcNote
Only when SSO is not possible: aws configure asks for an access key. Use an IAM user with the least rights and rotate the key. On EC2, ECS, EKS and Lambda, use IAM roles — the CLI finds those credentials by itself, no keys at all. In CI, use OIDC roles (GitHub Actions, GitLab).
Daily use: the commands and the real uses
S3:
aws s3 ls
aws s3 cp backup.tar.gz s3://acme-backups/web1/
aws s3 sync ./site s3://acme-site --delete
aws s3 presign s3://acme-backups/web1/backup.tar.gz --expires-in 3600EC2, filtered with --query (JMESPath):
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[].Instances[].[InstanceId,InstanceType,PrivateIpAddress,Tags[?Key==`Name`]|[0].Value]' --output table
aws ec2 stop-instances --instance-ids i-0abc123def4567890 --dry-run
aws ssm start-session --target i-0abc123def4567890Logs, EKS and identity:
aws logs tail /aws/lambda/orders --follow --since 15m
aws eks update-kubeconfig --region eu-central-1 --name prod
aws iam list-roles --query 'Roles[].RoleName' --output text
aws configure listReal uses at work:
- Backups and file sync to S3 from servers and pipelines.
- Inventory and reports: which servers run, which buckets are public, which keys are old.
- Log in to servers with SSM Session Manager — no open SSH port.
- Get the kubeconfig of EKS for
kubectl; give Terraform the same profile (AWS_PROFILE).
Make it safe
Security checklist:
- No access keys for the root user. MFA on every human login.
- SSO with short-lived credentials for people; IAM roles for servers; OIDC for CI.
- Least privilege: read-only profiles for daily work, admin only when needed.
- Never commit
~/.aws/or keys; scan repos withgitleaks. - Check before you act:
aws sts get-caller-identity,--dry-runon EC2 changes. - Rotate any old access keys:
aws iam list-access-keys. - CloudTrail on in every account, so every API call is logged.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Unable to locate credentials | No profile or no login. | aws configure sso / aws sso login; export AWS_PROFILE=…. |
The SSO session associated with this profile has expired / ExpiredToken | SSO credentials last only some hours. | aws sso login --sso-session acme. |
AccessDenied … is not authorized to perform | The role has no right for this action. | aws sts get-caller-identity — right account and role? Ask for the permission. |
| Empty result, but you know the resource exists | Wrong region or account. | --region eu-central-1; check AWS_PROFILE. |
aws: command not found | /usr/local/bin is not on the PATH (often with sudo). | export PATH=$PATH:/usr/local/bin, or use the full path. |
found existing installation … use --update | v2 is already installed. | ./aws/install --update. |
SSL validation failed behind a company proxy | The proxy CA is unknown. | export AWS_CA_BUNDLE=/etc/pki/ca-trust/source/anchors/corp.pem. |
Next steps
- Quick how-tos: Log in with SSO, Copy files to and from S3, Find public S3 buckets, EC2 without SSH keys, Budget alerts, CloudTrail, Rotate access keys.
- Command pages: aws, eksctl.
- The AWS CLI at work: Manage AWS, AWS CLI in DevOps.
- Build AWS with code: Install and set up Terraform. Use EKS: Install and set up kubectl.
- Go deeper: AWS Solutions Architect Professional.
1Why is SSO better than aws configure with an access key?
SSO credentials are short-lived and not stored as a long-lived key on disk. A stolen key works until someone deletes it.
2What is the first command to run before a change in an AWS account?
aws sts get-caller-identity — to check the account and role.