SERVER : File and Printer sharing with Windows computers (using Samba)
Friday, 12. January 2007, 16:14:25
After I've installed TorrentFlux on the server and downloaded the first files i've dicovered that using WinSCP to get the files from the server was just to slow, I've goft an avarage speed of 800-900Kb/s which is very low, especially since all my network devices are 100Mbps (which comes out to about 12 Mb/s).
While I was trying to figure out why was my file transfer so slow, I've discovered that SCP connections use SSH codification (or at least something similar) so that's why it's slow.
On the Ubuntu Forums I've read that I needed to install Samba and make some Samba shares in order to let the Win computers (and Linux too) gain access to shared resourcer (folders, printers, ...)
Step1 - Install SAMBA
Ok, so I should better show you how i've installed Samba and made the shares.
First thing, you have to install Samba, for that do this :
Now lets modify the config file, you should run this :
The "netbios name" in the smb.conf must be the same then the hostname of your server (Merlin in my case). Also make shore the logon path is correct to.
"workgroup = MYWORKGROUP" specifies the Windows domain that the Windows workstations use.
"logon drive = Y:" is the drive letter under which the SAMBA share will appear in the Windows Explorer.
With "logon script = scripts/logon.bat" you can specify a Windows batch script that is executed as soon as a Windows workstation logs in. If you want to use the script you must uncomment that line.
Now lets create the directories for domain logon and profiles :
Now you need to restart SAMBA so it takes the changes, for that execute
Now edit the /etc/nsswitch.conf file with
Add all computers of your workgroup in the /etc/hosts file on the server
Add the root user to the SAMBA password database. The root user (alias: Administrator) will be our domain administrator. This account is needed to add new computers to the SAMBA domain.
Create the file /etc/samba/smbusers and add the line by executing:
This will allow us to use the common windows username "Administrator" as alias for the Linux root user.
Now lets see if the shares are working, for that you can use this :
As you can see, my computer is also started, its name is WORKSTATION_1
On the Windows machines you should setup the default domain groups for windows, for that run this :
Now we have to configure the Samba server and create the shares. In my case I wanted to share the /mnt/c and /mnt/d folders and make them fully accessible to the users i've created (this is so because the 2 partitions where supposed to be a kind of backup or sharing drives). You might want to make some folders in the /home/ folder and share those, it's all up to you.
Step2 - add user access
First thing, lets create some users that will have access to the Samba shares, for that use :
You should see something like this :
By default Windows computers don't use passwords for accesing shares, so if you want to "follow" that philosophy you can just press "ENTER" and leave the password empty.
But as any "linux guru" would tell you, it's better to put a password.

