LINUX – Samba and Windows

I often find myself connecting to shares from  Windows to Linux and vice versa and I keep forgetting the commands – so here it is:

Connecting to a Windows share from Linux:

  • install winbind, cifs-utils and smbclient packages
  • change nsswitch.conf file (add/change this line: hosts: files wins dns ), then restart network
  • to see what shares are available on Windows box:
root@server1# smbclient -L //10.0.0.243 -U username
Enter username's password:
Domain=[contoso] OS=[Windows Server 2008 R2 Datacenter 7601 Service Pack 1] Server=[Windows Server 2008 R2 Datacenter 6.1]

Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
IPC$ IPC Remote IPC
share Disk
  • Mount the Windows share from console
mount -t cifs //10.0.0.243/share test -o username=linuxacademy,password=123456,rw,nounix,file_mode=0777
  • Mount the Windows share via fstab

>pre># stuff to put in the /etc/fstab file
# remote windows file share
//10.0.0.251/share /mnt/test cifs credentials=/root/.smbcredentials,rw,nounix,file_mode=0777,dir_mode=0777 0 0

and create the .smbcredentials file under root:

username=windows_username
password=windows_password

Connecting to a Linux share from Windows (configuring samba):

  • Install samba and samba-common
  • Configure /etc/samba/smb.conf file – add or uncomment and modify this section:
[homes]
   comment = Home Directories
   browseable = no
   writable = yes

[share]
   comment = Defalt Share
   path = /share/
   force user = samba
   force group = samba
   read only = no
   hosts allow =

Restart samba: service smbd restart

  • create samba username that matches windows account password:
root@server1:/# smbpasswd -a windows_username
New SMB password:
Retype new SMB password:
Added user windows_username.

Debian – Setting up Samba Standalone Server

Installation:

open terminal and install samba package and dependencies:

$sudo apt-get install libcupsys2 samba samba-common

The config:

open: /etc/samba/smb.conf

remove the content and paste this:

[global]
workgroup = WORKGROUP
netbios name = debianserver
server string = %h server (Samba %v)
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

[Shared]
  comment = Shared Drive
  path = /home/shared/
  valid users = @users
  force group = users
  create mask = 0660
  directory mask = 0771
  writable = yes

[homes]
   comment = Home Directories
   browseable = no
   valid users = %S
   writable = yes
   create mask = 0700
   directory mask = 0700

 

Add users:

useradd user1 -m -G users

Set a password for tom in the Linux system user database. If the user user1 should not be able to log in to the Linux system, skip this step.

passwd user1

-> Enter the password for the new user.

Now add the user to the Samba user database:

smbpasswd -a user1

-> Enter the password for the new user.

Now from Windows workstation browse the debian server, i.e.: \\10.0.0.10\ or \\10.0.0.10\user1

And restart samba service:

service samba restart

Job done.

 

Reference links:

http://www.howtoforge.com/debian-wheezy-standalone-server-with-tdbsam-backend

http://www.debianhelp.co.uk/samba.htm