SSH only works on first vagrant up; reboot times out ssh

I am able to create my vagrant instance with vagrant up, I am able to ssh in using vagrant ssh, no problem. However, when I run vagrant reload, I can never get back in, and only get the following"

    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...

Until it times out. I have these lines in my Vagrantfile:

config.ssh.forward_agent = true
config.ssh.insert_key = false

Although the second line I added after I already started having this problem. I’m happy to provide you with the contents of my Vagrantfile, or vagrant-config.json, or whatever you want. I’m running ubuntu 20.04 on my host, and my client is ubuntu 16.04.

Also: When I run vagrant with the GUI, it gets stuck at [sdb] Attached SCSI disk.

After a lot of trial and error, I found a solution:

  1. Enable Virtualbox GUI by adding vb.gui = true to your Vagrantfile.
  2. Open Virtualbox, navigate to your vagrant instance and hit settings, then Display: change graphics controller to WMSVGA.
  3. Run vagrant up.
  4. When the ‘GUI’ (vbox terminal) prompts you to log in, use vagrant / vagrant.
  5. Run sudo mkdir -p -m0755 /var/run/sshd && sudo systemctl restart ssh.service

Now, vagrant ssh will work correctly.

This is apparently a known bug with old VPS kernels. I will have to add this as a cron job, though I haven’t tried it yet. I think the easiest solution to this problem is to move up to Ubuntu 20.04 LTS (I’m on 16.04).

Is there a way to programmatically fix this, so I don’t have to do this every single time I boot up the machine?

Edit: I tried adding the crontab job and it just doesn’t work. It only works if Virtual Box is open.