Software & AppsOperating SystemLinux

Accessing Windows Shares from BASH in Ubuntu VMWare Player

Ubuntu 19

In this comprehensive guide, we will delve into the process of accessing Windows shares from BASH in an Ubuntu VMWare Player. This can be a useful skill when you need to share files between your host Windows machine and a guest Ubuntu machine running on VMWare Player.

Quick Answer

To access Windows shares from BASH in Ubuntu VMWare Player, you can either manually mount the drives using Samba and cifs-utils, or use the Files application in Ubuntu to connect to the Windows shares. Both methods provide effective ways to share files between your host Windows machine and the guest Ubuntu machine running on VMWare Player.

Prerequisites

Before we begin, it’s important to ensure that you have administrative privileges on both the Windows host and the Ubuntu guest machine. You should also have VMWare Player installed on your Windows machine and Ubuntu installed on VMWare Player.

Understanding Windows Shares

Windows shares, also known as shared folders or network drives, are folders on a Windows machine that have been made accessible to other computers on the same network. This feature allows multiple users to access and modify files in these folders, making collaboration and file sharing easier.

Accessing Windows Shares from Ubuntu

There are two primary methods to access Windows shares from Ubuntu: manually mounting the drives or using the Files application in Ubuntu.

Method 1: Manually Mounting Windows Shares

Step 1: Installing Necessary Packages

The first step involves installing the necessary packages on your Ubuntu machine. These packages include Samba and cifs-utils. Samba is a software suite that allows file and print sharing between machines running Windows and Unix-like systems. cifs-utils is a package that provides tools and utilities for mounting SMB/CIFS shares.

Open the terminal in Ubuntu and run the following command:

sudo apt-get install samba cifs-utils

This command uses the sudo command to run the command as the root user, apt-get is the package handling utility in Ubuntu, install is the command to install packages, and samba and cifs-utils are the names of the packages to be installed.

Step 2: Creating a Mount Point

After installing the necessary packages, the next step is to create a directory where the Windows share will be mounted. Run the following command:

sudo mkdir /mnt/smb

In this command, mkdir is used to create a new directory. /mnt/smb is the directory path where the Windows share will be mounted.

Step 3: Creating a Bash Script to Mount the Windows Share

Next, we need to create a Bash script that will be used to mount the Windows share. First, create a new file named smb.sh and make it executable:

touch smb.sh
chmod +x smb.sh

In these commands, touch is used to create a new file, chmod is used to change the file’s permissions, and +x makes the file executable.

Step 4: Adding Content to the Bash Script

Open the smb.sh file using a text editor like vi or nano:

vi smb.sh

Add the following content to the smb.sh file, replacing the placeholders with your own information:

#/bin/bash

SERVER_IP="192.168.1.1"
SHARE_NAME="c$"
USERNAME="samba user name"
PASSWD="samba password"
DOMAIN="domain"

mount.cifs //$SERVER_IP/$SHARE_NAME /mnt/smb/ -o username=$USERNAME,password=$PASSWD,dom=$DOMAIN

In this script, SERVER_IP is the IP address of your Windows machine, SHARE_NAME is the name of the Windows share you want to access, USERNAME and PASSWD are the username and password used to access the Windows share, and DOMAIN is the domain of the Windows machine.

Step 5: Running the Bash Script

Save and exit the text editor. Now, run the script to mount the Windows share:

./smb.sh

You can now access the Windows share by navigating to the mount point:

cd /mnt/smb/

Method 2: Using the Files Application in Ubuntu

The second method involves using the Files application in Ubuntu to connect to the Windows share.

Step 1: Connecting to the Windows Machine

Open the Files application and connect to your Windows host machine by clicking on the appropriate network location. Once connected, you should see the Windows shares listed in the sidebar of the Files application.

Step 2: Accessing the Windows Share

To access the shares from the terminal, navigate to the mount point of the share. By default, the shares are usually mounted under the /run/user/1000/gvfs directory. For example, if your share is named “sharename”, you can access it by running the following command:

cd /run/user/1000/gvfs/sharename

Conclusion

In this guide, we have covered two methods of accessing Windows shares from BASH in Ubuntu VMWare Player. Both methods are effective and can be chosen based on your preference. Remember to replace any placeholders in the instructions with your own information, such as server IP, share name, username, password, and domain.

Can I access Windows shares from Ubuntu without installing any additional packages?

No, you need to install the necessary packages like Samba and cifs-utils to access Windows shares from Ubuntu.

How do I install Samba and cifs-utils packages in Ubuntu?

You can install the packages by running the command sudo apt-get install samba cifs-utils in the terminal.

Where can I find the IP address of my Windows machine?

You can find the IP address of your Windows machine by opening the Command Prompt and running the command ipconfig. Look for the IPv4 Address under the network adapter you are using.

Can I access multiple Windows shares from Ubuntu using the same method?

Yes, you can access multiple Windows shares by creating separate Bash scripts or by manually mounting each share to different mount points.

How do I make the Bash script automatically mount the Windows share on startup?

To make the Bash script run automatically on startup, you can add it to the /etc/rc.local file or create a systemd service for it.

Leave a Comment

Your email address will not be published. Required fields are marked *