Skip to main content

Solving SSH connection issue with Linux Virtual Machine in Azure


I created a Linux Virtual Machine in Azure, but connecting to it through SSH was a real nightmare. I was always getting the below error -

"Permission denied (publickey)." 

After lot of googling, binging and shooting in the dark, this is how I fixed the problem:

  • Create a new ssh key by running below command. 
          PS: Do not change the default name or path of generated ssh key.
          ssh-keygen -t rsa -b 2048

          Generating public/private rsa key pair.
          Enter file in which to save the key (/c/Users/<Username>/.ssh/id_rsa):
          Enter passphrase (empty for no passphrase):
          Enter same passphrase again:
          Your identification has been saved in /c/Users/
<Username>/.ssh/id_rsa.
          Your public key has been saved in /c/Users/
<Username>/.ssh/id_rsa.pub


  • In Azure portal. Click on your Virtual Machine name, 
    • Select 'Reset Password -> 'Reset SSH' -> 'Reset SSH public key'
    • Type Username for VM
    • Open 'id_rsa.pub' public key in an editor, copy it's content and paste it in SSH public key text box.  
                    PS: Remember to remove any blank space from the pasted content.

  • Now try connecting again to VM from command line tool such as Git Bash
    • ssh <user>@<public_ip_of_your_linux_vm>
    • It worked! This time I saw the below output.
                 Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.15.0-1014-azure x86_64)

                 * Documentation:  https://help.ubuntu.com
                 * Management:     https://landscape.canonical.com
                 * Support:        https://ubuntu.com/advantage

                  Get cloud support with Ubuntu Advantage Cloud Guest:
                  http://www.ubuntu.com/business/services/cloud

                  0 packages can be updated.
                  0 updates are security updates
                  .......................
                  .......................



 

Comments

Popular posts from this blog

Solving PyCharm bug: "Python helpers are not copied yet..."

I have been using PyCharm Professional to run and debug Python code from my Windows machine to a remote Linux device. There are some other tools available for the same purpose (e.g. Python Tool for Visual Studio 2017). But in my opinion, PyCharm Professional stands out among its counterparts as it comes with a "All Batteries Included" setup. Once you configure remote Python interpreter in PyCharm, then it works out of the box. However, today after upgrading to PyCharm Professional 2018.2.1, I could not run my Python script on remote device. The execution always failed with below error - "Error running 'hello': Python helpers are not copied yet to the remote host. Please wait until remote interpreter initialization finishes." To solve this issue, I had to remove the ".pycharm_helpers " folder from the remove device and then restart PyCharm so that the folder is re-created and files are copied again. Here are the steps with comma...

Customized Crosshair with OxyPlot charting library

I am using Oxyplot to draw heatmap for a WPF project and needed to draw a crosshair that moves according to user clicks. Since I couldn't find any good example or documentation on the topic, I made a small hack by using LineAnnotations and by over-riding Oxyplot mouse click event. Here is the sample code using WPF with MVVM pattern- MainWindow.xaml <Grid>         <oxy:Plot x:Name="CrossHairPlot">             <oxy:Plot.Axes>                 <oxy:LinearAxis Key="MyXAxis" Position="Bottom" IsZoomEnabled="False"/>                 <oxy:LinearAxis Key="MyYAxis" Position="Left" IsZoomEnabled="False"/>                 <oxy:LinearColorAxis Key="...

Collect Python project dependencies

Sometimes we need to figure out dependencies of our Python project. I have been using the below two approaches to get it done: Using pipreqs If we want to collect all the dependencies and store them in a project-level 'requirement.txt' file, then pipreqs is an easy and simple solution. This library analyzes the import statements in the project to gather dependencies. First, we need to install pipreqs: pip install pipreqs In order to generate project-level requirement.txt file, run the below command: pipreqs /path/to/your/project/ requirements file would be saved as- ' /path/to/your/project/ requirements.txt ' To read about more advantages of pipreqs over pip freeze , read it from here Using pipdeptree     I have written a more detailed post about visual representation of python packages using 'pipdeptree' library in this blog . 'pipdeptree' provides more advanced options such as listing the dependencies in html format o...