Forum Discussion

GirishPrabhudesai's avatar
GirishPrabhudesai
Copper Contributor
Oct 07, 2024

Azure powershell Set-AzStorageLocalUser - how to use existing ssh key in azure?

I am trying to build powershell script to create a local user for sftp in the Azure Stroage account.

We have ssh keys already created in Azure. When the local user is created, existing ssh key created in azure should be assigned to the user. This can be easily done through Azure portal.

However, we are looking for the same option in the powershell commandlet.

Set-AzStorageLocalUser has option for "sshAuthorizedKey", but there is no option to select existing key.

Do we know how this can be achieved?

 

 

  • balasubramanim's avatar
    balasubramanim
    Oct 08, 2024

    GirishPrabhudesai 

     

    Please try these steps.


    1. Get the SSH Key: You need to manually retrieve the SSH key from Azure.
    2. Base64 Encode the Key: Convert the SSH key into Base64 format to ensure it's properly formatted.
    3. Use the Key: Finally, use the Set-AzStorageLocalUser command to assign the SSH key to your new local user.

     

    There is no built-in PowerShell command to directly pull and assign an existing SSH key automatically like you can in the Azure Portal. You have to handle it in these steps.

     

    Reference URL: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/mac-create-ssh-keys

     

    Many Thanks

    Balasubramani.M

  • GirishPrabhudesai 

     

    To use an existing SSH key for creating a local SFTP user in Azure Storage with PowerShell, Please try these steps.

     

    1. Get Your Storage Account: First, find the storage account where you want to create the local user.

    2. Retrieve the SSH Key: List the existing SSH keys associated with your storage account.

    3. Create a Local User: Use the key you retrieved to create a new local user.

    Reference URL: 

    1. Set-AzStorageLocalUser (Az.Storage) | Microsoft Learn

    2. Get-AzStorageAccount (Az.Storage) | Microsoft Learn

    • GirishPrabhudesai's avatar
      GirishPrabhudesai
      Copper Contributor

      balasubramanim Thank you for the reply. 

      We are expecting the option to handle the pulling and assigning the key by Azure powershell command, similar to the Portal UI. 

      Do we have that option ?

      In case, our powershell script need to do it, there are 3 steps

      1. Pull the ssh key from Azure SSH keys

      2. Base 64 encrypt the key

      3. Upload the key with the Set-AzStorageLocalUser command. 

      This has possibility of error in the format, encryption etc. 

       

      • balasubramanim's avatar
        balasubramanim
        Iron Contributor

        GirishPrabhudesai 

         

        Please try these steps.


        1. Get the SSH Key: You need to manually retrieve the SSH key from Azure.
        2. Base64 Encode the Key: Convert the SSH key into Base64 format to ensure it's properly formatted.
        3. Use the Key: Finally, use the Set-AzStorageLocalUser command to assign the SSH key to your new local user.

         

        There is no built-in PowerShell command to directly pull and assign an existing SSH key automatically like you can in the Azure Portal. You have to handle it in these steps.

         

        Reference URL: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/mac-create-ssh-keys

         

        Many Thanks

        Balasubramani.M

Resources