Mounting Windows share in Ubuntu server terminal

Hi,

I’ve been trying to properly mount a windows share using Linux today. I’ve got it figured out using bits and pieces here and there, so I’m sharing!

The server at 192.168.1.123 has a share named “shareFolder”. We have login credentials for the server, being “admin” and “password”.

First of all, we need a directory to mount the drive to. For example, I created a directory “Windows” in my home folder.

mkdir ~/Windows

When you have the mountpoint, you might also need to install cifs-utils:

sudo apt-get install cifs-utils

Now we’re set to mount.

To simply do a one-time mount of a network drive we type in the following command:

sudo mount -t cifs -o username=admin,password=password //192.168.1.123/shareFolder /home/Windows

*”-t” specifies the mount type, being CIFS. “-o” means “options”, which we append by comma separated values. If e.g you leave out the password parameter it will prompt you for your password.

If you now navigate to that directory and perform an “ls” you will see the directories and files.

To mount a drive automatically when you log in to your server we need to edit the “/etc/fstab” file.

sudo vi /etc/fstab

This has a lot of stuff in it, but you can disregard that. We need to append one line at the end being the following:

//192.168.1.123/shareFolder /home/Windows cifs user=admin,password=password,uid=1000 0 0

If you have a shared folder with a space in the name, you replace the white space with 40. I have a folder named “Seagate 2TB” so I have the following line:

//192.168.1.123/Seagate\0402TB /home/Windows cifs user=admin,password=password,uid=1000 0 0

The “uid=1000” is my ID on my client ubuntu machine. You can find this out by simply typing “id” in an empty terminal. This makes sure I am the owner of the share. Also, you can use single quotes for a one-time mount, but you can not use them in /etc/fstab!

To make things work you’ll need to reboot. To see if it works you can simply list the contents of the directory.

cd ~/Windows
ls

And that’s how I got it working. I hope it can be of service for anyone 🙂

Christophe,