How To: Install Samba on CentOS with Batch Script to Map Drive on Windows
Samba is a service that runs on linux servers to be able to share folders with windows workstations. Samba is a great option for someone who does not want a windows server on their network but requires the use of shared drives. This is a free alternative to paying for a windows server for use on your network. The instructions below will install samba, create a network share from the linux server, and a script to map that share as a network drive on a windows computer.
Update 10/28/11: Changed smbpassword to smbpasswd when adding a user.
yum -y install samba /sbin/service smb start /sbin/chkconfig smb on mkdir /data mkdir /data/share chmod 766 /data/share mv /etc/samba/smb.conf /etc/samba/smb.conf.backup nano /etc/samba/smb.conf
Paste the below text into the smb.conf file
# Samba Config - smb.conf [global] workgroup = workgroup netbios name = linuxshare security = SHARE load printers = No default service = global path = /data available = No encrypt passwords = yes [share] writeable = yes admin users = windowsuser path = /data/share force user = root valid users = windowsuser public = yes available = yes
Create the user from the above config, windowsuser.
/usr/sbin/useradd windowsuser passwd windowsuser # use the same password for both smbpasswd -a windowsuser /sbin/service smb restart
To delete a user from samba and linux use the following commands.
/usr/sbin/userdel windowsuser smbpasswd -x windowsuser
This batch script for windows will map a drive letter to a samba share with authentication.
:sample samba copy :04/16/2011 - Jonathan Manning net use u: \\192.168.1.100\share /user:windowsuser passwordfromabove u: dir > c:\test.txt copy "test.txt" "c:\test.txt" c: net use u: /delete echo done
Thanks for this!
One typo: smbpassword should be smbpasswd (on centOS 5.6 at least).
Good catch Ben, thanks for letting me know. I went ahead and fixed that.
Regards,
Jon
Thanks for the help. everything worked all right!!
I’m glad that helped you!
You still need to fix the smbpassword -> smbpasswd when creating the user.
Easy to follow but unfortunately it didn’t work for me. Access denied. I’m running CentOS5.7 so that may be part of it. It could also be related to iptables as I know that is blocking but I think I got it disabled.
Thanks I will do that right now.
Hi,
I followed your steps above and linux share comes up in network and i have also made the batch file and opened it but now wat? shouldnt there be a maped drive in computer? im using windows 7
Thanks,
Izack
Yes you will see a mapped network drive, the drive letter will be u: if you used the above script. This is the line that creates the mapped drive.
net use u: \\192.168.1.100\share /user:windowsuser passwordfromabove
Hope this helps.