I am running a VM on my linux server, and I connect to it usually using SSH. I was editing the SSH configurations for this VM to try out different parameters, and last saved edit was not working.

Now, I lost connection to my VM, and then all my tried to connect to the VM are failing "I get 'Connection Refused'". I know the error is coming because of my changed configuration file (ssh_config and sshd_config), and that my ssh service was stopped. Any idea how can I fix this? Is there a way using VBoxManage to edit the files inside the VM? This way I can at least fix the SSH file and get it working again.

Any help is very much appreciated!


Step-by-step Guide:

  • Download a linux live CD, e.g. Debian
  • Make sure your VM prefers to boot from its virtual Optical drive: Boot order
  • Insert the downloaded image into the drive: Optical drive
  • (Re)Start the VM to boot into the live system.
  • Start a terminal.
  • Mount the VM's virtual hard drive:
$ sudo su
# mkdir -p /mnt/drive
# mount /dev/sda /mnt/drive
  • Finally, correct the errors inside the VM:
# nano /mnt/drive/home/<USER>/.ssh/config
# nano /mnt/drive/etc/ssh/ssh_config
# nano /mnt/drive/etc/ssh/sshd_config

To prevent this to happen again, always keep one ssh connection open, until you have verified that the new configuration works. You can verify by restarting the sshd service and establishing a second session in parallel (restarting the sshd daemon does not terminate an established ssh session)!

Alternative approach: You could also try to mount the disk image into the host's file system. However, the necessary steps for this approach depend on the host's OS and the file type of the disk image (.vdi, .vhd, .vmdk, ...).


I would simply download the VHD (or whatever format you chose) of the VM and load it into VirtualBox locally. From here you can restore your SSH configuration to a known working state if you have a backup, or tweak it manually. When done, power off the VM and upload the VHD back to your server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.