A common way to communicate between operating systems such as Windows and Linux is to share files. You can accomplish this through various processes such as Samba, SFTP or FTP, SSH, cloud storage, or a portable device. Although this may sound pretty tedious but with the appropriate technique, you can master it in no time. In this article, I will demonstrate how to share files effortlessly between Linux and Windows in two simple methods.
Key Takeaways
- Learning how to share files over a network using Samba.
- Knowing how to share files using a virtual machine without the need for any network.
- Learning about sharing requirements and deciding on a suitable method.
Requirements
- User must have sudo/root privileges.
- User must have a text editor.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.02 LTS
Let me introduce you to two simple and easy scenarios for file sharing between Linux and Windows, even if you are a beginner in Linux. These methods will provide you access from either operating system and you won’t need to worry about file sizes or formats.
Samba is a free and open-source software suite that allows users to share files, folders, and printers between different operating systems running on a single network. It is a widely popular method due to its simplicity, stability, and compatibility with both Linux and Windows. Moreover, it offers seamless sharing of files with the added benefit of being able to configure user access and permissions.
Step 1: Installing Samba on Ubuntu
First, you need to install Samba on the Linux operating system. Here, I am using Ubuntu as my Linux distribution where I will be installing this software.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Type the following command to install Samba and press ENTER.
sudo apt-get install samba
- sudo: Permits a user with administrative privileges to execute commands.
- apt-get install: Specifies that the install task needs to be performed.
- samba: Name of an open-source and free software package.
➌ Confirm that the installation was complete and check its location in the system with
whereis samba
- whereis: Look for the location of the installed package.
- samba: Name of the package.
sudo smbpasswd -a ayesha
- sudo: Permits a user with administrative privileges to execute commands.
- smbpasswd: Sets password for Samba users.
- -a: Allows the command to add a new Samba user.
- ayesha: User name.
Step 2: Configure Samba on Ubuntu
After installing Samba, it is important to configure it so that it is functional for both operating systems. This step involves creating a directory as the shared folder and then making changes to the Samba configuration file.
Steps to Follow >
➊ Open Ubuntu terminal.
➋ Create a folder with the mkdir command. Here, I have created the folder, Shared_Folder in Desktop for easy access.
mkdir /home/ayesha/Desktop/Shared_Folder
- mkdir: Creates a new directory or folder
- /home/ayesha/Desktop/Shared_Folder: Absolute path of the location of the folder.
➌ Next, you have to configure the Samba service and make it suitable to share files with Windows. For that, run the given command in the terminal.
sudo nano /etc/samba/smb.conf
- sudo: Permits a user with administrative privileges to execute commands.
- nano: Text editor
- /etc/samba/smb.conf: Configuration file of Samba to customize settings such as user authentication, shares, and security.
- conf: Configuration file. smb stands for Sever Message Block Configuration.
➍ Provide the password of the currently logged-in user. After providing the password it will open up the text editor where you can alter the configuration settings of the shared folder.
➎ Once the text editor opens, write these lines at the end of the file.
[Shared_Folder]
path = /home/ayesha/Desktop/Shared_Folder
available = yes
valid users = ayesha
read only = no
writeable=yes
browseable=yes
public = yes
- Shared_Folder: Name of the folder whose contents you want to share.
- path: Absolute path of the folder you want to share.
- available: Specifies whether the file is available for sharing or not.
- valid users: User name.
- read-only: Specifies whether the file is available for reading or not.
- writeable: Specifies whether the folder can be written to or not.
- browseable: Specifies whether the shared file is visible while browsing the network or not.
- public: Specifies whether the shared file is accessible to all users or not.
➏ Finally, press CTRL+O and CTRL+X to save the changes and exit the editor respectively.
Remember to write the folder name, its path, and user name carefully. I chose Shared_Folder as my folder name and its absolute path in the system is included in the mentioned code. Besides, ayesha is the user name in my Linux system.
Read More: How to Configure NFS Server in Linux? [5 Steps]
Step 3: Check Samba Status on Ubuntu
You have to make sure that Samba is active otherwise the shared folder will not be accessible. You can ensure this by checking its status.
Steps to Follow >
➊ Open your Ubuntu terminal again.
➋ Run the following command to restart Samba in Linux.
sudo service smbd restart
- sudo: Permits a user with administrative privileges to execute commands.
- service: Controls services in the Linux system.
- smbd: Samba daemon which provides file-sharing services to Windows clients.
- restart: Stop running the service and start again.
➌ Enter the password of the currently logged-in user.➍ Now make sure that the smbd daemon is activated and operational.
systemctl status smbd
- systemctl: Manages system services, along with starting, stopping, and checking the status of services.
- status: Displays the current status of a service.
- smbd: Samba daemon which provides file-sharing services to Windows clients.
Step 4: Create a File in Linux and Access It From Windows
To confirm if files are accessible, I will proceed to create a file in the Shared_Folder and attempt to control it from Windows.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Type the following command in the Ubuntu terminal to get your Linux IP address.
hostname -I
- hostname -I: Displays the IP address associated with the hostname.
➌ Now go to Windows and open “This PC”.
➍ Click on the address bar and type the IP address and name of the folder which you created in Linux.
\\192.168.153.128\Shared_Folder
- 168.153.128: IP address of my Linux system.
- Shared_Folder: Name of the folder you have created in Linux to share files.
➏ Shared_Folder will open instantaneously when you hit OK. The folder will open as an empty folder in both Linux and Windows.The above image depicts that Shared_Folder in Windows is accessible.
The above image depicts that Shared_Folder in the Linux system is also accessible.
➐ To understand that Windows can access the files in the folder, I have saved an image in Shared_Folder in the Linux system.➑ Now check Shared_Folder in Windows.
You can now view the photo from Windows and have full control over it.
Step 5: Create a File in Windows and Access It From Linux
The file was accessible from Windows. But can you manage files created in Windows from Linux? Let’s find out.
Steps to Follow >
➊ First, create a Word file in Shared_Folder from Windows.➋ Go to Linux and open Shared_Folder there.
You can see in the above image that the file is visible and you can similarly have full control over it from Linux.
Read More: How to Share Files between Linux and Windows Dual Boot [3 Methods]
Multiple operating systems can run on a single physical computer with the help of VMware Workstation which is a virtualization software. This method is deemed advantageous if you wish to save time and effort in contrast to the laborious and time-consuming approach of file transfer through a network share. In this part, I will show you how you can share your files with VMware.
It is mandatory to enable the shared folder option in VM settings. This will ultimately grant anyone permission to have full access to files from either operating system.
Steps to Follow >
➊ At first power on your VMware Virtual Machine.
➋ Go to VM > Settings.➌ Next go to Options > Shared Folder. Click on Always enabled. Then hit on Add.
➍ Then browse the folder you want to share. I have chosen the folder Ayesha in this regard and its location and name of the folder appeared on the Host path and Name dialogue boxes. Afterward, click on Next.
➎ Now click on Enable this share and then press Finish.
➏ Make sure that your desired folder is added in the Folders option. Click on OK when you have completed the steps above.
You can see in the image shown above that folder Ayesha along with its location on my PC has been added to Folders box. It is now available for sharing files.
Now mount the shared folder, Ayesha in the existing /mnt/ directory as it is the standard folder for temporarily mounting files or devices. Moreover, /mnt/ does not interfere with any existing directory in the system. The mounted folder is now easily recognizable in the Linux system.
Steps to Follow >
➊ Open your Ubuntu terminal.
➋ Type the following command to make a folder named hgfs using mkdir command in the mnt directory.
sudo mkdir /mnt/hgfs
- sudo: Permits a user with administrative privileges to execute commands.
- mkdir: Creates a new directory or folder in the system.
- /mnt: Directory in Linux system that is used as a mount point for temporary files.
- /mnt/hgfs: Absolute path of the location of the newly created directory, hgfs.
➌ Now execute the following command to finally mount the shared folder, Ayesha.
sudo vmhgfs-fuse .host:/ /mnt/hgfs/ -o allow_other -o uid=1000
- sudo: Permits a user with administrative privileges to execute commands.
- vmhgfs-fuse: Command that mounts VMware shared folders in the Linux file system.
- .host:/: This specifies the name of the VMware shared folder that you want to mount. The dot (.) at the beginning specifies the default mount point.
- /mnt/hgfs: Absolute path of the location of the newly created directory, hgfs. This indicates where you want to mount your shared folder.
- -o: Specifies the options to use when mounting a folder.
- allow_other: The first option allows other users on the system to access the mounted shared folder.
- uid=1000: This option sets the user ID (UID) of the mounted shared folder to 1000. 1000 is the default UID. UID indicates which user owns the files of the mounted directory.
➍ Afterwards, type the following command to ensure that the shared folder is available in the terminal.
vmware-hgfsclient
- vmware-hgfsclient: Displays list of available shared folders.
➎ Now implement the commands below one by one to navigate to the folder Ayesha using cd command and list its contents with ls command.
cd /mnt/hgfs/Ayesha
ls
- cd: Changes the current working directory helping you to navigate through the file system by specifying the path of the directory you want to change to.
- /mnt/hgfs/Ayesha: Absolute path of the folder Ayesha in mnt directory.
- ls: Lists the contents of a directory.
It is important for you to understand the accessibility of this folder. To do so you need to find its location at first.
Steps to Follow >
➊ Now in the Files in Ubuntu, go to Files > Other Locations > Computer.➋ Then click on the folder named “mnt”.
➌ Then browse through hgfs > Ayesha.
In the above image, you can see that the folder Ayesha is empty at this point.
Step 4: Create a File in Linux and Access It From Windows
Let’s create a file in the folder Ayesha and access it from Windows.
Steps to Follow >
➊ Navigate to the shared folder in my case which is Ayesha and type the following commands to create a text file.
touch file.txt
ls
- touch file.txt: Creates an empty file named file.txt
- ls: Lists the contents of a directory.
Step 5: Create a File in Windows and Access It From Linux
Now I will save an image in the folder Ayesha in Windows and try to access it from Linux.
Steps to Follow >
➊ First, save a file in the specific shared folder in Windows. In my case, I will save a file named “Photo.jpeg” on my shared folder named “Ayesha” in Windows.➋ After that type the following command in the Ubuntu terminal after navigating to the shared folder.
ls
- ls: Lists the contents of a directory.
➌ To check it from the graphical user interface, navigate to your shared folder in Linux which is in my case Files>Other Locations>Computer>mnt>hgfs>Ayesha.
In the above image, you can see that I can successfully access the shared image on my Linux Virtual Machine.
Comparative Analysis of Cases
Ather going through the above-mentioned cases you may be confused in choosing the suitable process. I have shown a comparison of both scenarios to demonstrate the advantages and disadvantages. Hopefully, this will help to understand the criteria for deciding the best method.
Cases | Pros | Cons |
---|---|---|
Case 1 |
|
|
Case 2 |
|
|
To simplify, Case 1 is preferable when different operating systems are used and file sharing is a common requirement. On the other hand, sharing through Case 2 is feasible when you’re working with virtualized environments.
Conclusion
If you are confused about file sharing or find this process complicated, try the methods mentioned in this article. The file-sharing process has been simplified here so that anyone, regardless of their expertise in Linux, can undergo this experience smoothly and with no hassle. However, your need to share over a network or a virtual machine decides the scenario you are in and therefore you can transfer files based on your preference. Moreover, keep in mind that file sharing can pose security risks. Therefore, I recommend you to have a regular backup for your files and folders.
People Also Ask
Related Articles
- How to Access Shared Folder in Ubuntu [2 Methods]
- How to Install and Configure Samba Server in Ubuntu? [4 Steps]
- How to Install, Configure and Connect Samba Client on Ubuntu
- Install, Configure and Connect Samba on Ubuntu Using GUI
- How to Copy File from Windows to Linux Using SSH [2 Methods]
- How to Access Samba Share from Windows [2 Methods]