Linux as a Client to Windows SMB Shares

This article briefly explains how to access Windows SMB shares in Linux. Linux is a client here.

If you want to read about using Linux as a Samba server to serve files to Windows clients, see Samba Quickstart.

© 2005 Tero Karvinen http://www.iki.fi/karvinen
Quick Mini-HOWTO

This chapter contains just the required commands without any additional testing.

Here, we want to connect to smb://windowsuser:windowspassword@windowsserver/share (workgroup WINDOWSGANG), so we have:

Windows Server: “windowsserver”
Windows Share: “share”
Windows Username: “windowsuser”
Windows Password: “windowspassword”
Windows Workgroup: “WINDOWSGANG”
Linux User: “linuxboy”
Linux Group (for user linuxboy): “linuxboy”
Mount Point (an empty directory): “mymountpoint”

Edit $HOME/sambapass (here: /home/linuxboy/sambapass)

# $HOME/sambapass
username = windowsuser
password = windowspassword
domain   = WINDOWSGANG

Create an empty directory (a mount point):

$ mkdir $HOME/mymountpoint/

As root, edit /etc/fstab, add this line in the end:

//windowsserver/share /home/tee/mymountpoint
smbfs
credentials=/home/tee/sambapass,uid=linuxboy,gid=linuxboy,dmask=700,fmask=700
0       0

Put the above in a single line, I’ve splitted it only for readability. In options (credentials…fmask=700) there are no spaces. Numbers are zeros.

Then, as root, mount all mounts mentioned in fstab:

# mount -a

Mount often warns you a couple of times about “session request to windowsserver failed (Called name not present)”, but with ls you can see that the directory was mounted.

Test is as normal user (here: linuxboy)

$ touch $HOME/mymountpoint/tero.txt
$ ls $HOME/mymountpoint/
tero.txt

Well done, you have mounted a windows share to Linux using just command line. If you ever have to reboot, it will be automatically mounted again.
Step-by-Step Process for Troubleshooting

If the above worked for you, good. No need to read more, unless you want to learn troubleshooting.

$ smbclient -L 172.28.1.133
session request to 172.28.1.133 failed (Called name not present)
session request to 172 failed (Called name not present)
Password:
Anonymous login successful
Domain=[WORKGROUP] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
Sharename       Type      Comment
Error returning browse list: NT_STATUS_ACCESS_DENIED

===

$ smbclient -L 172.28.1.133 -U kaapo%alofoiyl2890xb
session request to 172.28.1.133 failed (Called name not present)
session request to 172 failed (Called name not present)
Domain=[GHETTOYO] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]

Sharename       Type      Comment
———       —-      ——-
IPC$            IPC       Remote IPC
D$              Disk      Default share
ADMIN$          Disk      Remote Admin
C$              Disk      Default share
tero            Disk      Teron testijako
http://www.iki.fi/karvinen
jako            Disk
session request to 172.28.1.133 failed (Called name not present)
session request to 172 failed (Called name not present)
Domain=[GHETTOYO] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]

Server               Comment
———            ——-

Workgroup            Master
———            ——-
$ smbclient //172.28.1.133/tero -U kaapo%alofoiyl2890xb

$ smbclient //172.28.1.133/tero -U kaapo%alofoiyl2890xb -c dir
session request to 172.28.1.133 failed (Called name not present)
session request to 172 failed (Called name not present)
Domain=[GHETTOYO] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
.                                   D        0  Thu Dec  1 13:44:57
2005
..                                  D        0  Thu Dec  1 13:44:57
2005

37032 blocks of size 2097152. 36219 blocks available

===

$ cat sambapass
username = kaapo
password = alofoiyl2890xb
domain   = WORKGROUP

$ smbclient -L 172.28.1.133 -A sambapass
session request to 172.28.1.133 failed (Called name not present)
session request to 172 failed (Called name not present)
Domain=[GHETTOYO] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]

Sharename       Type      Comment
———       —-      ——-
IPC$            IPC       Remote IPC
D$              Disk      Default share
ADMIN$          Disk      Remote Admin
C$              Disk      Default share
tero            Disk      Teron testijako http://www.iki.fi/karvinen
jako            Disk

===

$ sudo mount -t smbfs -o credentials=/home/tee/sambapass
//172.28.1.133/tero/ /home/tee/teroghettoy/
mount: wrong fs type, bad option, bad superblock on
//172.28.1.133/tero/,
missing codepage or other error
In some cases useful info is found in syslog – try
dmesg | tail  or so
(=> smbfs not installed)
$ sudo apt-get install smbfs

$ sudo mount -t smbfs -o credentials=/home/tee/sambapass //172.28.1.133/tero /home/tee/teroghettoy/
30872: session request to 172.28.1.133 failed (Called name not present)
30872: session request to 172 failed (Called name not present)
(but it still mounted)
mount |grep teroghettoy
//172.28.1.133/tero on /home/tee/teroghettoy type smbfs (rw)
$ sudo umount teroghettoy/
$ sudo umount teroghettoy/
umount: teroghettoy/: not mounted

$ sudo mount -t smbfs -o credentials=/home/tee/sambapass,uid=tee,gid=tee,dmask=700,fmask=700 //172.28.1.133/tero /home/tee/teroghettoy/

$ sudo mount
-t smbfs
-o credentials=/home/tee/sambapass,uid=tee,gid=tee,dmask=700,fmask=700
//172.28.1.133/tero /home/tee/teroghettoy/

Now writing works.

$ touch teroghettoy/foobar
$ ls teroghettoy/
foobar

$ grep teroghettoy /etc/fstab
//172.28.1.133/tero /home/tee/teroghettoy       smbfs   \
credentials=/home/tee/sambapass,uid=tee,gid=tee,dmask=700,fmask=700     \
0       0

$ sudo mount -a

$ mount |grep teroghettoy
//172.28.1.133/tero on /home/tee/teroghettoy type smbfs (rw)

 

another article :   http://www.madirish.net/node/77

评论关闭。