"Server refused our key" when logging into Ubuntu on EC2 as a different user

5,140

Yes the keypair is tied to the ubuntu user. After you create the new users, you'll need to put the key you want to use in $HOME/.ssh/authorized_keys .. Its a little complicated, as you also need to make sure the $HOME/.ssh has secure permissions

chmod 0700 $HOME/.ssh

and that the authorized_keys file also has secure permissions

chmod 0600 $HOME/.ssh/authorized_keys

One trick is to just copy the ubuntu user's key file to the new users if you just want to use the same key.

sudo cp -arf /home/ubuntu/.ssh /home/myuser/.ssh
chown -R myuser.myuser /home/myuser/.ssh

If you setup a password for those new users (not recommended actually.. password brute force attacks of SSH servers are rampant on the internet) you can also do this from your client machine:

ssh-copy-id user@host

Which will handle all of the permissions for you. Also if you store your key in your Launchpad.net account, you can do

ssh-import-id your-launchpad-user

And it will pull your key from launchpad (this command was renamed to ssh-import-id in 11.04 and later).

Share:
5,140

Related videos on Youtube

Jennifer Simonds
Author by

Jennifer Simonds

Updated on September 18, 2022

Comments

  • Jennifer Simonds
    Jennifer Simonds over 1 year

    We created an AWS micro instance running Ubuntu 10.04, and we can putty in as the "ubuntu" user using the key pair just fine. Now I've created two new users, but when I try to putty into the instance using their usernames I get "Server refused our key".

    What's going on? Is the keypair tied to the ubuntu user? Also, do we have to create a keypair for these users, or can they log in using a password? Or do we need to always putty in as "ubuntu" and then "su - myusername"? Or am I just missing something simple?