17
votes

Installed Ubuntu Server LTS 14.04 from Azure library on Azure VM. Logged in as standard "azureuser" created by Azure with my password. Changed root password:

sudo passwd root

If I try to login as "root":

Access denied

What do I miss? And yes, the password is correct.

6

6 Answers

48
votes

Just run sudo -s, you will get the root terminal.

17
votes

by default, Ubuntu disables the root account. Since root is godmode, disabling it means that all of the hackers with automated scripts that try to break the root account are wasting their time.

I highly recommend against this. (There are many reasons, here are some: https://askubuntu.com/questions/16178/why-is-it-bad-to-login-as-root) However, the steps to do so are Over on askubuntu.com

According to that page, to unlock the root account you must execute sudo passwd -u root. To relock the root account, use sudo passwd -l root

To reiterate: this is kinda a bad idea. A better solution would be to create a new user that has unlimited permissions ONLY WITHIN THE SCOPE OF WHAT YOU REQUIRE. Root is godmode; if you screw something up too bad for you. An elevated user for your scope, on the other hand, would only be able to destroy what it has access to...not your entire system.

8
votes

To enter into a Azure VM using SSH...

First, You need to enable the root account:

#sudo passwd root

Then you need to enable the root login for ssh editing the file /etc/ssh/sshd_config (the default value in Azure VMs is PermitRootLogin without-password, so you need to change/comment it):

...
#PermitRootLogin without-password
PermitRootLogin yes
...

Finally, you need to reload/restart the ssh service:

#sudo service ssh reload
1
votes

It's easier just to do sudo <command>. Then you don't have the full terminal for the super user. This will just execute the command with root privileges. See this article.

0
votes

It's an old post but it happens sometimes. Here is what I solved after research.

sample log

$ azure vm extension set hm hm  CustomScript Microsoft.Azure.Extensions 2.0 --auto-upgrade-minor-version  -i '{"commandToExecute": "cp /tmp/sudoers.org /etc/sudoers"}' info:    Executing command vm extension set
+ Looking up the VM "hm"
+ Installing extension "CustomScript", VM: "hm" info:    vm extension set command OK

For macOS user, here is simple steps. (at least you need node installed)

npm install -g azure-cli
azure login
azure config mode arm  

or asm, depends on your VM

azure vm list    

change mode if no VM listed

copy sudoers file from other machine to /tmp/sudoers.default of you target machine

backup sudoers

azure vm extension set hm hm  CustomScript Microsoft.Azure.Extensions 2.0 --auto-upgrade-minor-version  -i '{"commandToExecute": "cp /etc/sudoers /tmp"}'

copy default sudoers to /etc/sudoers

azure vm extension set hm hm  CustomScript Microsoft.Azure.Extensions 2.0 --auto-upgrade-minor-version  -i '{"commandToExecute": "cp /tmp/sudoers.default /etc/sudoers"}'
0
votes

I wasn't able to get any of the other answers to work for me, but this answer worked for my case.

For those too lazy to click the link:

ssh -i KEYPAIR.pem ubuntu@HOSTNAME   'sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'