2

I launched an Ubuntu 18 instance on EC2.

I connected to the server using ubuntu user.

I created a new user named newuser and added it to the sudo group.

Then I ran:

rsync --archive --chown=newuser:newuser ~/.ssh /home/newuser

in order to let the new user to connect to the server directly.

When I'm trying to connect to the server using the new user I'm getting the following error:

Using username "newuser".

Authenticating with public key "imported-openssh-key"

Please login as the user "ubuntu" rather than the user "root".

I get the same error from both MobaXterm and PuTTY.

  • Is there a ~/.ssh/config file that may be setting the remote user to root for SSH? – steeldriver Jul 8 at 22:08
  • @steeldriver no, there is one file in ~/.ssh/ which its name is authorized_keys – Alon Jul 9 at 9:11
  • Related can't sign on as root – WinEunuuchs2Unix Jul 10 at 0:32
3

there is a command inside authorized_keys as follows.

cat /root/.ssh/authorized_keys 
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10"

remove this line and keep the ssh-rsa and key that comes after it.

save the file then try again.

  • I have edited the file and even rebooted but I'm still getting the same error. – Alon Jul 10 at 14:27
3

As tritium_3 suggested, I had to edit .ssh/authorized_keys, to remove the following text:

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10"

and keep the ssh-rsa and key that comes after it.

However, the rsync command had copied the file to the new user, so I had to edit the file that was under /home/newuser/.ssh/authorized_keys rather than /root/.ssh/authorized_keys.

  • Yes, but I'm still concerned how that was auto added? I almost locked myself out of my machine. – jonincanada Nov 9 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.