Skip to content

Instantly share code, notes, and snippets.

@zombig
Last active December 13, 2024 11:11
Show Gist options
  • Save zombig/e3455c45e726a48edcaa7c23ee504495 to your computer and use it in GitHub Desktop.
Save zombig/e3455c45e726a48edcaa7c23ee504495 to your computer and use it in GitHub Desktop.
Short how to about my current windows environment

Windows Wroking Evniroment Example

Becuase of you have to do some tests with out games and products we are stongly reccomend to you use Windiows onto yours wokring notebook.

This document will show how to install and configure working environments.


Installing Required Software

Download and install next software.


Configuring

Configure downloaded softwares.

OpenSSH

After Windows OpenSSH will be installed you have to configure agent starup.

  1. Open PowerShell as an Adminitrator

  2. Run next command for enable ssh-agent service

Start-Service -Name ssh-agent
Set-Service -Name ssh-agent -StartupType Automatic
  1. Also we recommend to torn off sshd service as well
Stop-Service -Name sshd
Set-Service -Name sshd -StartupType Disabled

Please, make sure that you are using ssh-agent and ssh binaries provided by Win32-OpenSSH package!

Get-Command ssh-add
Get-Command ssh

A valid ssh binary location is: C:\Program Files\OpenSSH\ssh.exe

Generate SSH key-pair for your future VM (only for this VM!). Leave password empty.

ssh-keygen

You can find this pair into %USERPROFILE%\.ssh location.

KeePassXC

Just select yours keepass database file location. Then you have to navigate to Tools -> Settings -> SSH Agent and Enable SSH Agent Integration set Use OpenSSH box as well.

Now you can add an entry and add your ssh key into it (see Advanced tab). Next you have to navigate into SSH Agent tab and configure how and when your key will be added to ssh-agent.

VirtualBox

Create, configure and install your favorite linux distribution (e.g. ubuntu-server-24.04).

Do not forgent to add shares, or any additional devices for your choise.

If you will using NAT network you also should add port mapping for SSH (simple 22 to 22 I guess).

SSH

Add public key generated befor into .ssh/authorized_keys in VM (or you can do it on install in some distros).

VM AutoStart

Save next script somewere, e.g. D:\exe\sys\start-vm.bat

"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" startvm %VMNAME% --type headless

Replace %VMNAME% with your VM name.

Open startup menu (win+r -> shell:startup) and create link to yours bat file there.

Windows Terminal

Create bat file, e.g. D:\exe\sys\ssh-vm.bat

@echo off

set VMNAME="%1"
set USERNAME="%2"
set HOSTNAME="%3"

IF %VMNAME%=="" goto usage
IF %USERNAME%=="" goto usage
IF %HOSTNAME%=="" goto usage

"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" list runningvms | find /C %VMNAME%

IF %ERRORLEVEL%==1 goto start_vm

goto ssh_vm

:usage
@echo.
@echo Usage: is_running.bat VMNAME USERNAME HOSTNAME
@echo      VMNAME: name of yours VirtualMachine
@echo      USERNAME: username for connect
@echo      HOSTNAME: where we will ssh (VBox Adapter address)
@echo.
exit /b 1

:start_vm
echo VM %VMNAME% NOT RUNNING. STARTING %VMNAME%
"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" startvm %VMNAME% --type headless
ping -n 30 127.0.0.1 >nul

:ssh_vm
ssh -A %USERNAME%@%HOSTNAME%

exit /b 0

Open terminal configuration and add into profiles list next

            {
                "commandline": "D:\\exe\\sys\\ssh-vm.bat %VMNAME% %USER% %VMADDR%",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6102}",
                "cursorShape": "filledBox",
                "hidden": false,
                "icon": "ms-appdata:///roaming/ubuntu-32.png",
                "name": "Ubuntu-Server-24.04(VBox VM)"
            }

Key Bindings

