Networking and SSH: curl, ping and Remote Servers
Check network connections with ip and ping, download with curl and wget, see which ports are listening, and log in to remote servers and copy files with SSH and scp.
On this page 12 sections
Introduction
Most of the time you spend on Linux at work will be on servers you reach over the network. This lesson covers the commands for checking connections, talking to websites and APIs, and — most importantly — logging in to remote machines securely with SSH.
- How to see your IP address and test connections.
- How to make web requests and download files with curl and wget.
- How to check which network ports a server is listening on.
- How to log in with SSH keys, run remote commands and copy files.
Your Network: ip
ip address (short: ip a) lists network interfaces and their addresses; -brief gives one line each:
ip -brief addressClick Run to see what this code prints.
lo is the loopback interface — the computer talking to itself, always at 127.0.0.1, also called localhost. eth0 is the network card, here with the private address 172.17.0.2. Your machine will show its own names (such as wlan0 for Wi-Fi) and addresses.
Is It Reachable? ping
ping sends small test messages and measures how long replies take. -c 3 stops after three (without it, ping runs until you press Ctrl+C):
ping -c 3 one.one.one.oneClick Run to see what this code prints.
Replies and 0% packet loss mean the network works and the name was resolved to an IP address (1.1.1.1). getent hosts shows that name lookup on its own:
getent hosts example.comClick Run to see what this code prints.
Talking to the Web: curl and wget
curl makes web requests from the terminal and is the everyday tool for testing websites and APIs. -I fetches only the response headers, and -s hides the progress bar:
curl -sI https://example.com | head -n 5Click Run to see what this code prints.
200 means success. Without -I, curl prints the page itself:
curl -s https://example.com | grep -o "<title>.*</title>"Click Run to see what this code prints.
wget is built for downloading files; -O names the output file and -q keeps it quiet:
wget -q https://example.com -O example.htmlls -l example.htmlClick Run to see what this code prints.
| curl command | Use |
|---|---|
| curl https://api.example.com/users | GET request; print the response |
| curl -I https://example.com | Headers only (status code, server, caching) |
| curl -o file.zip https://…/file.zip | Save the response to a file |
| curl -L https://… | Follow redirects |
| curl -X POST -H "Content-Type: application/json" -d '{"name":"Priya"}' https://… | Send JSON to an API |
Which Ports Are Open? ss
Network services listen on numbered ports: 22 for SSH, 80 for HTTP, 443 for HTTPS. Priya starts Python’s built-in web server on port 8000 in the background and requests a page from it:
cd sitenohup python3 -m http.server 8000 > /dev/null 2>&1 &curl -s http://localhost:8000Click Run to see what this code prints.
ss -tln lists TCP ports in the LISTEN state, with numbers instead of names — the first command to run when a service “is not reachable”:
ss -tlnClick Run to see what this code prints.
0.0.0.0:8000 means the server accepts connections on port 8000 from any network address. Add -p (with sudo) to see which program owns each port.
Remote Servers with SSH
SSH (Secure Shell) gives you an encrypted terminal on another computer: everything you type runs there. The usual form is ssh user@server. Logging in with a key pair instead of a password is both safer and more convenient. First, create a key — press Enter to accept the default location and choose a passphrase (the Git course’s SSH lesson shows the full output):
ssh-keygen -t ed25519 -C "priya@laptop"That creates two files in ~/.ssh: the private key, which never leaves your computer, and the public key ending in .pub:
ls ~/.sshClick Run to see what this code prints.
Then put the public key on the server. On a real server, ssh-copy-id deploy@server does this for you: it appends id_ed25519.pub to the server account’s ~/.ssh/authorized_keys file. In this demonstration the “server” is an SSH server running on the same machine with its own user account, deploy, so the address is localhost — but every command works identically against a server on the other side of the world.
ssh deploy@localhost "whoami; hostname; pwd"Click Run to see what this code prints.
The first time you connect, SSH records the server’s identity (its host key) in ~/.ssh/known_hosts; normally it first asks you to confirm the fingerprint. From then on, it warns you loudly if the identity ever changes, which protects you from impostor servers. Putting a command after the address runs just that command remotely; without one, you get an interactive shell until you type exit.
ssh deploy@localhost "ls -la ~/.ssh"Click Run to see what this code prints.
Note the strict permissions on the server side: SSH refuses to use an authorized_keys file or .ssh folder that other users could change.
Put the steps of setting up key-based SSH login to a new server in order.
- Generate a key pair with ssh-keygen -t ed25519
- Copy the public key to the server with ssh-copy-id user@server
- Optionally disable password logins on the server
- Check that no password was needed
- Log in with ssh user@server and confirm the host fingerprint
Copying Files: scp
scp copies files over SSH, with the same user@server:path syntax. A colon marks the remote side:
scp report.txt deploy@localhost:~/ssh deploy@localhost "cat ~/report.txt"Click Run to see what this code prints.
Swap the arguments to download (scp deploy@server:~/report.txt .) and add -r for folders. For large or repeated transfers, rsync -av is better: it copies only what has changed.
Shortcuts: ~/.ssh/config
Instead of typing full addresses, describe each server once in ~/.ssh/config:
Host myserver HostName localhost User deploy IdentityFile ~/.ssh/id_ed25519ssh myserver 'echo connected as $USER'Click Run to see what this code prints.
For a real server, HostName would be its IP address or domain name. The same short name works with scp, rsync and Git.
You want to download /var/log/nginx/error.log from the server web1 (user deploy) into your current folder. Which command is right?
Common Mistakes
- Sharing or copying your private key (id_ed25519) instead of the .pub file.
- Accepting a host-key warning without checking why the server’s identity changed.
- Leaving password logins enabled on internet-facing servers.
- Forgetting the colon in scp, which copies to a local file literally named after the server.
Frequently Asked Questions
The machine is reachable, but nothing is listening on that port — the service is stopped, or listens on a different port. Check it on the server with ss -tln.
Nothing answered at all: the address may be wrong, the machine may be down, or a firewall is blocking the port.
Yes. Windows 10 and 11 include an OpenSSH client, so ssh works in PowerShell and Windows Terminal, and in WSL as usual.
Key Takeaways
- ip a shows addresses; ping tests reachability; getent hosts shows name lookups.
- curl makes web and API requests; wget downloads files.
- ss -tln lists listening ports — the first check when a service is unreachable.
- ssh user@server opens a remote shell; use key pairs and verify host fingerprints.
- scp and rsync copy files over SSH; ~/.ssh/config stores short server names.
Summary
You can now diagnose connections and work on remote servers securely. The final lesson pulls everything together into everyday system administration: disk space, memory, services, logs, scheduled jobs and users.