Skip to content

Instantly share code, notes, and snippets.

@jankais3r
Created January 25, 2021 01:45
Show Gist options
  • Save jankais3r/238da941ba6a6455c5f81a07cc2cfd18 to your computer and use it in GitHub Desktop.
Save jankais3r/238da941ba6a6455c5f81a07cc2cfd18 to your computer and use it in GitHub Desktop.
"WSL" on macOS
See it in action: https://asciinema.org/a/apMoGLtthFSCKrssymYKCwdMy
Setup:
1) Create a new Ubuntu Server VM using VMWare Fusion 12 (free for personal use)
2) Create and enable /etc/systemd/system/vmip.service which will expose VM's IP address on every boot
3) Generate a new, password-less ssh key on your Mac and add it to Ubuntu's authorized keys
4) Create ubuntu.sh on your Mac and adjust paths to the VM
#!/bin/bash
vmrun list | grep '/Users/jankais3r/Virtual Machines.localized/Ubuntu Server 20.04 LTS.vmwarevm/Ubuntu Server 20.04 LTS.vmx' -q;
if [ $? = 1 ]
then
echo "Booting Ubuntu...";
vmrun start /Users/jankais3r/Virtual\ Machines.localized/Ubuntu\ Server\ 20.04\ LTS.vmwarevm nogui > /dev/null 2>&1;
fi
while [ "$(vmrun -T fusion readVariable /Users/jankais3r/Virtual\ Machines.localized/Ubuntu\ Server\ 20.04\ LTS.vmwarevm/Ubuntu\ Server\ 20.04\ LTS.vmx guestVar vmip)" == "" ];
do
sleep 1;
done
ssh -i ~/.ssh/ubuntu -o LogLevel=ERROR -o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null jankais3r@`vmrun -T fusion readVariable /Users/jankais3r/Virtual\ Machines.localized/Ubuntu\ Server\ 20.04\ LTS.vmwarevm/Ubuntu\ Server\ 20.04\ LTS.vmx guestVar vmip`
echo "Ubuntu session ended."
[Unit]
After=network.service
[Service]
ExecStartPre=bash -c "systemctl set-environment vmip=`ifconfig ens33 | grep \"inet \" | cut -d' ' -f10`"
ExecStart=vmtoolsd --cmd "info-set guestinfo.vmip ${vmip}"
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment