Viewing and Connecting to an SMB Samba Share on Windows/Linux/Unix

This will give you the basic info needed to browse and connect to Samba shares from the command line.  From the GUI of Gnome or KDE etc, it is pretty standard and straight forward.  However, I've found very little guides on how to do it from the command line and if you're like me, a nerd who prefers command line for its simplicity and for remote use, this is the way to go.

First get a list of all the Samba/SMB shares on the target.

smbclient -L hostname (or IP address).

If you need to specify a specific username you would use:

smbclient -U username -L hostname 

If you are prompted for a password and you know one is not required, just hit enter (in this kind of case it doesn't matter what username you authenticate as).

The list of SMB Samba shares has been returned

Domain=[OURHOUSE] OS=[Unix] Server=[Samba 3.0.28-0.el4.9]

        Sharename       Type      Comment
        ---------       ----      -------
        DVDROMExternal  Disk
        dump            Disk
        driveshare      Disk

Connect to the chosen SMB Samba Share

smbclient \\hostname\sharename

Yes, you read it right.  The first part before the hostname contains 4 backslashes \\

And the part before share name contains two backslashes \

smb: > ls
  .                                   D        0  Fri Feb 27 08:50:50 2009
  ..                                  D        0  Thu Jan  8 14:32:19 2009
  New Folder                          D        0  Sat Jan 26 16:24:54 2008
  test                                D        0  Sun Sep  7 18:29:26 2008
  fdsfd                               D        0  Sun Jan 27 11:37:55 2008

You'll be prompted with something like the above.  Note that I did type "ls" to get the list of folders.

The rest is pretty normal and straight forward for anyone who has ever used command line ftp.

An SMB share retrieval example:

If you want to download a file called "test" just type:

mget test

If you want to recursively get a bunch of directories just do this:

recurse
prompt
mget *

The recurse is obvious, it means to get a directory and recursively so that means everything inside.

The prompt takes away the annoying prompt, that means for each transfer you wont' be prompted to manually confirm.


An alternate and preferred way using SMB over CIFS

If that annoys you, you can simply mount the share on your local system and then browse, retrieve and make/write files as you like (assuming your permissions on the SMB server allow for it).

Others may have had different experiences but I can only get mounting with CIFS working by using the IP and not the hostname.

mount -t cifs //192.168.1.24/driveshare /mnt/cifs -o user=guest,pass=bla

If you try with the hostname dmesg will produce this message:

CIFS VFS: cifs_mount failed w/return code = -22

 Mounting SAMBA SMB CIFS shares at boot time by using /etc/fstab

Just add a line like this to /etc/fstab

//192.168.1.24/driveshare /mnt/cifs cifs        user=guest,pass=bla 0 0

Be sure to modify the user and pass options if you require a specific user and password to connect to the share.

 

Latest Articles

  • Apache/Mod_SSL not serving the right/expected certificate?2010-03-09 04:09:36
  • Create/Enable SSL Certificates for Apache on Linux/Unix Systems eg. Redhat,Centos,Debian2010-03-09 04:07:21
  • MySQL Error "ERROR 1045 (28000): Access denied for user"2010-03-06 06:35:42
  • MySQL "Got error 28 from storage engine"2010-03-06 06:32:28
  • How to Track Down/Find Cause of Linux high disk iowait/wa2010-02-19 01:41:31
  • Mysqld Solution - Can't init databases /usr/libexec/mysqld: Can't read dir of '/tmp/' (Errcode: 13) /usr/libexec/mysqld: Can't create/write to file '/tmp/ibyP1qUC' (Errcode: 13) 100215 7:02:24 InnoDB: Error: unable to create temporary file; errno:2010-02-15 07:11:17
  • Windows Vista sysprep.exe /generalize error "The computer restarted unexpectedly or encountered an unexpected error. Windows installation cannot proceed. To install Windows, click "OK" to restart the computer, and then restart the installation."2010-02-13 10:08:29
  • Openvz "Container already locked" Error Message Solution/Fix2010-02-13 09:44:14
  • Adventures in pre-paid SIM Cards and data GPRS/Edge/3G in China with China Mobile in Shenzhen, Guangzhou, Shanghai, Beijing and other cities2010-02-12 08:37:57
  • iPhone Enable Tethering Manually Update ipcc Carrier Settings/Update via SSH2010-02-08 06:03:16
  • How To Enable 3rd/third party packages in RHEL/Redhat/Centos 4/5 Linux via RPMForge2010-01-17 16:44:41
  • How to avoid web content hijacking/copying/Force content to be accessed by only 1 domain name2010-01-17 16:39:39
  • SAMBA/SMB Share "Write" Access without Delete2009-12-19 20:04:22
  • The power of passive vs air cooling. Small fans make a world of difference.2009-12-18 13:22:52
  • Hard Drive Not Working/Not Detected By Your BIOS Anymore?2009-12-12 11:29:09
  • GRUB "Error 2: Bad file or directory type" 0.97 won2009-12-09 21:25:09
  • Unixbench Score with Glusterfs/Openvz & Quad Core Xeon - Updated with GlusterFS 2.0.8 & Optimized Client Config2009-11-29 01:26:44
  • Clustered/Distributed Network Filesystems, Which Ones live up to the hype?2009-11-28 22:19:13
  • Unixbench Score with Glusterfs/Openvz & Quad Core Xeon - Updated with GlusterFS 2.0.82009-11-28 22:04:16
  • yum error not working rpmdb: mmap: No such device TypeError: rpmdb open failed2009-11-23 00:06:42