Root login Ubuntu VM on Azure

后端 未结 6 1693
情深已故
情深已故 2021-02-02 13:38

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:

s         


        
相关标签:
6条回答
  • 2021-02-02 14:13

    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/'
    
    0 讨论(0)
  • 2021-02-02 14:14

    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 讨论(0)
  • 2021-02-02 14:19

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

    0 讨论(0)
  • 2021-02-02 14:25

    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.

    0 讨论(0)
  • 2021-02-02 14:27

    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
    
    0 讨论(0)
  • 2021-02-02 14:31

    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 讨论(0)
提交回复
热议问题