$ run as a normal user# run as root (or with sudo)
The quick answer
aws configure sso
aws sso login --profile prod
export AWS_PROFILE=prod
aws sts get-caller-identity
{
"Account": "111122223333",
"Arn": "arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_ReadOnlyAccess_0123abcd/alice"
}Your admin gives you two values: the start URL (https://acme.awsapps.com/start) and the SSO region.
Step by step
- Use AWS CLI version 2 (version 1 from
apt/piphas no modern SSO):
aws --version
aws-cli/2.31.0 Python/3.13.7 Linux/6.12 exe/x86_64- Create the profile with the wizard (
aws configure sso) — or write it yourself. Onesso-sessionand one profile per account and role:
[sso-session acme]
sso_start_url = https://acme.awsapps.com/start
sso_region = eu-central-1
sso_registration_scopes = sso:account:access
[profile prod-read]
sso_session = acme
sso_account_id = 111122223333
sso_role_name = ReadOnlyAccess
region = eu-central-1
[profile dev-admin]
sso_session = acme
sso_account_id = 444455556666
sso_role_name = AdministratorAccess
region = eu-central-1Make the read-only role your daily default; use the admin profile only when you need it.
- Log in once per session — one login works for all profiles of the same
sso-session:
aws sso login --sso-session acme
aws s3 ls --profile prod-read
aws ec2 describe-instances --profile dev-admin --query 'Reservations[].Instances[].InstanceId'- On a server without a browser use the device code — open the URL on your laptop and type the code:
aws sso login --profile prod-read --use-device-code- Tools that use the same login: Terraform, kubectl (EKS), SDKs and scripts read
AWS_PROFILE— no keys needed:
- Log out at the end of the day, or on a shared machine:
aws sso logoutCheck that it worked
aws sts get-caller-identity shows the right account and an AWSReservedSSO_… role (not an IAM user), and ~/.aws/credentials has no long-lived keys any more:
Common problems
| Problem | Cause | Fix |
|---|---|---|
Error loading SSO Token: Token for … does not exist / has expired | Not logged in, or the session ended (1–12 h). | aws sso login --profile NAME. |
The config profile (prod) could not be found | Wrong name, or AWS_PROFILE points to an old profile. | aws configure list-profiles; echo $AWS_PROFILE. |
| Browser does not open on a server | No GUI. | --use-device-code. |
AccessDenied on a command | The role (permission set) does not allow it. | Use the right profile, or ask for a better permission set — not a personal access key. |
| Old static keys still win | AWS_ACCESS_KEY_ID env variables or [default] keys are set. | env | grep AWS_; remove the keys, then deactivate them in IAM. |
| Wrong region in the output | No region in the profile. | Add region = to the profile, or --region. |
Go further
- Command pages: aws.
- Next how-tos: Copy files to and from S3, Connect to EC2 without SSH keys, Get the kubeconfig of EKS, AKS or GKE, Rotate AWS access keys.
- Full guide: Install AWS CLI v2 and log in with SSO. At work: The aws CLI in daily DevOps, OIDC instead of keys in CI.
- Practise: Lab: multi-account guardrails with AWS Organizations.
1Why is SSO better than an access key in ~/.aws/credentials?
The credentials are short-lived and come from a browser login; there is no long-lived secret on disk to leak.
2How do you log in on a server that has no browser?
aws sso login --use-device-code and finish the login on another device.