If you want to add a user that can access the SAMBA shares but don't want to have shell (command prompt) access on the server (this is the best method if you don't want to give them any kind of access on the server except for the shares), you should use the following :
Step3 - create the shares
So, now we have the users, lets create the shares.
For that do the following
Now lets add the folder to SAMBA, so it knows what to share :
After you've added all the shares, you have to restart SAMBA so it reads its data again, for that run this command :
While I was trying to figure out why was my file transfer so slow, I've discovered that SCP connections use SSH codification (or at least something similar) so that's why it's slow.
On the Ubuntu Forums I've read that I needed to install Samba and make some Samba shares in order to let the Win computers (and Linux too) gain access to shared resourcer (folders, printers, ...)
Step1 - Install SAMBA
Ok, so I should better show you how i've installed Samba and made the shares.
First thing, you have to install Samba, for that do this :
sudo apt-get install samba samba-common samba-doc libcupsys2-gnutls10 libkrb53 winbind smbclientIf you get a message that samba is already installed, similar to the one below
samba is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.it simply means you've already got samba installed (maybe you've installed something that uses it and that's why you have it installed).
Now lets modify the config file, you should run this :
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf-original sudo editor /etc/samba/smb.confand you should modify the file to look something like the one bellow :
[global] workgroup = MYWORKGROUP netbios name = MERLIN server string = %h server (Samba, Ubuntu) passdb backend = tdbsam security = user username map = /etc/samba/smbusers name resolve order = wins bcast hosts domain logons = yes preferred master = yes wins support = yes # Set CUPS for printing printcap name = CUPS printing = CUPS # Default logon logon drive = Y: # logon script = scripts/logon.bat logon path = \\merlin\profile\%U # Useradd scripts add user script = /usr/sbin/useradd -m %u delete user script = /usr/sbin/userdel -r %u add group script = /usr/sbin/groupadd %g delete group script = /usr/sbin/groupdel %g add user to group script = /usr/sbin/usermod -G %g %u add machine script = /usr/sbin/useradd -s /bin/false/ -d /var/lib/nobody %u idmap uid = 15000-20000 idmap gid = 15000-20000 # sync smb passwords with linux passwords passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n . passwd chat debug = yes unix password sync = yes # set the loglevel log level = 3 [homes] comment = Home valid users = %S read only = no browsable = no [printers] comment = All Printers path = /var/spool/samba printable = yes guest ok = yes browsable = no [netlogon] comment = Network Logon Service path = /home/samba/netlogon admin users = Administrator valid users = %U read only = no [profile] comment = User profiles path = /home/samba/profiles valid users = %U create mode = 0600 directory mode = 0700 writable = yes browsable = no
The "netbios name" in the smb.conf must be the same then the hostname of your server (Merlin in my case). Also make shore the logon path is correct to.
"workgroup = MYWORKGROUP" specifies the Windows domain that the Windows workstations use.
"logon drive = Y:" is the drive letter under which the SAMBA share will appear in the Windows Explorer.
With "logon script = scripts/logon.bat" you can specify a Windows batch script that is executed as soon as a Windows workstation logs in. If you want to use the script you must uncomment that line.
Now lets create the directories for domain logon and profiles :
sudo mkdir /home/samba sudo mkdir /home/samba/netlogon sudo mkdir /home/samba/profiles sudo mkdir /var/spool/samba sudo chmod 777 /var/spool/samba/ sudo chown -R root:users /home/samba/ sudo chmod -R 771 /home/samba/
Now you need to restart SAMBA so it takes the changes, for that execute
samba /etc/init.d/samba restart
Now edit the /etc/nsswitch.conf file with
sudo editor /etc/nsswitch.confand modify the hosts: files dns to be hosts: files wins dns.
Add all computers of your workgroup in the /etc/hosts file on the server
192.168.1.1 merlin 192.168.1.10 workstation1 192.168.1.11 workstation2 192.168.1.12 workstation3 192.168.1.13 workstation4 192.168.1.14 workstation5 192.168.1.15 workstation6
Add the root user to the SAMBA password database. The root user (alias: Administrator) will be our domain administrator. This account is needed to add new computers to the SAMBA domain.
smbpasswd -a root
Create the file /etc/samba/smbusers and add the line by executing:
echo "root = Administrator" > /etc/samba/smbusers
This will allow us to use the common windows username "Administrator" as alias for the Linux root user.
Now lets see if the shares are working, for that you can use this :
smbclient -L localhost -U%you should get something similar to this :
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.22]
Sharename Type Comment
--------- ---- -------
netlogon Disk Network Logon Service
profile Disk User profiles
IPC$ IPC IPC Service (merlin server (Samba, Ubuntu))
ADMIN$ IPC IPC Service (merlin server (Samba, Ubuntu))
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.22]
Server Comment
--------- -------
WORKSTATION_1 emil's computer
MERLIN merlin server (Samba, Ubuntu)
Workgroup Master
--------- -------
MYWORKGROUP MERLIN
As you can see, my computer is also started, its name is WORKSTATION_1
On the Windows machines you should setup the default domain groups for windows, for that run this :
net groupmap modify ntgroup="Domain Admins" unixgroup=root net groupmap modify ntgroup="Domain Users" unixgroup=users net groupmap modify ntgroup="Domain Guests" unixgroup=nogroupyou could probably make a BAT (batch) file, put the above in it, and set that to be the script that's executed by SAMBA on login (the "logon script = scripts/logon.bat" from the smb.conf file)
Now we have to configure the Samba server and create the shares. In my case I wanted to share the /mnt/c and /mnt/d folders and make them fully accessible to the users i've created (this is so because the 2 partitions where supposed to be a kind of backup or sharing drives). You might want to make some folders in the /home/ folder and share those, it's all up to you.
Step2 - add user access
First thing, lets create some users that will have access to the Samba shares, for that use :
sudo useradd username_to_add -m -G users sudo smbpasswd -a username_to_addOf course the username_to_add will be the name of the user you want to add. The first line creates a new user on the server, adds him to the "users" group and creates his home folder too. The second one adds the user to the SAMBA password database and asks for the password.
You should see something like this :
New SMB password: Retype new SMB password: Added user username_to_add.
But as any "linux guru" would tell you, it's better to put a password.
sudo useradd username_to_add -m -G users -s /bin/true sudo smbpasswd -a username_to_addthe "-s /bin/true" part will force the user to use /bin/true as shell, but that program doesn't do anything, so he actually doesn't have any access to the shell.
Step3 - create the shares
So, now we have the users, lets create the shares.
For that do the following
sudo mkdir -p /path_to_the_folder/you_want/all_users_to_access/ sudo chown -R root:users /path_to_the_folder/you_want/all_users_to_access/ sudo chmod -R ug+rwx,o+rx-w /path_to_the_folder/you_want/all_users_to_access/The first command will create the folder /path_to_the_folder/you_want/all_users_to_access/ (of course you should enter what you want), the second command will make the folder accessible by any user who's part of the users group, and the third command will enshure the folder is writeable by all users (from the users group).
Now lets add the folder to SAMBA, so it knows what to share :
sudo editor /etc/samba/smb.confat the end of the file add this
[share_name] comment = All Users path = /path_to_the_folder/you_want/all_users_to_access/ valid users = @users force group = users create mask = 0660 directory mask = 0771 writable = yesof course the share_name will be the name as it appears when you browse the computer in Network Neighbourhood (just make shore you don't put any special characters or spaces), and the path will be the path you just created before.
After you've added all the shares, you have to restart SAMBA so it reads its data again, for that run this command :
sudo /etc/init.d/samba restart












