9

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.

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

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.

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

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.

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

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!

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.