简体   繁体   中英

aws ec2 instance - permission denied to write to ~/.aws/credentials

When ssh into a aws ec2 linux instance, the user is ec2-user by default. Then I need to set aws credentials by writing to ~/.aws/credentials , but got permission denied. I feel that if I use sudo then the credentials file would be owned by root user, as a result my api server can't read from it.

What's the correct approach to set up aws credentials there?

The 'correct' way to setup the credentials, is to assign a role to the ec2 instance when you create it (or assign them after you create it). That role can be created and assigned to the EC2 instance via the AWS console - there is no need to ssh in and create the credentials there.

See: Easily Replace or Attach an IAM Role to an Existing EC2 Instance by Using the EC2 Console | AWS Security Blog

You can create the credentials file locally, then upload to your ec2 instance.

  1. create the credentials file locally
$ vim credentials
  1. upload to your ec2 instance
$ scp /path/credentials username@servername:/path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM