Whilst it is possible to use one line to mount a share: (//servername/sharename /media/windowsshare cifs username=msusername,password=mspassword,iocharset=utf8,sec=ntlm 0 0), this is not recommended, since the username and password are available for all to view. This may not be a problem for you, but this post will take the extra steps of masking those details.
- Install the CIFS Utilities
sudo apt-get install cifs-utils - Create a directory where the share will be mounted. I personally like to create this mount in my home directory, but you can create it pretty much where ever you like:
sudo mkdir /home/<UbuntuUserName>/Server - Create a smbcredentials file:
sudo gedit ~/.smbcredentials - Add lines for the username and password (for the destination where the share is located):
username=<Username>
password=<Password> - Edit the smbcredentials file to prevent changes:
chmod 600 ~/.smbcredentials - Edit the /etc/fstab file with root privileges and add the following line:
//<Servername>/<Sharename> /home/<UbuntuUserName>\Server cifs credentials=/home/<UbuntuUserName>/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
Don't forget to save the file! - This can then be tested by typing the following command:
sudo mount -a
If this correctly mounts the share, it should work the next time you log on. - Note: In the latest versions of most file managers, these mounted shares are only available read only by default. If like me, you are used to a Windows environment, this can be a little annoying.
However, it is much more secure. To write to the mounted share, simply open the file manager as root (e.g. sudo pcmanfm)
Note: the following "variables" are used in the above steps:
<Username>
Username for accessing the remote share
Username for accessing the remote share
<Password>
Password for accessing remote share
<UbuntuUserName>
Local Ubuntu username
Password for accessing remote share
<UbuntuUserName>
Local Ubuntu username
<Servername>
Server name or IP address of the server housing the remote share
Server name or IP address of the server housing the remote share
<Sharename>
Share name on the remote server
Share name on the remote server