How to share Files and Printers Between Linux and MS Windows with Samba

13 Jan 2005

These instructions presume you have all the necessary software installed on your Linux box and have working network cards on each box. Linux software required is CUPS, SAMBA and Webmin. The printer is set up on the MS windows box.

You will probably have CUPS and SAMBA in your distribution, but you might not have Webmin. You can get it from the web. Download the file suitable for your distribution. Once it is installed, usually in /usr/libexec/webmin cd to that directory and run the script ./setup.sh You can press enter for most of the prompts. Use root and root's password for the administrator unless you have an admin user. Webmin uses Perl, so you must have this installed before you try to set Webmin up.

Make sure CUPS and SAMBA are installed and able to run on your Linux box. You can check if they are available and marked for run on boot through Yast – Run Level Editor on Suse or by using setup – system services in a terminal on RedHat. Other distributions you will find help in the documentation, but the start up scripts can be found in /etc/init.d and the run level services are often links to these scripts in /etc/rc.d/rc.RunLevelNumber or /etc/rc.RunLevelNumber. Whatever your system, just make sure they are marked for run at boot and start them running now.

You need A WORKING CONNECTION between the Linux box and the MS Windows box. This is basic stuff and not covered here except to say that in simple networking the IP addresses must be on the same network. (There is plenty of help on this especially in the Linux How Tos which are available on the Web. Look at Ethernet Networking to start.)
ie 192.168.0.0 or 192.168.1.0 etc., otherwise you won't get a connection.

For this example, I will use 192.168.0.1 for the MS Windows box and 192.168.0.2 for the Linux box.
The host names will be "swine" and "pearl" respectively.
The workgroup name will be SWINET.
Enable print and file sharing on "swine". You will have to perform the annoying MS reboot.
After plugging in the network cabling, check the connections at each box with the command
ping 192.168.0.2 in a DOS prompt window on MS, and ping -c 5 192.168.0.1 in shell terminal on Linux.

Presuming you got this far there are some important mandatory factors to get a SAMBA connection working. It's all in the passwords, plus a bit of setup in the correct order.

In MS Windows - Make a new user or use settings/control panel/passwords to create an MS windows user with a password.

EG user name = stomfi
password = 2mcStb
Note the user name is all lower case. The password is more or less the first letters of "Too many cooks Spoil the broth". A great way of thinking up hard to crack easy to remember passwords.
Make sure the Windows work group is set to SWINET do this in Right Click NetworkNeighborhood properties.

On Linux - Make an account on Linux for your windows login name making sure you give it the same password as your windows one.

EG stomfi & 2mcStb

On Linux - as root - use the samba password shell command which will prompt for the password:

smbpasswd -a stomfi
2mcStb
2mcStb

Now set up the SAMBA config file by copying the text delineated by ######### below into your editor and save the file into /etc/samba/smb.conf. Don't use a word processor because they can put hidden characters in your file which may prevent it running properly.

There are plenty of comments in this file which I have left just in case you need these features. Comment lines begin with a semi colon

#################################### 
; /etc/samba/smb.conf 
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
; This is the file that stomfi is using to connect a hard drive based 
; Linux system to a windows box with windows printer 
; See the Winprint instructions below for how to set up the printer using 
; Webmin and Cups 
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
[global] 
 printing = cups 
 printcap name = cups 
 guest account = nobody 
 invalid users = root 
; "security = user" is always a good idea. This will require a Unix account 
; in this server for every user accessing the server. 
 security = user 
; Change this for the workgroup your Samba server will be part of 
 workgroup = SWINET 
 server string = %h server (Samba %v) 
; If you want Samba to log though syslog only then set the following 
; parameter to 'yes'. Please note that logging through syslog in 
; Samba is still experimental. 
 syslog only = no 
; We want Samba to log a minimum amount of information to syslog. Everything 
; should go to /var/log/{smb,nmb} instead. If you want to log through 
; syslog you should set the following parameter to something higher. 
 syslog = 0; 
