lab #9: using linux with microsoft windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... ·...

12
CTEC1863/2019F Lab #9 Samba Page 1 of 12 Lab #9: 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 initials + 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 .

Upload: others

Post on 25-Jun-2020

7 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 1 of 12

Lab #9: 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 initials + 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.

Page 2: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 2 of 12

4. (continued)

For example, a user named Goran Jankovic would use GJANKOVIC or JANKOVICG as the netbios name.

We will all use the workgroup COMPENG.

NOTE: If either of these lines are missing in your smb.conf file, add them.

[global]...workgroup = COMPENG...netbios name = YOURSERVERNAME

...

[homes]...writable = yes

...[shared]comment = Shared Folderpath = /home/sharedpublic = yeswritable = yesbrowseable = 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

Page 3: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 3 of 12

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.

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 (get server status) systemctl status smb.service

Page 4: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 4 of 12

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 -Droot 18883 1 0 10:58 ? 00:00:00 /usr/local/samba/sbin/smbd -Droot 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

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 gjankovic gjankovic.compeng

Get your CentOS IP address using the ip a command.

After you save the hosts file, test by ping-ing both hostnames. (Ctrl-C to stop ping.)

Page 5: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 5 of 12

10. (a) Test your Samba server using a Linux client:

smbclient -N -L //YOURSERVERNAME

For example,

smbclient -N -L //GJANKOVIC 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 GJANKOVIC

(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

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).

continued...

Page 6: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 6 of 12

Step 10 continued...

(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 haveNew SMB password: run this command (once) on the server;Retype new SMB password: you don’t have to do this on the clientAdded user goranj.

$ smbclient //jankovic/goranj Run this command on the client or serverPassword: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 availablesmb: \> pwd Current directory is \\JANKOVIC\goranj\smb: \> qui

The Linux client is similar to FTP, so you can transfer files.

smb: \> help ? altname archive blocksize cancelcd chmod chown del dirdu exit get hardlink helphistory lcd link lowercase lsmask md mget mkdir moremput newer open print printmodeprompt put pwd q queuequit rd recurse reget renamereput rm rmdir setmode symlinktar tarmode translate vuid logon!

Page 7: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 7 of 12

11. Repeat procedures 9 and 10 on your Ubuntu VM. (You may need to install theSamba 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, butthe protocol is very inefficient! NFS is better.)

PART B: Test Samba using Microsoft Windows

12. From Windows, if you are logged in as Administrator, simply open aCommand 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 10 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.)

Use ping to contact your CentOS VM (using your IP address from Part A, Step 9.)

Page 8: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 8 of 12

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 forassistance, 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...

Page 9: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 9 of 12

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).

Page 10: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 10 of 12

14. From Windows Explorer window, enter the UNC name for your Samba serverusing 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.

Page 11: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 11 of 12

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...

Page 12: Lab #9: Using Linux with Microsoft Windowstechnology.niagarac.on.ca/courses/ctec1863/labs/... · CTEC1863/2019F Lab #9 Samba Page 11 of 12 15. Double-click on a share to view the

CTEC1863/2019F Lab #9 Samba Page 12 of 12

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 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.)