Advanced
Searching inInstall guides
How to search
  • Paste an error message in quotes, e.g. "permission denied", to find the fix table that explains it.
  • Choose an area and a part of the guide (install, first settings, daily use, security, fixes) to go straight to the right step.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Guide 10AWS CLI · Cloud

Install and set up the AWS CLI

The AWS CLI (aws) manages everything in Amazon Web Services from the terminal: S3 files, EC2 servers, EKS clusters, logs, IAM and more. Scripts, CI pipelines and Terraform use the same login. This guide installs AWS CLI version 2 on RHEL and Ubuntu, sets up a safe login with IAM Identity Center (SSO) and profiles, and shows the daily commands and the fixes for login and permission errors.

  • 8 Lessons
  • 14 Commands

$ run as a normal user# run as root (or with sudo)

10.1

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.

ItemValue
VersionAWS 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
EnvironmentAWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID … (they win over the files)
NetworkHTTPS (443) to the AWS endpoints

10.2

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 unzip

Then 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.10

For 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.

10.3

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]: prod

This writes your profile:

~/.aws/config
[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"
}
SettingWhy
One profile per account and roleprod, dev, audit — you always know where a command goes.
regionThe default region; change one command with --region.
output = jsonBest 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" >> ~/.bashrc

Note

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).

10.4

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 3600

EC2, 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-0abc123def4567890

Logs, 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 list

Real 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).

10.5

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 with gitleaks.
  • Check before you act: aws sts get-caller-identity, --dry-run on EC2 changes.
  • Rotate any old access keys: aws iam list-access-keys.
  • CloudTrail on in every account, so every API call is logged.

10.6

Update and remove

Download the zip again and run the installer with --update:

curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip -qo awscliv2.zip
./aws/install --update

Remove it:

rm /usr/local/bin/aws /usr/local/bin/aws_completer
rm -rf /usr/local/aws-cli
rm -rf ~/.aws

10.7

Fix common problems

ProblemCauseFix
Unable to locate credentialsNo profile or no login.aws configure sso / aws sso login; export AWS_PROFILE=….
The SSO session associated with this profile has expired / ExpiredTokenSSO credentials last only some hours.aws sso login --sso-session acme.
AccessDenied … is not authorized to performThe 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 existsWrong 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 --updatev2 is already installed../aws/install --update.
SSL validation failed behind a company proxyThe proxy CA is unknown.export AWS_CA_BUNDLE=/etc/pki/ca-trust/source/anchors/corp.pem.

10.8

Next steps

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.

All commands in this chapter