; This socket options really speed up Samba under Linux, according to my 
; own tests. 
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_SNDBUF=4096 SO_RCVBUF=4096 
; Passwords are encrypted by default. This way Windows 9x and NT 
; clients can connect to the Samba server with no problems. 
 encrypt passwords = true 
 passdb backend = smbpasswd guest 
; It's always a good idea to use a WINS server. If you want this server 
; to be the WINS server for your network change the following parameter 
; to "yes". Otherwise leave it as "no" and specify your WINS server 
; below (note: only one Samba server can be the WINS server). 
; Read BROWSING.txt for more details in your Samba docs. 
 wins support = yes 
; If this server is not the WINS server then specify who is it and uncomment 
; next line. 
; wins server = 192.168.0.10 
# If we receive WINS server info from DHCP, override the options above. 
; include = /etc/samba/dhcp.conf 
; Please read BROWSING.txt and set the next four parameters according 
; to your network setup. There is no valid default so they are commented 
; out except for the local master here. 
; os level = 0 
; domain master = no 
 local master = yes 
; preferred master = no 
; What naming service and in what order should we use to resolve host names 
; to IP addresses 
 name resolve order = lmhosts host wins bcast 
; This will prevent nmbd to search for NetBIOS names through DNS. 
 dns proxy = no 
; Name mangling options 
 preserve case = yes 
 short preserve case = yes 
; This boolean parameter controls whether Samba attempts to sync. the Unix 
; password with the SMB password when the encrypted SMB password in the 
; /etc/samba/smbpasswd file is changed. 
 unix password sync = true 
; For Unix password sync. to work on a  GNU/Linux system, the following 
; parameters must be set (thanks to Augustin Luton 
;  for sending the correct chat script for 
; the passwd program in Debian Potato). 
 passwd program = /usr/bin/passwd %u 
 passwd chat = *EntersnewsUNIXspassword:* %n
 *RetypesnewsUNIXspassword:* %n
 . 
; The default maximum log file size is 5 MBytes. That's too big so this 
; next parameter sets it to 1 MByte. Currently, Samba rotates log 
; files ( eg /var/log/{smb,nmb} ) when these files reach 1000 KBytes. 
; A better solution would be to have Samba rotate the log file upon 
; reception of a signal, but for now on, we have to live with this. 
 max log size = 1000 
 obey pam restrictions = yes 
; Some defaults for winbind (make sure you're not using the ranges 
; for something else.) 
; winbind uid = 10000-20000 
; winbind gid = 10000-20000 
; template shell = /bin/bash 
; ISOLATIN1 with euro sign 
unix charset = iso-8859-15 
display charset = iso-8859-15 
dos charset = 850 
[homes] 
 comment = Home Directories 
 browseable = no 
; By default, the home directories are exported read only. Change next 
; parameter to "no" if you want to be able to write to them.  Not a good idea.
 read only = yes 
; File creation mask is set to 0700 for security reasons. If you want to 
; create files with group=rw permissions, set next parameter to 0775. 
 create mask = 0700 
; Directory creation mask is set to 0700 for security reasons. If you want to 
; create dirs. with group=rw permissions, set next parameter to 0775. 
 directory mask = 0700 
[printers] 
 printer = MSwinPrinter1 ; what we will call our MS printer 
 browseable = no 
 printable = yes 
 writable = no 
 path = /var/spool/cups 
 comment = All Printers 
 public = no 
 create mode = 0700 
[public] 
 comment = User Public rw 
 browseable = yes 
 path = /usr/public 
 printable = no 
 public = yes 
 writable = yes 
 create mode = 0770 
; A sample share for sharing your CD-ROM with others. 
[cdrom] 
 comment = Samba server's CD-ROM 
 writable = no 
 locking = no 
 path = /mnt/cdrom 
 public = yes 
