Created
January 25, 2021 01:45
-
-
Save jankais3r/238da941ba6a6455c5f81a07cc2cfd18 to your computer and use it in GitHub Desktop.
"WSL" on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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