Mounting remote filesystems with smbfs
Posted by Steve on Fri 17 Jun 2005 at 11:43
Previously we've covered mounting remote filesystems using OpenSSH which works very well for most Unix servers. But when it comes to remotely mounting filesystems from Windows servers, or desktops, there's only one choice. The Samba file system module, smbfs.
Much like mounting remote filesystems with OpenSSH this involves the use of a kernel module, but unlike shfs there's no need to build this from source yourself.
The Debian kernel packages all come with the smbfs module built already, although if you compile your own kernel from source you might need to enable it yourself.
Samba is a very well known project in the Linux world, it allows you to do a lot of different things but most noticably:
- Communicate with a Microsoft Windows fileserver, domain server, or printer server.
- Impersonate a Microsoft Windows fileserver, domain server, or printer server.
Both the K desktop environment (KDE), and the GNOME desktop allow you to explore remote Samba shares, or Microsoft windows shares. However there are times when you cannot use these - for example if you wished to backup a remote machine from a shell script.
For these jobs the Samba File System kernel module, and tools, are a much better fit.
To mount a remote system directly upon your current system you'll need:
- The smbfs kernel module
- The smbfs package.
- A mountpoint - this is just an empty directory.
- The Name/IP address of the host to connect to.
- Login credentials to the remote share - both username and password.
- Local root privileges to do the mount, and load the kernel module.
If you don't already have the smbfs package installed you'll need to install it:
root@mystery:~# apt-get install smbfs
When this is installed you'll also get the samba-common package. If you're not already running a Samba server the installation of this package will ask a couple of questions about your workgroup name, etc. You may safely ignore those questions and just accept the defaults.
Once you have the smbfs package installed you can begin testing things.
As a small example lets assume I wish to mount the "C:" drive of remote machine "recurring.my.flat" to the local machine mystery.my.flat I would begin by loading the kernel module:
root@mystery:~# modprobe smbfs
You can cause this module to be loaded automatically as the machine boots by running:
root@mystery:~# echo 'smbfs' >> /etc/modules
Once the module is loaded I'll create a new directory to be the mount-point:
root@mystery:~# mkdir -p /mnt/recurring
This directory will be where all the remote files will be visible. To actually perform the mounting we have to run:
root@mystery:~# mount -t smbfs -o username=Administrator //recurring/c$ /mnt/recurring
If this command is successful you'll be prompted for the password to make the connection. To avoid this you can also specify the password for the connection on the command line as this example shows:
root@mystery:~# mount -t smbfs -o username=Administrator,password=Password //recurring/c$ /mnt/recurring
An invalid password, or lack of credentials will give you a response similar to this:
22077: session setup failed: ERRDOS - ERRnoaccess (Access denied.) SMB connection failed
If you receive an error message which is unrelated to authentication you should check the end of the "dmesg" output, by running:
root@mystery:~# dmesg | tail
If the output includes the following text then you're missing the smbfs package:
smbfs: mount_data version 1919251317 is not supported
Once you've successfully mounted the remote system you can explore from the comfort of your Debian machine:
root@mystery:~# cd /mnt/recurring/ root@mystery:/mnt/recurring# ls arcldr.exe Images System Volume Information arcsetup.exe IO.SYS six.avi AUTOEXEC.BAT MSDOS.SYS Untitled.zip boot.ini MyWorks Untitled.upd cat.zip NTDETECT.COM Utilities CONFIG.SYS ntldr Videos Documents and Settings pagefile.sys WINNT putty.exe Program Files WUTemp
You can also mount the filesystem via /etc/fstab - but note this will include your password in plain text to any local user upon the system:
//recurring/c$ /mnt/recurring smbfs defaults,user,noauto,username=Administrator,password=Password 0 0
To protect your passwords you can instead save them in a file, and pass that along instead - for example you could create the file /etc/recurring.smbpass which contains the username and password to use for the connection:
root@mystery:~# cat >/etc/recurring.smbpass <<EOF username=Administrator password=password EOF
By changing the permissions this can then be read only by the root user:
root@mystery:~# chmod 600 /etc/recurring.smbpass root@mystery:~# chown root.root /etc/recurring.smbpass
With the login details safely secured you can now mount the remote system using them :
root@mystery:/mnt# mount -t smbfs //recurring/c$ /mnt/recurring -o credentials=/etc/recurring.smbpass
Similarly you can adjust the mount line in /etc/fstab to read:
//recurring/c$ /mnt/recurring smbfs defaults,credentials=/etc/recurring.smbpass 0 0
This will cause the mount to be loaded whenever your machine boots - or if you run as root:
root@mystery:~# mount /mnt/recurring
[ Send Message | View Steve's Scratchpad | View Weblogs ]
rss2email will the job for you if you use the relevent feed.
As it is I currently use 60%+ of my bandwidth on people reading the feeds and ignoring most of the articles - so I'm not going to start sending out mass emails too! (Soon I think I'm going to start banning clients who poll the feeds too agressively, I'm still looking at a good piece of software to do that..)
(Another approach would be to use bloglines/livejournal/etc to see new posts).
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
From the command-line, you need quotes around the folder name like this:
# mount -t smbfs //bert/"My Documents" /mnt/bert_docs
In /etc/fstab, you need to use the OCTAL designator (\040) like this:
//bert/My\040Documents /mnt/bert_docs smbfs defaults,credentials=bert_pwd 0 0
[ Parent | Reply to this comment ]
The use of cifs seems to have superceeded smbfs.
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
The 2Gb limit is probably related to the filesystem, or the tools not using LARGEFILE support.
But I've managed to mount shares from Windows 2000, XP, and 2003 server without any problems.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
add -o lfs to mount
it's permanent problem with linux-related software
buggy man pages, use source luke :-p
try smbmount --help to see this hint
abbatini@poczta.onet.pl
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Certainly only one choice unless you're running a newer kernel ..
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
NT_STATUS_SHARING_VIOLATION opening remote file
When I run windows xp from within vmware I can fully acces the same share using the same credentials, so it does not look like a permissions issue.
When I try to mount a share I get the following error:
32710: session setup failed: ERRDOS - ERRnoaccess (Access denied.)
SMB connection failed
Needles to say it is driving me nuts.
Dejan
[ Parent | Reply to this comment ]
VAC
[ Parent | Reply to this comment ]
> mount -t smbfs -o username=foo,password=blah //GAMING/Music /srv/Music
28784: session request to GAMING failed (Not listening on called name)
28784: session request to *SMBSERVER failed (Not listening on called name)
If you're getting this as well, ensure that you can connect to port 445 on the destination machine (simple, telnet
Control Panel -> Network Connections -> Local Area Connection.
Make sure 'File and Printer Sharing for Microsoft Networks' is selected. Turning this on solved my problem.
[ Parent | Reply to this comment ]
I enter:
mount -smbfs -o username=my_name@my_org.com //pc/welcome /share
and get the answer:
session setup failed: ERRDOS - ERRnoaccess (Access denied.) SMB connection failed
then i created local user on windows machine and run the previous command again with new name and successfully mounted fs.
is it possible to mount a partititon using domain credentials?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
account=domain\\user
password=password
domain can be substituted with hostname of the machine if you are using a local account.
[ Parent | Reply to this comment ]
mount -t smbfs -o username={user},password={pass},workgroup={domain} //{SERVER}/{SHARING} {MOUNT PATH}
Axell.
[ Parent | Reply to this comment ]
E.g. I have an fstab entry
//server/dir /mnt/dir smbfs noauto,rw,users,uid=foo,username=bar/staff 0 0
It allows root to say : mount /mnt/dir and this works as expected:
it prompts for the password (of the remote user "bar" of the (Windows) group "staff" on the server "server"), and then mounts the remote FS as this user, locally appearing as owned by the local user "foo" (I think - in fact, for me foo=bar).
If a non-root user does "mount /mnt/dir", it also prompts for a password, but then issues an error :
cannot mount on /mnt/dir: Operation not permitted.
smbmnt failed: 1
I vaguely remember that in former times, this(?) problem could be resolved by setting some smb-related program suid root, but this seems no more possible.
The interest of this construct is to allow several users to mount and unmount a (say, group-owned) remote file system - or individual file systems, by adding an fstab entry for each user needing it.
(Often it is impracticable to mount smbfs's on boot since a network error can make the whole bios hang for a moment, so it's safer to mount the smbfs on need and umount it afterwards.)
[ Parent | Reply to this comment ]
Thank you so much!!
Regards
[ Parent | Reply to this comment ]
I have just a question: when I mount remote samba shares as per your advice I can access and modify the files only as root as their owner is root... How can I let normal users manage those files?
Thank you once more!
[ Parent | Reply to this comment ]
nb: uid and gid specifie the files/folders owner
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
timeout connecting to 10.100.20.1:139
Error connecting to 10.100.20.1 (Operation already in progress)
6739: Connection to bighome.iitb.ac.in failed
SMB connection failed
The command i used is:
sudo mount -t smbfs -o username=username,port=139 //bighome.iitb.ac.in/username /mnt/Bighome/
Please help me with this problem
Thanks,
Arun
[ Parent | Reply to this comment ]
I've been scanning through heaps of samba-related how-tos in order to mount a directory on a remote samba server. This is one of the few that explains it properly.
Thanks again!
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
I have mount a smbfs under SLES10 with:
mount -t smbfs //server/share -o username=user/domain,password=pass /mnt/windows/
Yes, behind username= as first the username and then the domain...
All other dosn't work p.e. (-o username=user,password=pass,domain=domain).
Regards Michael.
[ Parent | Reply to this comment ]
I have a smb share called DOWNSTAIRS with the C: shared. I try "//DOWNSTAIRS/c$" but it returns "mount error: could not resolve address for downstairs: Name or service not known"
This lists the shares and says everything is okay however...
$ smbclient -L DOWNSTAIRS
Domain=[UPSTAIRS] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
Sharename Type Comment
--------- ---- -------
C$ Disk Default share
{snip}
what am I doing wrong?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]