Cloud and deployment · Beginner · 14 min
Set up the AWS CLI v2 with IAM Identity Center sign-in and named profiles
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 or macOS · AWS CLI 2.42.4
You will have AWS CLI 2.42.4 installed from a signature-checked bundle, signing in through IAM Identity Center with separate dev and prod profiles and no long-lived access keys on your machine.
On this page
The AWS CLI needs credentials for every call. The old way is an access key pair saved in ~/.aws/credentials: two strings that never expire, sit in plain text in your home folder, and get copied into backups, dotfiles repositories and screenshots. Anyone who finds them can act as you until somebody notices and deletes the key.
IAM Identity Center (the service that used to be called AWS SSO) removes that file from the picture. You sign in through a browser, the CLI caches a short-lived token, and it swaps that token for temporary credentials when a command runs. When the session ends, the credentials stop working on their own.
In this tutorial you install AWS CLI 2.42.4, check the download is really from AWS, sign in through Identity Center, and set up two named profiles: dev for day-to-day work and prod for the account you want to touch with more care. The commands are for Ubuntu 26.04; the install step also shows macOS, and everything after it is the same on both.
Step 1 · Install the AWS CLI from the signed bundle
AWS publishes the CLI as a zip bundle with a detached PGP signature next to it. Check the signature before you run the installer, so a tampered or half-downloaded file never gets executed.
On Ubuntu, install the tools you need, then create a working folder:
sudo apt update
sudo apt install -y curl unzip gpg ca-certificates
cd "$(mktemp -d)"Save the AWS CLI Team public key. This is the key block printed on AWS's install page; it expires on 1 July 2027, so if gpg later reports it as expired, copy the current block from that page instead:
cat > aws-cli-team.asc <<'EOF'
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG
ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx
PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G
TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz
gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1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j6Z0SrCkJujhWk3IBPic/wJgz01LEc/OAdUPlby90RJZcIBhSlWhT7mXnXIO
c0HWlNQrns2s3CTyYwZSiSlYe9ApeLwhjDo8NhbFuCAy61l6O5UsR4AfZxx/rGKv
2wFb1/RN/P4gNe6vmxZAPjR0AQcwD3tc2McimOLr/22kmPz8IH3I0X7WoSFr0Biz
E91G7bb0hOb/cA==
=knv7
-----END PGP PUBLIC KEY BLOCK-----
EOF
gpg --import aws-cli-team.asc
gpg --fingerprint A6310ACC4672475CCompare the fingerprint gpg prints with the one on AWS's page: FB5D B77F D5C1 18B8 0511 ADA8 A631 0ACC 4672 475C. A key that imports is not proof by itself; matching the fingerprint is.
Download version 2.42.4 and its signature. uname -m prints x86_64 or aarch64, which matches AWS's file names. The zip is about 75 MB, so if you are on metered or prepaid mobile data, do this on Wi-Fi:
VERSION=2.42.4
curl -fsSLo awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m)-${VERSION}.zip"
curl -fsSLo awscliv2.sig "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m)-${VERSION}.zip.sig"
gpg --verify awscliv2.sig awscliv2.zipLook for Good signature from "AWS CLI Team <aws-cli@amazon.com>". The lines that follow, WARNING: This key is not certified with a trusted signature!, are expected: they mean you have not personally signed AWS's key, not that the file is bad. If you see BAD signature, delete both files and download again. Only then unpack and install:
unzip -q awscliv2.zip
sudo ./aws/install
aws --versionIf the installer stops with a message about an existing installation, you already have a v2 CLI; add --update to the install command. This install does not come from apt, so apt upgrade will never update it. To move to a newer release later, repeat this step with the new version number and run sudo ./aws/install --update.
On macOS, the .pkg installer carries a macOS package signature instead of a PGP file. Download the same version, look at its signature, then install it for all users:
curl -fsSLo AWSCLIV2.pkg "https://awscli.amazonaws.com/AWSCLIV2-2.42.4.pkg"
pkgutil --check-signature AWSCLIV2.pkg
sudo installer -pkg AWSCLIV2.pkg -target /
aws --versionpkgutil should report a signed package with a certificate chain naming Amazon, something like Developer ID Installer: Amazon.com Services LLC. If it says no signature, do not install it.
Check it worked
aws --version prints a line starting aws-cli/2.42.4, followed by the Python version bundled with the CLI and your operating system.
Step 2 · Look for access keys already on this machine
Before adding anything, see what the CLI would use right now. aws configure list walks the same lookup order every command uses: command-line options, environment variables, then the files in ~/.aws:
aws configure list
ls -la ~/.aws 2>/dev/null || echo "No ~/.aws folder yet"On a fresh machine every value shows <not set>. If the access_key row shows a masked value with the type shared-credentials-file, there is a long-lived key in ~/.aws/credentials. Keep it for now so nothing breaks, finish this tutorial, then delete the key in the IAM console (or ask whoever issued it) and remove the file. If the type is env, the key comes from AWS_ACCESS_KEY_ID in your shell profile; remove that line too.
Check it worked
You know which of two cases you are in: no credentials at all, or a key you now plan to retire. Write down the access key ID's last four characters if there is one, so you can find it in IAM later.
Step 3 · Sign in once with aws configure sso
Get two values from your AWS access portal or your administrator: the start URL (it looks like https://d-1234567890.awsapps.com/start or a custom address) and the Region where your Identity Center lives. Then run the wizard:
aws configure ssoAnswer the prompts like this, replacing the URL with yours:
SSO session name (Recommended): my-team
SSO start URL [None]: https://d-1234567890.awsapps.com/start
SSO region [None]: eu-west-1
SSO registration scopes [sso:account:access]:The scopes prompt already shows sso:account:access as its default, so press Enter to accept it (typing the value also works).
The CLI opens your browser. Sign in with your usual company login, then approve the request; the approval screen names the client botocore-client-..., which is the CLI. Back in the terminal, pick your development account from the list, then the role (the permission set your administrator assigned, for example PowerUserAccess). Finish with these answers:
Default client Region [None]: eu-west-1
CLI default output format (json if not specified) [None]: json
Profile name [PowerUserAccess-111122223333]: devIf you are working over SSH on a machine with no browser, run aws configure sso --use-device-code instead. It prints a URL and a short code you can open on your phone or laptop.
The wizard writes everything to ~/.aws/config. Read it:
cat ~/.aws/configThere are two sections. [sso-session my-team] holds how to sign in: the start URL and the Identity Center Region. [profile dev] holds what to sign in as: one account ID, one role name, and your defaults for that profile. There is no secret anywhere in the file.
Check it worked
ls ~/.awsYou see config, and after the browser sign-in an sso folder, which holds the cached token. There is no credentials file unless one was there before.
Step 4 · Add a prod profile that reuses the same sign-in
You do not need to run the wizard again for a second account. A new profile can point at the same sso-session, so one browser sign-in covers both. Add prod to the end of the file. Replace 444455556666 with your production account ID and ReadOnlyAccess with the role you were given there; ask for a read-only role in production if you only need to look:
cat >> ~/.aws/config <<'EOF'
[profile prod]
sso_session = my-team
sso_account_id = 444455556666
sso_role_name = ReadOnlyAccess
region = eu-west-1
output = table
EOFoutput = table is deliberate: production output looks different on screen, which is a small extra cue about where you are.
If your users are mostly in Africa, the Cape Town Region, af-south-1, is the closest. It is an opt-in Region, so an account administrator has to enable it before any command there works; until then, keep eu-west-1 or whichever Region your team uses.
Check it worked
aws configure list-profiles
aws configure get sso_account_id --profile prod
aws configure get output --profile prodlist-profiles prints dev and prod (in file order), then 444455556666 and table. aws configure get reads the file only, so it works before you sign in.
Step 5 · Set defaults for commands that name no profile
Commands without --profile use a profile called default. Give it a Region and an output format, but no account or role. That way a forgotten --profile fails with an error such as "Unable to locate credentials" instead of quietly running against an account:
aws configure set region eu-west-1
aws configure set output jsonaws configure set edits ~/.aws/config in place and adds a [default] section if there is none, so it is safe to run on a file you already have.
Check it worked
aws configure listThe output has four rows, something like:
NAME : VALUE : TYPE : LOCATION
profile : <not set> : None : None
access_key : <not set> : None : None
secret_key : <not set> : None : None
region : eu-west-1 : config-file : ~/.aws/configThe Region comes from the file and there are no keys, which is what you want for the default profile.
Step 6 · Sign in and confirm who you are
The wizard signed you in once. When the session expires (your administrator sets how long it lasts), sign in again with the session name. One sign-in serves every profile that uses my-team:
aws sso login --sso-session my-teamNow ask AWS who each profile is:
aws sts get-caller-identity --profile dev
aws configure list --profile devCheck it worked
get-caller-identity returns JSON something like this, with your own account and email:
{
"UserId": "AROAEXAMPLEID:you@example.com",
"Account": "111122223333",
"Arn": "arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_PowerUserAccess_0123456789abcdef/you@example.com"
}The ARN says assumed-role, not user: you are using temporary role credentials. aws configure list --profile dev now shows a masked access key with the type sso. That key lives in a cache, not in any file you maintain, and it expires on its own. If either command says the token has expired or does not exist, run aws sso login --sso-session my-team again.
Step 7 · Switch between dev and prod
There are two ways to choose a profile. --profile applies to one command:
aws s3 ls --profile prodAWS_PROFILE applies to every command in the current terminal until you close it or unset it:
export AWS_PROFILE=prod
aws configure get sso_role_name
unset AWS_PROFILE
aws configure get sso_role_name --profile devA --profile on the command line wins over AWS_PROFILE. A good habit: leave AWS_PROFILE set to dev in your shell profile if you like, but never to prod. Name prod explicitly on each command that needs it, so production work is always a choice you can see in your history.
Check it worked
The first aws configure get prints ReadOnlyAccess (the prod role), and the second prints PowerUserAccess (the dev role). After you sign in, aws sts get-caller-identity --profile prod shows the production account ID, and with --profile dev the development one.
Step 8 · Sign out and remove old keys
When you finish for the day, or on a shared computer, end the session. This removes the cached sign-in token and the temporary credentials the CLI saved from it:
aws sso logoutIf the second step found a key in ~/.aws/credentials, now is the time to retire it. Confirm your SSO profiles work first, then delete the access key in the IAM console under your user's security credentials. Delete the local file only after that, so you do not lose track of which key it held:
rm ~/.aws/credentialsCheck it worked
After aws sso logout, aws sts get-caller-identity --profile dev fails with an error saying you need to sign in again, and ls ~/.aws shows config with no credentials file. Your profiles are intact; the next aws sso login --sso-session my-team brings both back.
Next steps
- Use the
devprofile to create and reach a server in /tutorials/launch-an-ec2-instance-and-connect. - Learn what the roles behind your profiles can and cannot do in /tutorials/understand-aws-iam-users-groups-and-roles.
- Put a site on AWS with the CLI you just set up in /tutorials/host-a-static-site-on-s3-and-cloudfront.
- Keep Terraform state in S3 with the same profiles in /tutorials/terraform-1-17-remote-state-on-s3.
Related tutorials
- Write, test and deploy an AWS Lambda function in Node.jsYou will have a tested Node.js 26 function running on AWS Lambda with its own logs-only role, tuned memory, timeout and environment variables, and a published version behind a live alias you can move forward or roll back.
- Understand AWS VPCs: subnets, route tables, gateways and NATYou will have built a two-zone VPC with public and private subnets, an internet gateway, a NAT gateway and a free S3 endpoint using the AWS CLI, read every route table to see which subnets are public and why, and then deleted it all.
- Share private S3 files safely with presigned URLsYou will keep an S3 bucket private and still let browsers download and upload files through short-lived presigned URLs, with type and size limits, CORS and logs that never hold a working link.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials