First, log in as the ec2-user:
ssh -i yourkey.pem ec2-user@host
Then use sudo to run the required commands, for example, to edit the files in /etc/hosts file which is owned by root which obviously requires root privileges: sudo nano /etc/hosts
Also, to avoid typing sudo every time, use sudo su to become a superuser with root privileges