Clients, servers and shared resources¶
Exercise clients-servers-and-shared-resources-annex.pdf · PDF
This morning you sent a photo. Where is it now? Not only in your phone. It sits on a computer you have never seen, and that computer handed it to your friend the moment their phone asked for it.
That computer is a server. Until now you configured one machine (Unit 5) and connected machines together (Unit 3). From today, one machine works for the others. In this unit you build a real one, step by step, for a real-looking company.
What you will learn
- Tell a local resource from a network resource, with examples of each
- Explain client and server as roles, and a service as a program that waits on a port
- List the services listening on a machine with
ss -tln, and say which ones the network can reach - Give a server a fixed address and a name the clients can resolve
- Create the company's groups and users on the server, and catch a group that gives far too much power
- Why "server" is not a kind of box
The restaurant: clients, servers, services¶
All year the computer was a kitchen. Today the kitchen opens to the public. Picture it: a kitchen with three small serving windows (hatches), each with a number painted above it, and customers waiting outside.
| Word | In the restaurant | In computing |
|---|---|---|
| Server | The kitchen that cooks for others | A machine (really: a program) that offers something to other machines |
| Client | The customer who orders | The program that asks |
| Service | One hatch with a cook always waiting behind it | A program that waits for requests: a daemon, as you saw in Unit 5 |
| Port | The number above the hatch | 22 = SSH, 445 = file sharing, 631 = printing |
| Protocol | How you must order ("a number 4, please") | The rules of the conversation: SSH, SMB, IPP... |
flowchart LR
subgraph CLIENTS ["Clients (the customers)"]
direction TB
C1["<b>deb-lab</b><br>asks for a shell"]
C2["<b>win11</b><br>asks for a file"]
end
subgraph SRV ["ubu-srv (the kitchen)"]
direction TB
P22["<b>port 22</b><br>SSH hatch"]
P445["<b>port 445</b><br>file-sharing hatch"]
P631["<b>port 631</b><br>printing hatch"]
end
C1 -->|"SSH protocol"| P22
C2 -->|"SMB protocol"| P445
A server is a role, not a kind of box: a program that offers a service to other machines.
Your laptop is a client when it opens a web page and a server when it shares a folder. The same machine can do both in the same second.
Careful: a server is not a big expensive computer
A Raspberry Pi can be a server. Your own ubu-srv is a virtual machine with 2 GB of RAM. What makes it a server is that a service is listening and other machines use it.
Local and network resources¶
A resource is anything useful a computer can offer: files, a printer, a program, a shell, Internet access.
- A local resource is inside or plugged into your own machine.
- A network resource is given to you by another machine, through the network.
| Resource | Local | Network |
|---|---|---|
| Files | Your home folder on your own disk | A shared folder on a file server; Google Drive |
| Printer | A USB printer on your desk | The printer in the corridor, used by 40 PCs |
| Programs | The editor installed on your PC | A web application: Classroom, a game server |
| Shell | The terminal you open | A terminal on another machine, through SSH |
What do you lose when the network cable is cut? Everything in the right-hand column. And what do you gain with it? One copy for everybody, one backup, one place to give permissions.
Google Drive looks local
The Google Drive folder on your PC looks like a local folder. That is exactly what a good network resource does: it hides the network. Cut the Wi-Fi and try to open a file that was never downloaded.
Find the services on your machine¶
Each service waits on a port. The command ss (socket statistics) lists them:
-t= TCP,-l= only listening sockets,-n= show numbers instead of names,-p= which program.
A typical line on ubu-srv:
Read it as: something waits on port 22, on every address of this machine. The part before the colon tells you who can reach it:
| Local address | Means | Reachable from the network? |
|---|---|---|
0.0.0.0, * or [::] |
Every address of the machine (IPv4 / IPv6) | Yes |
127.0.0.1, 127.0.0.53 or [::1] |
Only localhost, the machine itself | No |
What you will probably find:
| Machine | Port | Program | Network? |
|---|---|---|---|
ubu-srv |
22 | sshd (shown as systemd when it starts on demand) |
Yes |
ubu-srv |
53 | systemd-resolve, on 127.0.0.53 |
No: localhost only |
deb-lab |
631 | cupsd, on 127.0.0.1 |
No: localhost only |
Two common slips
ss without -l shows connections, not listeners. And if ubu-srv shows nothing on port 22, SSH was not ticked in the installer: install it with sudo apt install openssh-server (you need it for the next page anyway).
The unit project: the Tramuntana office server¶
Tramuntana Apps is a 12-person app studio in Palma. Today every file lives on somebody's laptop, the designers send logos by chat, and nobody knows which copy is the latest one. When Pau's laptop died, a week of work died with it.
The company buys one small server. You are the person they hire to set it up. Your server is the VM ubu-srv (Ubuntu Server 26.04 LTS, no desktop); the clients are deb-lab (Debian 13) and win11. By 20 May it must offer:
| What the server must offer | Built in |
|---|---|
| A fixed address and a name the clients resolve | This page |
| The company's groups and users, nobody with more power than the job needs | This page |
| Remote administration by SSH, with keys only | SSH remote access |
| A common folder that opens from Windows and Linux | Samba file server |
| One folder per department | Share permissions and groups |
| A projects folder exported by NFS, mounted at boot | NFS |
| A shared print queue | Print server |
| An application and its database in containers | Containers to Composing services |
| A domain, security policies and basic hardening | The rest of the unit |
Three rules for the whole project:
- Snapshot first. Take a snapshot of
ubu-srvbefore each session. If you break it, you go back ten minutes, not five weeks. - Check from a client. A service works when a client can use it, not when the install command ends.
- Least privilege. Everybody gets what the job needs and nothing more. Permissions go to groups, not to people.
At the end of every session you add an entry to ~/server-log.md: the date, what you changed (file or command), how you checked it, and one problem you had with its solution. In Unit 7 this log becomes the server's documentation.
Give the server an address and a name¶
A client finds a server by its address. If DHCP gives ubu-srv a different address next week, every client is lost. So servers get a static IP address, one that never changes. Ours is 192.168.122.10, inside the virtual network default of virt-manager (192.168.122.0/24, gateway and DNS 192.168.122.1).
First find the interface name:
Then create /etc/netplan/60-static.yaml with sudo nano. Netplan is Ubuntu's network configuration tool, and its files are written in YAML, a format where indentation is the structure:
network:
version: 2
ethernets:
enp1s0:
dhcp4: false
addresses: [192.168.122.10/24]
routes:
- to: default
via: 192.168.122.1
nameservers:
addresses: [192.168.122.1]
sudo chmod 600 /etc/netplan/60-static.yaml
sudo netplan try # press Enter when it asks, if you see no error
ip -br a
ping -c 3 192.168.122.1
netplan try applies the change and rolls it back by itself after 120 seconds if nobody presses Enter. That is the safety net when you change the network of a machine you may not be able to touch.
Where people get stuck
- YAML is strict: spaces, never tabs, two spaces per level. One wrong indent gives
Invalid YAML. - The interface is not always
enp1s0: copy the name fromip -br a. - Do not edit
50-cloud-init.yaml: the system may rewrite it. Your60-static.yamlis read later, so it wins.
Now the client needs a name for the server. On deb-lab:
/etc/hosts is the machine's local phone book: it is read before DNS is asked. If ping ubu-srv fails, the line is missing or has a typo.
Who works here: groups and users¶
Marta sits at her laptop and wants a file on the server. How does the server know she is Marta? She needs an account on the server. Accounts on deb-lab do not exist on ubu-srv: each machine has its own /etc/passwd.
| Group (department) | Users | What they will get |
|---|---|---|
dev |
marta, pau (intern) |
The code and project folder |
design |
joan |
Logos, mock-ups |
admin |
aina |
Invoices, contracts: nobody else reads them |
On ubu-srv:
for g in dev design admin; do sudo groupadd $g; done
sudo useradd -m -s /bin/bash -G dev marta
sudo useradd -m -s /bin/bash -G dev pau
sudo useradd -m -s /bin/bash -G design joan
sudo useradd -m -s /bin/bash -G admin aina
for u in marta pau joan aina; do sudo passwd $u; done
Check the result with id marta and getent group dev (it should list marta,pau). Then ask the most important question: what can each user do?
Aina, from the administration department, can run every command as root. Nobody gave her that. Look for the reason:
Ubuntu ships the line %admin ALL=(ALL) ALL in /etc/sudoers: an old rule from the years when Ubuntu's administrators were in a group called admin. We created a group with the same name for a different reason, and it inherited the power. Fix it with sudo visudo: put # in front of that line, save (Ctrl+O, Enter, Ctrl+X) and check again:
No error message does not mean it is right
Nobody attacked this server. groupadd admin gave no error and still opened root to a whole department. Administration (invoices) and administrator (root) are two different words that look the same. Debian has no such line; Ubuntu does. Always check what a new user can do with sudo -l -U user.
Finally, create the folders the next sessions will share, and start your log:
Key takeaways¶
- A server is a role: a program that offers a service to clients. The same machine can be both.
- A local resource is on your machine; a network resource is given by another machine, and gives one copy, one backup and one place for permissions.
- Each service waits on a port.
ss -tlnlists them;0.0.0.0means the network can reach it,127.0.0.1means localhost only. - A server needs a static IP address (Netplan on Ubuntu,
netplan tryas the safety net) and a name the clients resolve (/etc/hostsbefore DNS). - Each machine has its own accounts. Give permissions to groups, and always check what a user can do: on Ubuntu a group called
admingets sudo.
Quick check¶
1. What makes a computer a server?
- A program on it offers a service to other machines
- It is more powerful than a normal PC
- It has no screen and no keyboard
- It runs Linux instead of Windows
Server is a role, not a kind of hardware. A Raspberry Pi or a 2 GB VM is a server as soon as a service listens on a port and other machines use it.
2. ss -tln shows a service on 127.0.0.1:631. Who can connect to it?
- Only the machine itself
- Any machine on the LAN
- Any machine on the Internet
- Nobody, because the port is closed
127.0.0.1 is localhost: the service listens only for the machine itself. To be reachable from the network it would have to listen on 0.0.0.0, * or [::].
3. Why does a server get a fixed address instead of one from DHCP?
- So that clients always find it in the same place
- Because fixed addresses make the network faster
- Because DHCP does not work on server machines
- Because a fixed address saves addresses in the network
Clients find a server by its address. If DHCP gave it a new one, every client would lose it. A static IP address never changes.
4. Why could aina, from the administration department, run every command with sudo?
- Her group's name matched an old rule in Ubuntu's sudoers file
- The
useraddcommand makes every new user an administrator - She was the first user created on the server
- Her password was too short to be accepted
Ubuntu's /etc/sudoers ships %admin ALL=(ALL) ALL. The department group admin inherited that power by its name. Comment the line out with visudo and check with sudo -l -U aina.
5. Which of these is a network resource?
- The printer in the corridor used by the whole floor
- A USB stick plugged into your laptop
- The terminal you open on your own PC
- The home folder on your own disk
A network resource is given to you by another machine through the network. The corridor printer is shared by many PCs; the other three are local resources on or in your machine.
6. On deb-lab, ping ubu-srv works even though no DNS server knows that name. Where did the name come from?
- From a line in the file /etc/hosts
- From the Netplan file on the server
- From the output of the ss command
- From the server's /etc/passwd file
/etc/hosts is the machine's local phone book, read before DNS. The line 192.168.122.10 ubu-srv is enough for that one client.
7. You open a web page on your laptop while it shares a folder with your brother's PC. Select the two that are true.
- Your laptop is a client of the web server
- Your laptop is a server for your brother's PC
- A machine must choose to be a client or a server
- Your laptop is only a server, since it shares a folder
Client and server are roles, and one machine can play both at the same time. It asks the web server (client) and answers your brother's PC (server).
Today you sat in front of the server's console. A real server lives in a locked room: next, you learn to manage it without ever touching it, with SSH remote access.