Connecting to a Windows Shared Drive from CentOS using smbclient

What is the quickest way to access a Windows Shared Drive from CentOS ? Use smbclient !

It’s an FTP-like client to access SMB/CIFS resources on a server and its part of the “samba-client” package which is installed by default on CentOS.

[laurent@localhost Downloads]$ rpm -qf /usr/bin/smbclient
samba-client-3.5.10-114.el6.i686

The firewall is pre-configured so you don’t need to change anything to use it:

If you look on the internet, you’ll find lots of posts telling you to use this syntax: smbclient [SHARED_DRIVE_UNC_PATH] -U [username]. But if your target Windows server belongs to a domain, you’ll get an NT_STATUS_LOGON_FAILURE error:

[laurent@localhost Downloads]$ smbclient //10.6.9.206/tmp -U laurent
Enter laurent's password:
session request to 10.6.9.206 failed (Called name not present)
session setup failed: NT_STATUS_LOGON_FAILURE

That’s because the domain name must be provided using the -W option. Also (and I must say that I lost a couple of minutes before of this), the password that you must enter is the one from the domain you want to connect to, not the one from your local Linux account.

[laurent@localhost Downloads]$ smbclient //10.6.9.206/tmp -U laurent -W entropysoft
Enter laurent's password:
Domain=[ENTROPYSOFT] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
 smb: \>

From there, you can navigate in the target system using the “ls” & “cd” commands and upload/download files using the “put” & “get” commands: see the smbclient man pages for more information.

smb: \> ls
 . DR 0 Fri Oct 5 09:27:04 2012
 .. DR 0 Fri Oct 5 09:27:04 2012
 activity_lifecycle.png A 82637 Mon Sep 3 14:01:54 2012
 AllowImperso.ps1 A 387 Mon Dec 12 16:03:37 2011
 amazon.pem 1696 Thu Aug 30 13:17:43 2012
 amazon.ppk A 1464 Wed Sep 12 19:41:54 2012

37897 blocks of size 8388608. 17669 blocks available
smb: \> get activity_lifecycle.png
getting file \activity_lifecycle.png of size 82637 as activity_lifecycle.png (2017.5 KiloBytes/sec) (average 2017.5 KiloBytes/sec)
smb: \>

Laurent KUBASKI

Advertisements

Fixing the “non appearing files” issue when sharing files with SAMBA on CentOS

OK, I easily lost 8 hours trying to fix this issue:

  • installed SAMBA on CentOS
  • correctly configured smb.conf (security=user, writable=yes)
  • created a user account and declared it using smbpasswd
  • made sure that this user had full read/write access to the shared folder
  • made sure that the firewall was allowing SAMBA traffic

Then, from a Windows 7 PC, I used the ‘Map network drive” option, connected to my SAMBA shared drive, entered my SAMBA user name and password… and then what ?

  • only read-only access to the shared drive
  • only folders were visible, no files whatsoever

Do you know why ? Because SELinux is activated by default on CentOS.

To check if this is the case for you, use the ‘sestatus’ command: if you get an ‘enabled’ result, then you may want to disable it by following the procedure detailed here.

Laurent KUBASKI