CTEC1863/2017F Lab #10 Samba Page 1 of 11 Lab #10: Using Linux with Microsoft Windows In this lab, we turn Linux into a Microsoft Windows network server using Samba, "the free SMB and CIFS client and server for UNIX and other operating systems." Source: samba-3.0.11/readme For more information about Samba, read the online documentation: http://www.samba.org/ (official Samba web site) PART A: Installing the Samba Server on Linux 1. Start your CentOS VM. 2. Become root. Make sure that Samba is installed: yum install samba samba-client samba-common 3. Enable Samba in the firewall: firewall-cmd --permanent --zone=public --add-service=samba firewall-cmd --reload 4. The CentOS Samba configuration file is /etc/samba/smb.conf. Make a backup first: cd /etc/samba/ cp smb.conf smb.conf.old Using gedit (or another text editor, as root), search for the settings in the existing smb.conf file. Use your surname/last name/family name in all capital letters as the "netbios name". This will become the name of the Linux Samba server on a Microsoft Windows network. NOTE: Remove any leading semicolons (;) in configuration lines -- those are Samba comments.
CTEC1863/2017F Lab #10 Samba Page 2 of 11 4. (continued) For example, a user named Goran Jankovic would use JANKOVIC as the netbios name. We will all use the workgroup COMPENG. [global]... workgroup = COMPENG... netbios name = YOURSERVERNAME... [homes]... writable = yes... [shared] comment = Shared Folder path = /home/shared public = yes writable = yes browseable = yes After making the necessary edits, save the file. 5. Create your shared folder. It is best to give it "shared" permissions (like /tmp). For example, mkdir -p /home/shared chmod 1777 /home/shared 6. SELinux ("Security Enhanced Linux") is a service that runs to allow fine-grained control of which files can be accessed, etc. You must allow Samba in SELinux: chcon -t samba_share_t /home/shared setsebool -P samba_enable_home_dirs 1 Also copy at least one file into the folder, so that you can properly test it.
CTEC1863/2017F Lab #10 Samba Page 3 of 11 7. After making the necessary edits, save the file. Prepare to run Samba: testparm (validate the configuration) The testparm program should not produce any error messages. If so, you probably have one or more errors in your smb.conf file. 8. Continue to prepare to run Samba: smbpasswd -a yourusername (add yourself as a Samba user) systemctl enable nmb.service smb.service (start the servers) systemctl restart nmb.service smb.service ps -ef grep mbd (verify servers are running) OR systemctl status nmb.service systemctl status smb.service (get server status) Note: If you make a change to your smb.conf file, you must notify the Samba server processes by sending a "Hangup" signal with the kill command. For example, # ps -ef grep mbd root 18881 1 0 10:58? 00:00:00 /usr/local/samba/sbin/nmbd -D root 18883 1 0 10:58? 00:00:00 /usr/local/samba/sbin/smbd -D root 18972 1087 0 11:10 pts/1 00:00:00 grep mbd # kill -HUP 18881 18883 You can also just restart the two services: systemctl restart nmb.service smb.service
CTEC1863/2017F Lab #10 Samba Page 4 of 11 9. Add an entry to your /etc/hosts file for your Samba server name. (Make a backup first and then use a text editor.) For example: 192.168.3.191 jankovic jankovic.compeng Get your CentOS static IP address using the ip a command. After you save the hosts file, test by ping-ing both hostnames. (Ctrl-C to stop ping.) 10. (a) Test your Samba server using a Linux client: smbclient -N -L //YOURSERVERNAME For example, smbclient -N -L //JANKOVIC Anonymous login successful Domain=[COMPENG] OS=[Unix] Server=[Samba 4.1.0] Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (Samba 4.1.0) homes Disk shared Disk Anonymous login successful Domain=[COMPENG] OS=[Unix] Server=[Samba 4.1.0] Server Comment --------- ------- JANKOVIC Samba 4.1.0 Workgroup Master --------- ------- COMPENG JANKOVIC (b) You can also use your IP address. For example: smbclient -N -L //192.168.3.191 Anonymous login successful Domain=[COMPENG] OS=[Unix] Server=[Samba 4.1.0]... (c) Test Samba access to your home directory: smbclient -U yourusername //yourservername/yourusername...continued...
CTEC1863/2017F Lab #10 Samba Page 5 of 11 10....continued... After connecting, if you run a dir command, you should see the files in your home directory. (d) In another window, as your non-root user, run the Samba client: smbclient //yourservername/yourusername You should see the same result as in step (c). (e) Test Samba access to your shared directory: smbclient //yourservername/shared For example, if the user Goran has a Linux username "goranj", then goranj would be his username for Samba and for Microsoft Networking. # smbpasswd -a goranj The system administrator would have New SMB password: run this command (once) on the server; Retype new SMB password: you don t have to do this on the client Added user goranj. $ smbclient //jankovic/goranj Run this command on the client or server Password: Domain=[COMPENG] OS=[Unix] Server=[Samba 3.0.11] smb: \> ls. D 0 Tue Jul 20 11:21:29 2015.. D 0 Tue Jul 20 11:15:45 2015.bash_profile H 191 Tue Feb 10 14:24:53 2015.bashrc H 124 Tue Feb 10 14:24:53 2015 lab10 D 0 Wed Jul 21 09:04:13 2015 samba-3.0.12.tar.gz 5453486 Wed Jul 21 10:20:49 2015 60892 blocks of size 32768. 495 blocks available smb: \> pwd Current directory is \\JANKOVIC\goranj\ smb: \> qui...continued...
CTEC1863/2017F Lab #10 Samba Page 6 of 11 10...continued... The Linux client is similar to FTP, so you can transfer files. smb: \> help? altname archive blocksize cancel cd chmod chown del dir du exit get hardlink help history lcd link lowercase ls mask md mget mkdir more mput newer open print printmode prompt put pwd q queue quit rd recurse reget rename reput rm rmdir setmode symlink tar tarmode translate vuid logon! 11. Repeat procedures 9 and 10 on your Ubuntu VM. (You may need to install the Samba client first.) This uses Ubuntu as the client, connecting to your CentOS server over the network. (Samba can be used to transfer files between Linux and Linux, but the protocol is very inefficient! NFS [Lab 9] is better.) PART B: Test Samba using Microsoft Windows 12. From Windows, if you are logged in as Administrator, simply open a Command Prompt. If you are logged in as l17student, go to the Start menu, All Programs, Accessories. Right-click on Command Prompt and select Run as Adminstrator (and agree to the UAC prompt.) OR Boot another PC into the L17 Open Windows 7 partition and log on as Administrator. Verify that you are on the CIT network (as indicated by a 192.168.2 or 192.168.3 IP address.)...continued...
CTEC1863/2017F Lab #10 Samba Page 7 of 11 12....continued... Use ping to contact your CentOS VM (using your IP address from Part A, Step 9.) Note: for these examples, assume that user Srdjan Matovina has a Samba server called MATOVINA on IP address 172.31.40.2 and a Samba user name srdjan. 13. (a) Open the c:\windows\system32\drivers\etc\lmhosts.sam file using Notepad. The easiest way to do this is to cd into the directory first using the Tab key for assistance, and then run notepad lmhosts.sam from the Command Prompt (so that it is running as Administrator.) Add an entry for your Samba server (since we don't have a WINS server handy.) For example:...continued...
CTEC1863/2017F Lab #10 Samba Page 8 of 11 13...continued... Save the file as c:\windows\system32\drivers\etc\lmhosts -- NO EXTENSION! Verify using the Command Prompt that the file has no extension and rename it if necessary. (b) Do the same with the c:\windows\system32\drivers\etc\hosts file (since we don't have control of the DNS server either.) Test your hosts file entry by ping-ing the hostname(s).
CTEC1863/2017F Lab #10 Samba Page 9 of 11 14. From Windows Explorer window, enter the UNC name for your Samba server using your Samba username and password. For our example server, its UNC name is \\MATOVINA You can also enter the IP address instead in the UNC format, e.g., \\172.31.40.2 Windows may also show your Samba server in the left pane of the Explorer window, under Network.
CTEC1863/2017F Lab #10 Samba Page 10 of 11 15. Double-click on a share to view the contents of the share. Alternatively, you can right-click on a share and map a network drive to it. The UNC name for your home directory is in the form: \\ yourservername \yourusername For our example server, Srdjan's home directory, in UNC form, is: \\MATOVINA\srdjan...continued...
CTEC1863/2017F Lab #10 Samba Page 11 of 11 15....continued... OR you can use NET USE commands to manage the drive. 16. Try to read and write files to and from the share using Windows programs. When You Are Done 1. Take a screen shot of your Windows 7 PC connected to your Samba server, using the Snipping Tool. 2. Email the screen shot and your Linux smb.conf file [hint: you can copy it to Windows via one of your Samba shares first] to your professor. (Or post on BB.)