-2

I create an azure ubuntu 1804 vm with no root user and ssh public key.

Then I try to use the script of how to enable root ssh public key login with no root account and sshpass and sudo?

But I got the problem of "Please login as the user "xx" rather than the user "root"

3
  • By the way, why azure want to forbidden me to ssh as root user? If I can not ssh root@xxx , how should I automatic manage my server? Looks like there is no other way more secure than ssh root@xxx with ssh public key with automatic management. Easy guess ssh username?
    – bronze man
    Nov 13, 2019 at 9:06
  • ssh as root is big no-no, from a security standpoint, so I'm thinking this is why you're getting that error, as Azure are trying to comply with basic security best practices.
    – schaiba
    Nov 13, 2019 at 9:07
  • @schaiba so what should I do it with automatic management? Write a tool that work as ssh -c xxx@xxx sudo 'xxx'? and make the username same again and again? that command just have too much escapes, I have to use a tool to escapes for me.
    – bronze man
    Nov 13, 2019 at 9:13

1 Answer 1

0
ssh -C -o StrictHostKeyChecking=no -o ConnectTimeout=10 xxxYourServerUsername@xxxYourServerIp 'sudo bash -c '"'"'umask 077 && mkdir -p .ssh && echo '"'"'"'"'"'"'"'"'xxxYourSshPublicKey'"'"'"'"'"'"'"'"' > /root/.ssh/authorized_keys'"'"''

Replace xxxYourServerIp with your server ip. Replace xxxYourServerUsername with your server username .Replace xxxYourSshPublicKey with your SshPublicKey content (should like ssh-rsa xxx root@xxx)

I think this is the secure and automatic way to do it, it should be secure then how to enable root ssh public key login with no root account and sshpass and sudo?

2

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.