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

 

 


Posted by Anonymous (213.164.xx.xx) on Fri 17 Jun 2005 at 12:49
e-mail updates of new articles please!

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Fri 17 Jun 2005 at 12:53
[ 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 ]

Posted by Anonymous (24.210.xx.xx) on Wed 28 Dec 2005 at 18:15
Good article. I finally got smbfs to work. But many Windows folder names contain spaces (for example, "My Documents"), you need to explain how to handle this on the command-line and in /etc/fstab.

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 ]

Posted by Anonymous (193.195.xx.xx) on Fri 17 Jun 2005 at 14:27
I've had problems using smbfs to mount shares on Windows 2003 servers and also for transferring files >2GB.

The use of cifs seems to have superceeded smbfs.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Sat 18 Jun 2005 at 12:52
[ 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 ]

Posted by Anonymous (213.134.xx.xx) on Mon 20 Jun 2005 at 18:11
Hi,

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 ]

Posted by Anonymous (129.132.xx.xx) on Sat 18 Jun 2005 at 12:45
I've never got to mount samba shares with german umlauts correctly? i've tried the iocharset and codepage option but haven't had any success :-(( i don't know if its the combination of codepages on the samba server AND client or if it depends on the locales settings of the client? any hints? i've googled and found a lot people with the same or similar problem but not THE solution :-(

[ Parent | Reply to this comment ]

Posted by Anonymous (82.75.xx.xx) on Sun 19 Jun 2005 at 02:59
Please know that uid/gid forcing under Sarge is broken. The bug-fix just came in after Sarge went stable. So if you want to force a uid/gid on a mount you have to apt-pin it.

[ Parent | Reply to this comment ]

Posted by Anonymous (128.8.xx.xx) on Mon 20 Jun 2005 at 14:21
I think this article doesn't explain adequately the whole issues of how to handle user permissions, which can be a problem on a multi-user computer. For example, there is no mention of the uid/gid issue. Since I am running unstable, writing to the filesystem has started to work for me, but it is balky. It usually doesn't return to the prompt after a command, I have to Control-C out. Sometimes the write has taken place and sometimes it hasn't.

[ Parent | Reply to this comment ]

Posted by Anonymous (137.224.xx.xx) on Tue 21 Jun 2005 at 11:38
only one choice? I thought the cifs module is also quite a valid choice, and in some situations even a better choice.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Tue 21 Jun 2005 at 11:39
[ 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 ]

Posted by dejan (69.194.xx.xx) on Tue 5 Jul 2005 at 02:40
I've been using samba for years now without a problem, but about a week ago, IT(windows) people at work did some "critical updates" for windows 2003 server and now I can't mount windows shares any more. I can connect with smbclient and list get and delete! files, but I can't put (write) a file. When I try that I get:
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 ]

Posted by Anonymous (148.175.xx.xx) on Tue 30 Aug 2005 at 19:48
Excellent help! This site is great for accurate help files. Thank you.

VAC

[ Parent | Reply to this comment ]

Posted by Anonymous (24.219.xx.xx) on Sat 21 Jan 2006 at 05:12
This is a problem that I encountered while attempting to mount a Windows share from a Linux machine was the following.

> 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 ]

Posted by Anonymous (213.184.xx.xx) on Tue 8 Aug 2006 at 12:30
Hi! could you help me to resolve the problem when i try to mount with domain user name?
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 ]

Posted by oxtan (80.126.xx.xx) on Wed 9 Aug 2006 at 19:31
[ View Weblogs ]
you could try using the domain\user notation, it works in windows only environments with tools like psexec, for instance. Untested.

[ Parent | Reply to this comment ]

Posted by Anonymous (12.107.xx.xx) on Wed 15 Nov 2006 at 22:40
Here is how I used the domain\user notation.

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 ]

Posted by Anonymous (200.94.xx.xx) on Tue 22 May 2007 at 15:47
Hi, you can use this notation too:

mount -t smbfs -o username={user},password={pass},workgroup={domain} //{SERVER}/{SHARING} {MOUNT PATH}

Axell.

[ Parent | Reply to this comment ]

Posted by Anonymous (194.199.xx.xx) on Wed 3 Jan 2007 at 02:51
Mounting an smbfs with corresponding fstab entry does not seem to work for non-root users (as well on 2.6.18-3 as on 2.4.27-2).
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 ]

Posted by Anonymous (88.159.xx.xx) on Fri 19 Oct 2007 at 05:54
OMG. I've been looking for a solution similar to this for weeks, and then I gave up. Today for some reason I decided to give it another go, I used google, found this page within minutes, and it solved all my problems.

Thank you so much!!
Regards

[ Parent | Reply to this comment ]

Posted by Anonymous (151.75.xx.xx) on Mon 5 Nov 2007 at 13:32
Thank you very much for this useful guide!

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 ]

Posted by Anonymous (151.75.xx.xx) on Mon 5 Nov 2007 at 14:10
adding uid=LINUXUSER,gid=LINUXGROUP after the -o argument solved the problem, thanks.

nb: uid and gid specifie the files/folders owner

[ Parent | Reply to this comment ]

Posted by Anonymous (125.161.xx.xx) on Thu 10 Jan 2008 at 09:51
Thanks. the uid=USERID, gid=GROUPID bit help solve a problem for me as well.

[ Parent | Reply to this comment ]

Posted by Anonymous (203.78.xx.xx) on Sat 1 Dec 2007 at 10:18
When I try to mount an smbfs file system on my debian(lenny) system, I get the following error:

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 ]

Posted by Anonymous (81.170.xx.xx) on Tue 22 Jan 2008 at 11:07
Thank you!

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 ]

Posted by Anonymous (210.22.xx.xx) on Sun 3 Feb 2008 at 03:49
really good doc.

[ Parent | Reply to this comment ]

Posted by Anonymous (195.145.xx.xx) on Fri 7 Mar 2008 at 07:34
Hi, all.

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 ]

Posted by Anonymous (209.42.xx.xx) on Mon 1 Nov 2010 at 21:56
How are you connecting to "//recurring/c$"?

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 ]

Posted by ramack (70.57.xx.xx) on Tue 11 Jan 2011 at 17:35
Thank you! This helped me figure out how to mount a remote fs with read/write permissions by adding UID=MYUSERID

[ Parent | Reply to this comment ]

Posted by Anonymous (115.119.xx.xx) on Tue 13 Sep 2011 at 12:21
This command mounts a remote filesystem in your local machine. But is there a possibility where you can mount the remote filesystem in the remote machine itself??(but the command has to be fired in your local machine)

[ Parent | Reply to this comment ]

Posted by Anonymous (59.144.xx.xx) on Thu 17 Apr 2014 at 02:01
Hi, Can the same steps be used for other flavors of linux, like centos.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 821 votes ~ 10 comments )

 

 

Related Links