; 
; The next two parameters show how to auto-mount a CD-ROM when the 
; cdrom share is accessed. For this to work /etc/fstab must contain 
; an entry like this: 
; /dev/scd0 /cdrom iso9660 defaults,noauto,ro,user 0 0 
; The CD-ROM gets unmounted automatically after the connection to the 
; If you don't want to use auto-mounting/unmounting make sure the CD 
; is mounted on /cdrom 
; preexec = /bin/mount /cdrom 
; postexec = /bin/umount /cdrom 
################################################ 
Don't forget to save the file into /etc/samba/smb.conf
or where ever it goes on your distribution
Restart the samba server with Yast – run level editor – expert mode – restart or the redhat command service smb restart from a terminal
or by going to the directory /etc/init.d and running the SAMBA startup file from there
eg ./samba restart or similarly /etc/init.d/samba restart
you can always grep for samba in a terminal to find out your initialisation file name
grep samba /etc/init.d/*

Make sure you set the /usr/public directory for open access

mkdir /usr/public
chmod a+wrx /usr/public

Now logon to your Windows box using the name and password you created

EG stomfi 2mcStb

Double click Network Neighborhood
Double click the hostname of your Linux box
Use the same password

EG 2mcStb

If you followed these instructions so far you should now be able to access the Linux box. Try writing and saving a file to the public share on the Linux box

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
WinPrint
Now for the Printer which should already be going on the "swine" box.
On "swine" click on Settings/Printers and right click the printer you want to share. Click "sharing" and click "shared as" and give it a share name

EG "hp"
Open the NetworkNeighborhood Icon
Click on the local Machine Name EG swine
Click on the Printer and write down the share name exactly as MS records it
EG Swinehp

Now for Linux
Unlike older Linux network printing using LPD where the client connection sends a raw print file to be processed on the print server, Linux Cups to MS windows Samba printers uses the client printer driver. This had me stymied for about 10 minutes, until I hacked the solution.

(To Hack: To discover and apply a clever way of solving a problem. Something easily done on Linux, with all those lovely tools for dumb users like me, but not so easy on MS Windows. At least I can't figure out how to).

On Linux
Fire up Webmin in your favourite browser by the address:
http://hostname:10000

EG http://pearl:10000

Enter your webmin admin user name and password

EG root TAB wtJaHaNd ENTER

Click the Hardware Icon along the Webmin top bar
Click Printer Administration
Click Add new printer

In the Printer Configuration Panel
Enter a name

EG MSwinPrinter1
Enter description
EG MS Windows Laser Printer

Leave the rest as is unless you need this as the default printer.

In the Printer Description Panel Click Remote Windows server
Enter the MS windows Machine Name

EG Swine
Enter the Printer Name
EG hp
At the bottom Click on Create
Return to Printer Admin and you will see your newly created printer with none in the Driver column.

Click on the Servers Icon
Click on Samba Windows File Sharing
Click on Restart Samba Servers at the bottom of the page.

Now put the address for cups in the browser address

EG http://pearl:631
Click on Printers on header bar
Your new Printer will be shown with the Name MSwinPrinter1 and Local Raw Printer
The Device URL will be smb://Swine/hp
Click on Modify Printer under the above line
Click Continue - Modify Printer MSwinPrinter1
Click Continue - The Device - Windows Printer via SAMBA
Click Continue - Device URL
Click Continue - Model/Driver - This is what we will change
Our example Model is an HP and the Driver is for a LaserJet
Click HP
Click Continue - Model/Driver
Click HP LaserJet Series CUPS v1.1(en) - (For the CUPS version I am using) - Back to Admin
Click MSwinPrinter1 - Shows page for MSwinPrinter1
Click Print Test Page
Click On the Job ID and you should see positive messages like
Printer state accepting jobs
CUPS v 1.1 is ready to print

If the Test page is no good go back and Modify Printer again using a different Driver. If you have Gimp Print installed these may be the best drivers.

This is the end of these hopefully simple tips and tricks for getting a working SAMBA file sharing and Windows printing.

You will notice I didn't mention using LinNeighborhood.
You can try this in Linux but don't forget to set up the options to open up the mounted share with the file manager. This uses that other wonderful Linux tool "Midnight Commander". I should be doing a HowTo on using MC for end users soon, so look for this as it can save you a lot of running around looking for the right file utilities.



Informacja z serwisu http://www.djack.com.pl