I can't ssh to my Amazon AWS Ubuntu instance using a newly created user and a key pair?

Solution 1:

You seem to have a misunderstanding about the public key you upload to the server.

This key must be stored in the file ~/.ssh/authorized_keys for every user that should be identified by this key.

This path ~/.ssh/authorized_keys is equivalent to your current user directory, if you are logged in as grader user, that path will point to:

/home/grader/.ssh/authorized_keys

In case you are logged in as ubuntu user, that path will point to:

/home/ubuntu/.ssh/authorized_keys

So for now you could copy the key file with:

sudo cp /home/ubuntu/.ssh/authorized_keys /home/grader/.ssh/

Then set the correct owner and permissions:

sudo chown grader:grader /home/grader/.ssh/authorized_keys
sudo chmod 0600 /home/grader/.ssh/authorized_keys

Keep in mind that now you accept all keys that you might have enabled for the user ubuntu for the user grader as well.