HostOnNet Blog

How to Access Windows Share in Linux

Looking for Linux Server Admin or WordPress Expert? We can help.

Samba is used to share fine between Linux and Windows computers in a network.

To mount an smbfs share from a Linux workstation at the command line, you can use either the smbmount command or use mount -t smbfs. Both command will work the same. When you use mount -t smbfs, the mount program actually passes the command over to smbmount for execution. Throughout this document I’ll use smbmount instead of mount -t smbfs.

An example would look like this:

smbmount //servername/sharename /mountdirectory -o username=mywindowsusername,password=mywindowspassword

The mount equivelant is:

mount -t smbfs //servername/sharename /mountdirectory -o username=mywindowsusername,password=mywindowspassword

//servername/sharename refers to the name of the Windows computer and the name of the share.

/mountdirectory refers to the directory you use as the mount point on the Linux workstation. It can be any directory as long as the user executing the command has rights to it.

Whether you need to supply a username and password depends on what type of security you have on the Windows share. If you have a share created with no password on it, you shouldn’t need to provide a username and password. If the share happens to be on a Windows NT server that is part of a domain, you would need to provide a domain login name and password.

Making the Mount Permanent

smbmount does not make the mount permanent. If the Linux workstation is rebooted, you will have to mount the share again. To make the mount occur each time you start the Linux workstation, you can put an entry in your /etc/fstab file. An example file would look like this:

LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
LABEL=/home /home ext3 defaults 1 2
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda3 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0
/dev/hdd4 /mnt/zip100.0 auto noauto,owner,kudzu 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
//servername/sharename /mountdirectory smbfs username=windowsuserename,password=windowspassword 0 0

The last line in the file is the line that will mount the Windows share. You would add a line similar to that in your /etc/fstab file for each share you want to mount. Once again the username and password are only needed if the Windows share is set up to require them. If a username and password are not required, you may just replace them with the word defaults.

An important thing to remember is that there is no space between the comma and the word password. If you put a space there, it won’t work.

Providing Security

The /etc/fstab is readable by everyone so it obviously wouldn’t be a good idea to have your Windows password in it. The way to get around this is by using what is known as a credentials file. This is a file that contains just the username and password. The best place to put this file would be in your home directory. Here is how to do it.

Create a file in your home directory named .smbpasswd (the period at the start of the filename makes it a hidden file). Modifify the permissions on the file so only you have permission to read and write to it. The only thing in the file is your Windows username and password. Here’s the commands you would enter to create the credentials file:

echo username=mywindowsusername > .smbpasswd
echo password=mywindowspassword >> .smbpasswd
chmod 600 .smbpasswd

Substitute your Windows username and password in the commands. No one else except root would be able to read the contents of this file.

Once that is created, you would modify the line in the /etc/fstab file to look like this:

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpasswd 0 0

You can also use the credentials option in the smbmount command for security reasons. That command would look like this:

smbmount //servername/sharename /mountdirectory -o credentials=/home/myhomedirectory/.smbpasswd

Providing Read/Write Access to the Share

Another problem with mounting the Windows share as shown in the /etc/fstab file above is that only the root user would have read/write access to the share. All other users would have read only access to it. If you wanted read/write access to it for yourself, you need to specify your userid or groupid. That would change the line in /etc/fstab to look like this:

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/. smbpasswd,uid=mylinuxusername,gid=mylinuxgroupname 0 0

Whatever user and or group you specified in the line would have read/write access to the mounted share. You can use either the user or group name or the user or group numerical ID. Either should work.

If you had several users you wanted to have read/write access to it, create a group and add those users to the group. Then specify just that groupid in the /etc/fstab file. You wouldn’t need to specify a userid. The line in etc/fstab would look like this:

//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/. smbpasswd,gid=sambausersgroup 0 0

You can see the man pages on smbmount, smbumount, mount, and fstab for more details.


If you have trouble mounting your Windows shares from /etc/fstab, here are some things to try.

The most important thing is to try to mount the share using the mount -t smbfs command from the command line. This is what will be executed when the the Linux workstation is booted up and the mounts in /etc/fstab are initialized. If you can’t sucessfully mount the share with mount -t smbfs, it won’t work in /etc/fstab. Work the bugs out with mount -t smbfs. Once it works, it should then work in /etc/fstab.

One of the most common problems with mount -t smbfs is a file not found error. The file not found is smbmnt, which is used by smbmount. It’s usually a result of the smbmnt command not being in the path when the mount command executes. The mount command usually resides in the /bin directory and smbmnt resides in /usr/bin. To fix this problem, you need to create links to smbmnt in the /bin directory. To accomplish this, execute these commands as root:

ln -s /usr/bin/smbmnt /bin/smbmnt
ln -s /usr/bin/smbmount /bin/smbmount

Another problem occurs when a non-root user tries to mount a Windows share using smbmount. To allow them to do it you need to setuid root the smbmnt command. Since smbmnt usually resides in /usr/bin, you can accomplish it with this command as root:

chmod u+s /usr/bin/smbmnt

This will not work if you setuid the smbmount command. It is specifically written so that it won’t execute if it is setuid root.

To allow non-root users to unmount the shares, you need to setuid the smbumount command. Execute this as root:

chmod u+s /usr/bin/smbumount

Posted in Uncategorized. Bookmark the permalink.

One Response to How to Access Windows Share in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.