Showing posts with label WSL. Show all posts
Showing posts with label WSL. Show all posts

Monday, March 16, 2026

How to Mount Windows Network Drives in WSL

Mounting network drives in Windows Subsystem for Linux (WSL) opens up a whole new dimension for file management and development. Learn how.
The Linux terminal on Ubuntu

Mounting network drives in Windows Subsystem for Linux (WSL) opens up a whole new dimension for file management and development. This process allows you to access files stored on remote servers or shared folders directly from your WSL environment, making it easier to work across platforms.

In this article we'll review a step-by-step guide on how to do it.

Prerequisites

Before diving in, ensure you have the following:

  • Windows 10 or Windows 11: Ensure WSL is enabled.
  • WSL Installed: You should have WSL set up (either WSL1 or WSL2).
  • Network Share Details: Know the network path (e.g., `\\SERVER\ShareName`) of the shared drive you want to mount.

Mounting Network drives in WSL

1. Enable WSL (If Not Already Done)

If you haven’t enabled WSL on your Windows machine, do so with these steps.

First, oen PowerShell as Administrator by searching for PowerShell in the Start menu, right-click, and choose "Run as Administrator".

Next, let's run the WSL Installation Command:
$ wsl --install

If needed, restart your computer by following any prompts to complete the installation.

2. Install Required Packages in WSL

To work with network drives, you might need the `cifs-utils` package for WSL. Open your WSL terminal and run:

sudo apt update
sudo apt install cifs-utils

3. Create a Mount Point

Next, you'll need to create a directory where the network drive will be mounted. Choose a convenient location, like `/mnt/`.

sudo mkdir /mnt/my_network_drive

4. Mount the Network Drive

Now it's time to mount the network drive. Use the following command, replacing the placeholders with your actual server address, share name, username, and password:

sudo mount -t cifs //SERVER/ShareName /mnt/my_network_drive -o username=YOUR_USERNAME,password=YOUR_PASSWORD
- **Example**:
sudo mount -t cifs //192.168.1.10/SharedFolder /mnt/my_network_drive -o username=user,password=pass

5. Access the Mounted Drive

You can now access your network drive at `/mnt/my_network_drive`. Use commands like `ls` to view the contents:

ls /mnt/my_network_drive

6. Unmounting the Drive

When you're finished, you can unmount the drive with:

sudo umount /mnt/my_network_drive

Additional Tips

Persistent Mounting

To automatically mount the drive at WSL startup, add the following line to your `/etc/fstab`:
//SERVER/ShareName /mnt/my_network_drive cifs username=YOUR_USERNAME,password=YOUR_PASSWORD 0 0

Security Considerations

Storing passwords in plain text in `fstab` can be insecure. Instead, consider using a credentials file:

Create a file to store your credentials:

nano ~/.smbcredentials

Add the following lines:

username=YOUR_USERNAME
password=YOUR_PASSWORD

Change permissions to secure the file:

chmod 600 ~/.smbcredentials

Update the `fstab` entry to use the credentials file:

//SERVER/ShareName /mnt/my_network_drive cifs credentials=/home/YOUR_USERNAME/.smbcredentials 0 0

Conclusion

By following these steps, you can seamlessly access Windows network drives from your WSL environment. This integration not only enhances your productivity but also provides a robust way to manage files across different operating systems. Whether you're developing applications or handling files, having access to network resources in WSL is invaluable. 

With this guide, you should be well-set to access your Windows network drive in WSL. Happy coding!

Tuesday, April 13, 2021

How to get started with the Linux terminal

The terminal may seem scary for new Linux users. However, it's one of the tools that has the biggest potential on your Linux journey. Learn why
The Linux terminal on Ubuntu

On a previous post we discussed the benefits of using the Linux terminal. Today, let's review how to get started with Bash, the most common shell in GNU/Linux operating systems.

The history of Bash

But before we get hands-on, let's learn more a little about Bash. Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (which is located in your system under /usr/bin/sh and is still widely used, especially in containers).

First released in 1989, it has been used as the default login shell for most Linux distributions including the most popular distributions such as UbuntuFedora, Arch, Debian and even on the Raspberry Pi.

But bash is way beyond a simple place to enter commands. It's a powerful command processor where commands can be entered. Bash can also read and execute commands from a file, called a shell script. Like other shells, it supports filename globbing (wildcard matching), piping, command substitution, variables, and control structures for condition-testing and loops.

To finish our introduction, the name Bash is an acronym for Bourne Again Shell, a pun on the name of the Bourne shell that it replaces (and extends).

Why learn Bash

Due to its popularity, power and ubiquity, we strongly recommend that you learn it if you want to be comfortable in Linux and computers in general. Many skills you'll learn in your bash/OSS-journey will definitely carry over to Macs, Windows and well into your professional life.

Bash on Windows

Today, Bash can also be found on Windows via the Windows Subsystem for Linux (WSL for short). We will review how to get started on WSL real soon. Keep tuned!

Starting the Terminal

To start the terminal on Ubuntu (or any GNOME-based distro), simply type terminal on the Activities tab. KDE and Xfce users should also have equivalent terminal apps in their systems.

On Ubuntu, type terminal to open your first terminal

Clicking on the terminal icon should open a new terminal for you:

Your bash terminal on Linux

You can confirm that it's running bash by running the following command:

echo $SHELL
/bin/bash

Entering Commands

Entering commands in your terminal is straightforward, just type them. For example, here are some basic ones:

  • pwd - lists the current directory
  • ls - lists the files in the current directory
  • cd - change the current folder
  • cat - prints the contents of a file
  • cp - copies a file
  • mv - moves a file
  • rm - removes a file
  • mkdir - creates a new directory
Some simple commands on the terminal
The above list may seem a lot for a new user. Don't stress, with time you'll learn these tools and soon they'll be part of your muscle memory

Manual Page

Linux also has an interesting utility called man that is used for reading the manuals (documentation) of the programs, tools and libraries available on your system. To view Bash's manual, type:

man bash

To go the extra mile, we also recommend checking this related manual page:

man bash-builtins

Follow up video

To finish, we would like to point you to an online resource that will teach you Bash better than we could. Feel free to watch it at your own pace to get familiar with it. For the record, we have absolutely no affiliation we the video below, we just want you to learn Bash and Linux 😊

Conclusion

On this article we learned a little more about the Linux terminal and Bash. Bash is a fantastic tool that any Linux user should learn. We hope it helps!

See Also

Featured Article

What is a Shell in Linux?

Learn what is a shell in Linux, your shortcut to a successful career with Linux and open source software ...