How to mount Windows (SMB) shares on Ubuntu Linux

Posted on April 30th, 2010 by David Luhman and tagged , .

Here's how to mount SMB (Windows) shares on an Ubuntu system. Most of this assumes you're the root user. You may have to prepend 'sudo' to many commands depending on your situation.

First, you may have to install the following :

  • # apt-get install smbfs smbclient

You can do a simple interactive connect with this :

  • # smbclient \\YOUR_SERVER\myusername-U myusername -W YOUR_WORKGROUP

This will at least show the SMB share is reachable.

Next, to enable auto-mounting on system start, you'll want to add one of the following to your /etc/fstab file :

  • //YOURSERVER/sharename /share/sharename smbfs auto,username=myusername,password=SECRET,uid=1000,umask=000,user 0 0
  • //YOURSERVER/sharename /share/sharename smbfs auto,credentials=/root/.credentials,uid=1000,umask=000,user 0 0

You'll need to create the directory /share/sharename on your Linux system if you haven't done so already.

The second, credentialed entry above is more secure since everyone can read /etc/fstab.

The file /root/.credentials-smb should have the following :

username=your_smb_username
password=your_smb_password

It also should have these permissions : chmod 600 /root/.credentials-smb

You can see if your SMB share mounts with :

  • # mount -vvv /share/sharename (or mount -a -vvv)

The -vvv provides verbose output for debugging.

Here's a great reference on this :

Comments

cifs is a more modern replacement for smbfs

Nice post. though afaik I'd rather use cifs instead of smbfs. cifs is a modern replacement for smbfs:

/YOURSERVER/sharename /share/sharename cifs auto,username=myusername,password=SECRET,uid=1000,umask=000,user 0 0

Comment by Anonymous (not verified) on Apr 25th, 2011 at 5:38 am

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options