Accessing Ubuntu VM while SSH daemon is modified and cannot open socket

SA 21 Reputation points
2021-09-30T23:38:40.383+00:00

Hello,

I was able to SSH into Ubuntu VM and things were working fine. Last time, I made some change to /lib/systemd/system/ssh.service (ssh daemon) which loads my shared library. Unfortunately, before stopping the VM I forgot to undo the changes and now, due to my shared library, it seems that the sshd is unable to open a socket. As a result, I am unable to ssh into my VM. I think if I get access to VM and undo the changes in /lib/systemd/system/ssh.service then things will work perfectly.

I don't whether there is another way of accessing my VM and it seems that the SSH is the only way to access, therefore, I have ended up in this situation. I have tried both RDP and Azure Bastion, and nothing is working. I am not whether I created any password and the ones that I remember are not working.

How to access the VM? What can I do to safe the data in my VM?

Please let me know. Thanks!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,171 questions
{count} votes

Accepted answer
  1. SRIJIT-BOSE-MSFT 4,331 Reputation points Microsoft Employee
    2021-10-01T10:52:09.477+00:00

    @SA , thank you for your question.

    You might want to try any of the following options:

    • ##### Azure Serial Console The Serial Console in the Azure portal provides access to a text-based console for virtual machines (VMs) and virtual machine scale set instances running either Linux or Windows. This serial connection connects to the ttyS0 or COM1 serial port of the VM or virtual machine scale set instance, providing access independent of the network or operating system state. The serial console can only be accessed by using the Azure portal and is allowed only for those users who have an access role of Contributor or higher to the VM or virtual machine scale set. Serial Console is generally available in global Azure regions and in public preview in Azure Government. It is not yet available in the Azure China cloud. Please read the Prerequisites to access the Azure Serial Console.
      For detailed steps check Get started with the Serial Console OR
    • ##### Recovering Azure VM by attaching OS disk to another Azure VM
      1. Create a temporary Linux Azure Virtual Machine (we shall refer to this new VM as the Recovery VM henceforth). [How-to guide] 2. Mount a copy of the impacted VM's OS disk as a data disk on the Recovery VM. You can find a list of steps here. 3. SSH to the Recovery VM and fix the issues on the mounted copy of the impacted VM's OS disk. 4. Detach the mounted copy of the impacted VM's OS disk from the recovery VM. [How-to guide] 5. Swap the OS disk on the impacted VM with the copy (which now has the fix). [How-to guide]

    Disclaimer: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as convenient to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful