Please login as the user “ubuntu” rather than the user “root”

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.


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.


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.


The proper way to address this is by using ssh's -l flag. Not by tampering with warning messages.

Example:

Not working:

$ sudo ssh -i *path/xxxxx.pem* n.n.n.n
Please login using xxxxx

Working:

$ sudo ssh -i keys/xxxxxx n.n.n.n -l ubuntu
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-1021-aws x86_64)

Note: You are elevating your permission to execute access to the .pem file. Which means you are probably 'root'. The SSH connection wants you to login with that machine's user name in this case "ubuntu". So, passing the "-l" flag allows us to set that value.

Hope this helps!