Create a new user on EC2 and give sudo privileges

Writing by on Monday, 2 of May , 2016 at 10:00 pm

newhost.compute.internal is the new host you launched
ec2-user is the user created by EC2
newuser is the user you want created and need password-less ssh & sudo privileges
– is newuser’s public key

# Copy newuser’s to the new instance
scp -i ~/.ssh/my.pem ~/.ssh/ ec2-user@newhost.compute.internal:~

# Login to the newhost (and sudo as root)
ssh -i ~/.ssh/my.pem ec2-user@newhost.compute.internal
sudo su –

# add newuser and copy the keys
useradd -c “firstname lastname” newuser
cd /home/newuser
mkdir .ssh
cat /home/ec2-user/ >> .ssh/authorized_keys

# provide right ownership and permissions
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chown -R newuser:newuser /home/newuser

# give sudo access
vim /etc/sudoers

Leave a comment

Category: AWS

Determine size of an S3 bucket or folder

Writing by on Wednesday, 16 of March , 2016 at 6:01 pm

Ensure that you have awscli installed as well as your keys setup in ~/.aws/credentials

To determine the size of an S3 Bucket or a folder, you can summarize the output as follows.

aws s3 ls –summarize –human-readable –recursive s3://mybucket/directory/

2015-03-05 19:57:33 71 Bytes directory/sub1/sub2/file.gz

Total Objects: 71
Total Size: 81.9 MiB

To determine the size of an S3 Bucket, you can also use s3api list-objects as shown below.

aws s3api list-objects –bucket mybucket –output json –query “[sum(Contents[].Size), length(Contents[])]”

For more info refer to ServerFault

Leave a comment

Category: AWS

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.