Tuesday, February 15, 2011

Connect to Windows shares from Linux ( Samba Guide)

To access Windows shares from our Linux PC.
First we need to install smbclient
On Debian
sudo aptitude install smbclient
It will ask
1. for workgroup, type in the same workgroup you have configured on Windows
2. whether or not to use encrypted passwotd, select ‘Yes’
3. if it should get WINS server’s IP address from DHCP or not, select ‘Yes’ or ‘No’ as appropriate.
On Red hat/Centos/Suse
yum install smbclient
Let’s first find which machines are advertising their shares
findsmb
                                *=DMB
                                +=LMB
IP ADDR          NETBIOS NAME     WORKGROUP/OS/VERSION
---------------------------------------------------------------------
192.168.1.2   Rahul-PC      +[WORKGROUP] [Windows 5.1] [Windows 2000 LAN Manager]
192.168.1.3   Harish-PC     +[WORKGROUP] [Windows 5.1] [Windows 2000 LAN Manager]
Next find what are shared on the windows box
sbmclient -L windows_machine_name -U username
For me it would be like this
smbclient -L Rahul-PC -U testuser
Password:
Domain=[Rahul-PC] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Sharename       Type      Comment
        ---------                ----           -------
        IPC$                 IPC           Remote IPC
        REPORTS             Disk
        ADMIN$              Disk           Remote Admin
        C$                  Disk           Default share
Domain=[Rahul-PC] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Server                   Comment
        ---------                    -------

        Workgroup                Master
        ---------                    -------
Provide the password for the testuser you have on the windows PC.
Now we want to mount a shared directory
First create a directory to mount the share on
mkdir /mnt/mount_point_name
In my case, it is
mkdir /mnt/reports
Next mount the share on the above created mount point directory
mount -t smbfs -o username=windows_username,password=windows_pc_ password   //windows_pc_name_or_IP/share_name   /mnt/mount_point_name
For me, it looks like below
mount -t smbfs -o username=testuser,password=secret //192.168.1.2/$C /mnt/reports
Change directory to the mount point
cd /mnt/reports
to see files/folders in the windows share. Now you can copy to/from it as if it was a local directory, do
ls 

No comments:

Post a Comment