Skip to content

Instantly share code, notes, and snippets.

@takase1121
Last active April 2, 2022 04:17
Show Gist options
  • Save takase1121/76ba3bc5b477ea8c04f41d9761395efa to your computer and use it in GitHub Desktop.
Save takase1121/76ba3bc5b477ea8c04f41d9761395efa to your computer and use it in GitHub Desktop.
Accessing Ubuntu files from Windows easily

Here is a brief tutorial on how to open your Ubuntu files like any other Windows folder. The way we'll achieve this is by adding a Host-Only network adapter.

Some networking 101

I'm not an expert.

I am not an expert in networking and can barely fix anything. Don't quote me on this.

A computer network is just like a dorm. Each computer has an address (how to find them). In order to avoid 2 computers having the same address, a protocol called DHCP is used to "give" address to a computer joining a network. Think of it as moving into a dorm and the dorm supervisor assigns you a room number.

DHCP is not the dorm supervisor, it's just a way for them to give you the room number - something like the front desk.

  • IP address is the address of the computer. It is usually written as xxx.xxx.xxx.xxx. Think of it as your room number, let's say section 2 room 2.
  • Subnet mask is a mask that tells the computer which part of an IP address belongs to you and to the router. This is usually 255.255.255.0 in simple networks so don't worry about it.
  • The gateway is the address of the router. Think of it as the room number of the dorm supervisor.

When your computer wants to send something to another computer, it does this:

  • your computer tries to find the receiver address on the network. If it finds it, it sends the data directly to the receiver.
  • if your computer cannot find any matching address locally, it will send it to gateway, and gateway will be responsible for relaying the data to the receiver.

Steps

Adding a Host-Only Network Adapter to an existing VM. Open VMWare Workstation (or Player, it should be fine). Click on "Edit virtual machine settings".

image

Click on the "Add" button.

image

Click on the "Network Adapter" option and click "Finish".

image

Select any one of the network adapters from the left and change the Network Connection to Host Only.

image

Get your computer's IP address on your Host-Only network.

Before we write anything down, we'll need to double check your network details.

Open your Task Manager and go to the "Performance" section. Find an entry with VMnet1 and click on it.

You'll find the IP for your Host-Only Network Adapter. Note that this is NOT THE GATEWAY IP, it is your computer's IP. Remember that your computer and VM is now in the same network, thus they both have their own unique address.

For any given VMWare software, the default Gateway IP is always xxx.xxx.xxx.2. If your computer IP is 192.168.170.1, then your gateway is 192.168.170.2.

Set up static IP in Ubuntu. When you're in Ubuntu, click on the 3-prong icon on the top right corner to see your network connections. There will be 2 connections, one connected and one connecting (or off). The connecting / off network is your Host-Only adapter.

Click it and select "Wired Settings".

image

On Wired Settings, click on the Cog beside the connecting / off Network.

image

In the menu, go to the "IPv4" tab and change the method to "Manual". Enter your address, netmask (subnet mask) and gateway.

  • The address should be the IP address obtained above, with the last field changed to any number that isn't 0, 1, 2 and less than 256.
  • The netmask is 255.255.255.0.
  • The gateway IP is mentioned above.

After entering the values, press the "Apply" button. If the network does not try to connect immediately, just click the toggle.

image

If both networks are connected, than you've successfully set up static IP.

Install and set up samba server on Ubuntu.

First, install samba by running sudo apt install samba.

image

Ubuntu's default samba configuration is suprisingly good and it should work out of the box. However, you do need to add your own home folder to the configuration.

Open the configuration file with sudo nano /etc/samba/smb.conf (or any editor, really. It's up to you)

image

Go to the very end of the file and add an entry (replace (username) with your Ubuntu username):

[(username)]
  comment = My home folder
  path = /home/(username)
  guest ok = no
  browseable = yes
  writable = yes
  create mask = 0755
  directory mask = 0755

image

Save and close the file.

After that, you will need to add your username to samba. Run sudo smbpasswd -a (username):

image

You're ready to go! Start the samba server by running sudo systemctl start --now smbd

Connect to your samba server from Windows.

You're almost set! Open File Explorer, go to "This PC" and click "Map Network Drive".

image

In the dialog, enter \\(your Ubuntu IP Address)\(your Ubuntu username). Click "Finish".

image

Windows should ask you for your username and password. Enter them, and you're in! If everything is set up properly, you should be able to see your home folder in File Explorer and can add, edit and remove files.

The password is your SMB password, the one you entered into smbpasswd. It can be different than your Ubuntu password.

With everything set up, your home folder behaves almost like a USB drive attached to your computer. As long as the VM is started, you can access it.

Extras: human-readable names for your VM!

Tired of typing 192.168.170.123 everytime? Here's a tip to turn that IP address of yours into a human-readable, memorable name!

You'll need Administrator privileges.

  1. Start your editor with administrator privileges.
  2. Open C:/Windows/system32/drivers/etc/hosts (Your Windows installation may be different, but you get the idea).
  3. add (Ubuntu IP address) (any name, eg. ubuntu.local)
  4. Save the file.
  5. You can now address your VM with the new name instead of the IP address!

If you think you can live without GUI, then you can simply SSH into your VM.

Why do this?

Using Ubuntu in a VM sucks. You can either use the VM ina 800x600 window or use fullscreen and be greeted with laggy animations. You also cannot alt-tab your window because all the keystrokes are sent to the VM. You would have to run everything on the VM.

Some recommendations

If you're going to use a terminal, use a good one. On Windows 10, install Windows Terminal. If you're on Windows 11, Windows Terminal is installed by default.

Steps

Install and run OpenSSH server.

Run sudo apt install openssh-server.

image

Run sudo systemctl enable --now ssh to start the SSH server.

image

Connect to your VM.

Start Windows Terminal. You should be in Windows Powershell.

Run ssh (your Ubuntu username)@(your Ubuntu IP).

Use your Ubuntu password here. When prompted about the fingerprint, just say yes.

image

Extras

You can run this automatically when opening Windows Terminal.

Make sure you have the latest Windows Terminal version since they've only added the GUI settings a while ago.

Click on the small arrow on the tab bar and select "Settings".

image

Here, scroll down and click on the + button. Click + New empty profile.

image

Change the name to your liking, and put the ssh command in the "Command line" field. After customizing the other options, Click "Save".

image

You should be able to see your newly created profile here.

image

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