Sunday, 24 May 2015

Mounting Windows Shares in Ubuntu

In a mixed Windows/Ubuntu environment, it is often the case the you need to mount a Windows a share from within Ubuntu.  This can be done on an ad-hoc basis, or at every log on.

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.

  1. Install the CIFS Utilities
        sudo apt-get install cifs-utils
  2. 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
  3. Create a smbcredentials file:
        sudo gedit ~/.smbcredentials
  4. Add lines for the username and password (for the destination where the share is located):
        username=<Username>
        password=<Password>

  5. Edit the smbcredentials file to prevent changes:
        chmod 600 ~/.smbcredentials
  6. 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!
  7. 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.
  8. 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
<Password>
    Password for accessing remote share
<UbuntuUserName>
    Local Ubuntu username
<Servername>
    Server name or IP address of the server housing the remote share
<Sharename>
    Share name on the remote server

No comments:

Post a Comment