How to mount samba drive in Linux using command line

8,506

First, unless already installed, install cifs-utils as follows:

sudo apt-get install cifs-utils

Then, choose a path where to place a file containing the credentials to access your shared folder. Let's say /home/.smbcredentials, as an instance.
So, open that file and write your credentials as follows:

usename=yourUsername
password=yourPassword

Also, decide where to mount your shared folder. Let's say /myfolder, as an instance.

Now, assuming you want your network folder to be accessible as soon as your Linux system is started, edit the /etc/fstab file. You can use nano as follows:

sudo nano /etc/fstab

Then, you should be able to see something already written to that file. Therefore, just append one line to the bottom:

//yourHostNameOrIpAddress/path/to/your/shared/folder  /your/mount/point  cifs  guest,iocharset=utf8,file_mode=0777,dir_mode=0777,credentials=/path/to/the/credentials/file

That's all, reboot your Linux system by typing reboot -f and your network drive will be mounted.

As an alternative to rebooting, running /etc/fstab as superuser should work:

sudo /etc/fstab
Share:
8,506

Related videos on Youtube

Davide Cannizzo
Author by

Davide Cannizzo

I've been programming since I was 9 years old. Now, I'm mostly busy with compiler & language design and development, static analyzers, IDEs, and IDE plugins for some languages I've defined myself. I'm also working on some OS development, a way that can't ever be imagined — some very amazing stuff everyone is unawarely waiting for (I can only say it will be different from everything we’ve gotten used to). Other than that, I currently develop software using (for the most) C#, Kotlin, or C++, Android apps in Kotlin, and websites (usually with Kotlin multiplatform, as I happen to hate JavaScript — too much of a mix of paradigms, while missing a real foundation). I love innovating stuff to make everything newer, faster, and more appealing to the end–user. UI design is one of my first thoughts when developing software aimed at end–users, and I'm mostly inspired by Google's Material Design. Find me out on Quora, where I mostly explain things.

Updated on September 18, 2022

Comments

  • Davide Cannizzo
    Davide Cannizzo over 1 year

    I've got a shared folder on a Windows computer, and I'd like to mount it on a server running Ubuntu Server.

    How can I mount a samba drive from the command line?

  • Nate C-K
    Nate C-K over 2 years
    Other ways to mount the new drive: sudo mount /your/mount/point (mount that drive using the settings in /etc/fstab) or sudo mount -a (mount all drives listed in /etc/fstab)