I'd like to use key bindings from Gnome Terminal, so here is config:

    "actions": 
    [
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 3
            },
            "keys": "ctrl+4"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 9
            },
            "keys": "ctrl+0"
        },
        {
            "command": 
            {
                "action": "prevTab"
            },
            "keys": "ctrl+pgdn"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 2
            },
            "keys": "ctrl+3"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 4
            },
            "keys": "ctrl+5"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 7
            },
            "keys": "ctrl+8"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 0
            },
            "keys": "ctrl+1"
        },
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        },
        {
            "command": "find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 1
            },
            "keys": "ctrl+2"
        },
        {
            "command": 
            {
                "action": "nextTab"
            },
            "keys": "ctrl+pgup"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 8
            },
            "keys": "ctrl+9"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 6
            },
            "keys": "ctrl+7"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 5
            },
            "keys": "ctrl+6"
        }
    ],

Docker Network (VM)

Configure Docker daemon

 sudo cat << EOF > /etc/docker/daemon.json
{
  "bip": "192.168.100.1/24",
  "mtu": 1500,
  "default-address-pools":[
    {
      "base": "192.168.110.0/24",
      "size": 29
    }
  ]
}
EOF

And restar docker

sudo systemctl restart docker.service
sudo systemctl restart docker.socket

Installing Guest Adddons

Because of VB licensing we are able to use Guest Addons as well with GPLv3 license...

The “VirtualBox Guest Additions” is a set of software drivers and utilities that are shipped as a subset of the VirtualBox base package and that are installed inside a virtual machine for better performance and usability. Like the VirtualBox base package, the VirtualBox Guest Additions are licensed under the GPLv3.

https://www.virtualbox.org/wiki/Licensing_FAQ


Installing Guest Addons

  1. Download latest version of guest addons https://download.virtualbox.org/virtualbox/7.1.4/VBoxGuestAdditions_7.1.4.iso

  2. Connect downloaded image to guest on your host (via VBox GUI)

  3. On guest mount cdrom

sudo mount /dev/cdrom /mnt/
  1. install requirements
 sudo apt update && sudo apt install -y bzip2 tar
  1. Run GA installer
 cd /mnt/
 sudo ./VBoxLinuxAdditions.run --nox11

Ubuntu VM Newworking

For easy-to-use I suggest to configure your VBox/VM networks in next way.


Configure VBox Network Adapter

Navigate to File -> Tools -> Network Manager and edit VirtualBox Host-Only Ethernet Adapter.

  • Assign 192.168.200.1 as IPv4 Address for it

  • Assign 255.255.255.0 as a network mask for it

  • Disable DHCP Server


Default: NAT

I reccomend to create a separate NAT network, and disable Promiscue mode on it.


Additionaly Adapter

For VM enable second network adapter and choose Virtual adapter -> VirtualBox Host-Only Ethernet Adapter.

Disable promisc mode.


Configure VM Network

Login into your VM (ubuntu) and configure netplan

cat <<EOF >/etc/netplan/99_config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true
    enp0s8:
      addresses:
        - 192.168.200.100/24
EOF

Apply netplan

sudo netplan apply

Conclusion

Now you could use 192.192.200.100 address to access to yours VM from host.

Ubuntu: Share disks from hosts

You also could connect a hosts disks


Configure VM

  1. Navigate to VM settings Shared Folders section

  2. Press add button

    1. Select Path to filder, e.g. D:\ for share whole D drive

    2. Select Folders Name, e.g. D_DRIVE

    3. Select Mount Point, e.g. /media/host/d

    4. Select required permissions

  3. Apply Configuration


VM Configuration

Login into VM (Ubuntu) and make next

sudo cat << EOF >>/etc/fstab

D_DRIVE /media/host/d vboxsf uid=1000,gid=1000 0 0
EOF

Create drive for mount point

mkdir -p /media/host/d

Mount

sudo mount -a

Share Disks from VM

You also could share some folders from VM to host.


VM Configuration

Install samba

sudo apt install samba

Create dir

mkdir -p /home/zombig/src

Configure samba

sudo cat << EOF >/etc/samba/smb.conf
[src]
   path = /home/zombig/src
   browseable = yes
   read only = no
   valid users = zombig
   hosts allow = 192.168.200.1
EOF

Add user to samba

sudo smbpasswd -a zombig
```bash

Start samba and enable

```bash
sudo systemctl restart smbd
sudo systemctl enable smbd

Allow fw

sudo ufw allow samba

Configure Host

Navigare to This PC -> Map network device

Choose letter and set path to \\192.168.200.100\src. Enter creds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment