The following forum(s) have migrated to Microsoft Q&A (Preview): Azure Virtual Machines!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Remote Powershell for Linux VM RRS feed

  • Question

  • Hi All,

    I wrote a script to create a Linux VM(Ubuntu) in azure. That script also includes to install some software in the VM once it starts. These two are automated in Powershell. I used some SSH.Net libraries to take the remote session using New-Sshsession and Invoke-SshCommand to execute the commands.

    But while installing getting the problem with root password. I could not able to pass the password and if i want to pass the password i need to include it for each command that i want to execute as sudo. For Windows VM it is working fine, but for Linux VMs getting problems to install the software as sudo.

    Please provide any solution

    Thanks,

    Bhaskar.

    Monday, April 14, 2014 10:03 AM

Answers

  • Hi,

    Based on my experience, you can specify the SSHpublickeys when creating the Linux VMs in Azure, however, it is neccessary to specify the name and the password for the VM at the same time. It seems that you can only do that via Windows Azure portal.

    Best regards,

    Susie

    Wednesday, April 16, 2014 9:33 AM
  • I think I can answer at least part of your question - You can definitely create VM's using PowerShell scripts, and there are 2 articles that might help you get started on this:

    http://blogs.msdn.com/b/rmattsampson/archive/2014/04/03/azure-development-in-the-azure-sdk-2-3-and-update-2-rc.aspx

    http://msdn.microsoft.com/library/azure/dn642480.aspx

    Basically, using the Azure Powershell Cmdlets you can provision any type of VM that you want (you need to know the OS identifier before you provision, but you can get all of those using the Azure PowerShell Cmdlets.  Then once you've provisoned the machine, you can use PowerShell DSC to run some additional setup steps, like so:

    http://blogs.msdn.com/b/powershell/archive/2014/02/28/want-to-automatically-configure-your-machines-using-dsc-at-initial-boot-up.aspx

    Does this help?


    R. Matt Sampson

    Friday, April 18, 2014 2:21 PM

All replies

  • Hi,
    Thanks for your question.
    Based on my research, if the virtual machine was provisioned with either a certificate as well as a password, or just a user name and password. In this case sudo will prompt for the user's password before executing the command. Did you mean that you could not set the root password by running “$ sudo passwd root”? I would appreciate it if you can provide the commands you ran. In addition, it seems that you need to type sudo before the commands if you want to run commands with elevated privileges.

    More information:

    Install software on your Linux virtual machine in Azure

    Best regards,
    Susie

    Tuesday, April 15, 2014 8:52 AM
  • Hi Susie,

    Actually I want to automate the process through the powershell like provisioning and installing some software on that. This should be automated. The final out put is the VM running with that software. For changing the root pass word also requires the password when i run with sudo. So how can I pass the password in secure manner or a Key based authentication to execute the commands as the root user on privisioned VM through powershell. Passing the password for each command is not secure in real scenario. Even when I pass the password to New-SshSession is also a security concern with SSH port. Is there any way to create to Linux VM without password using powershell cmdlets, So that we can use only Key based authentication.

    Is any solution to install a software a Linux VM without manul intervention using Powershell in elevated mode.

    Tuesday, April 15, 2014 1:51 PM
  • Hi,

    In the azure portal we can able to create a linux machine, but why can't we create the same with Powershell. I was trying to create a Linux Vm through Powershell without Password and SSHPublic Keys, but It was showing error like "UserPassword is required"

    Is there anyway to create a Linux VM without password but with SSHPublickeys switch.

    Thanks and Regards

    Bhaskar.D.

    Tuesday, April 15, 2014 6:05 PM
  • Hi,

    Based on my experience, you can specify the SSHpublickeys when creating the Linux VMs in Azure, however, it is neccessary to specify the name and the password for the VM at the same time. It seems that you can only do that via Windows Azure portal.

    Best regards,

    Susie

    Wednesday, April 16, 2014 9:33 AM
  • I think I can answer at least part of your question - You can definitely create VM's using PowerShell scripts, and there are 2 articles that might help you get started on this:

    http://blogs.msdn.com/b/rmattsampson/archive/2014/04/03/azure-development-in-the-azure-sdk-2-3-and-update-2-rc.aspx

    http://msdn.microsoft.com/library/azure/dn642480.aspx

    Basically, using the Azure Powershell Cmdlets you can provision any type of VM that you want (you need to know the OS identifier before you provision, but you can get all of those using the Azure PowerShell Cmdlets.  Then once you've provisoned the machine, you can use PowerShell DSC to run some additional setup steps, like so:

    http://blogs.msdn.com/b/powershell/archive/2014/02/28/want-to-automatically-configure-your-machines-using-dsc-at-initial-boot-up.aspx

    Does this help?


    R. Matt Sampson

    Friday, April 18, 2014 2:21 PM