Mounting a Windows Share to the Linux File System
Novell Cool Solutions: Feature
By Michael L. Farrell
Digg This -
Posted: 21 Sep 2007
Many of us are familiar with the traditional way to access Windows network shares on a Linux desktop via KDE's "smb://" URL handler. However you may not know that there is an alternative, more efficient and more flexible solution for doing this.
This is done by using the mount.cifs tool to mount the network share to a point (directory) on the local filesystem. Furthermore, if you want to directly access network files from non-kde or non-gnome programs, then this is the only way to do it.
Before continuing, you should verify that you have installed the cifs-mount RPM package on your system using YaST.
The mount procedure
This extremely simple command, will mount a windows network path to any path on the local filesystem. Note that this must be done with root privileges.
otherbox:~ # mount.cifs "//slickbox/users" /mnt -o user=kain Password: <type in windows network password here> otherbox:~ # ls /mnt generic kain slickbox:~ #
Above, "slickbox" is the host, "/users" is the share that we wish to access, and "/mnt" is the desired mount point on the local filesystem. It's also important to specify the user name needed to access the remote computer.
When we are finished with the share, we simply unmount the share from the mount point.
otherbox:~ # umount /mnt Password: <type in windows network password here> otherbox:~ # ls /mnt generic kain otherbox:~ #
A better way
You may notice from above, that the root user will be the only user capable of writing to the network share (if the share has writing enabled of course). This is often a nuisance as many of us do our file management from our user accounts in a graphical file manager. To enable this, we add the share to the list of permanently associated mount points in the /etc/fstab file.
First let's create a more suitable name for our mount point
otherbox:~ # mkdir /SlickboxUsers otherbox:~ # chown kain.users /SlickboxUsers
Make sure to change the ownership of the mount point as done above to determine who can mount the network share. For cifs mounts, it seems that you have to be the owner of the mount point.
Next, we alter the /sbin/mount.cifs and /sbin/umount.cifs binaries to execute with root permissions. This is done by setting the SUID bit.
otherbox:~ # chmod +s /sbin/mount.cifs otherbox:~ # chmod +s /sbin/umount.cifs
For security reasons, be sure to do this only on a system where you trust the users who can execute mount.cifs & umount.cifs. Additionally, you can restrict the execution privileges to a group of users though as stated above, only one user will be able to mount the share.
Now, we're ready to add to the fstab file. The fstab file is the primary configuration file for all of the accessible data volumes on your computer; from your hard drives, to your DVD-ROM. For this reason, extra care should be taken while editing the file and as always, you should make backup copies of any edited system file.
A basic /etc/fstab file is similar to the following:
/dev/sdb6 / reiserfs acl,user_xattr 1 1 /dev/sdb7 /home reiserfs acl,user_xattr 1 2 ....
Where the first column contains the device or source of the filesystem, the second column contains the mount point, the fourth column contains the filesystem type, and the remainder of the each entry contains filesystem-specific options.
To permanently add the Windows network share, we add the following line to /etc/fstab
//slickbox/users /SlickboxUsers cifs user=kain,pass=userpass,rw,users 0 0
Note that this method requires your password to be present in plaintext in the /etc/fstab file, so you may want to alter permissions on who can read the file.
otherbox:~ # chmod 600 /etc/fstab
And that's it! Now, as your regular user, you can access the share!
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com