Bash Networking — Complete Guide to Remote Access & File Transfer
Bash provides powerful networking tools for connecting to remote servers, transferring files, diagnosing connectivity issues, and automating data transfers — essential skills for developers and system administrators.
What You’ll Learn
- Test network connectivity with
ping - Download files and interact with APIs using
curlandwget - Access remote servers securely with
ssh - Transfer files with
scpandrsync - Understand SSH key-based authentication
Why Bash Networking Matters
Modern applications rarely run on a single machine. You deploy to servers, pull updates from APIs, back up to remote storage, and diagnose why connections fail. Durga Antivirus Pro uses curl to download daily virus definition updates from its servers, rsync to mirror scan databases across data centers, and ssh to remotely manage deployed scanners. DodaZIP uses wget --mirror to archive client websites and rsync to sync compression jobs across a cluster.
Learning Path
flowchart LR
A[System Monitoring] --> B[Networking<br/>You are here]
B --> C[Compression]
curl and wget sections.Ping — Is the Remote Server Alive?
ping sends a small packet to a remote host and waits for a reply. Think of it as knocking on a door and waiting for someone to say “come in.”
# Basic ping — runs forever until you press Ctrl+C
ping google.com
# Send exactly 4 pings, then stop
ping -c 4 google.com
# PING google.com (142.250.80.14) 56(84) bytes of data.
# 64 bytes from 142.250.80.14: icmp_seq=1 ttl=118 time=12.3 ms
# 64 bytes from 142.250.80.14: icmp_seq=2 ttl=118 time=14.1 ms
# Check latency statistics
ping -c 10 google.com | tail -1
# rtt min/avg/max/mdev = 12.345/14.567/18.901/1.234 msWhat the output means: time=12.3 ms is round-trip time — milliseconds for the packet to reach Google and return. Under 50ms is excellent; over 200ms is noticeable lag.
curl — Swiss Army Knife for URL Transfers
curl is like a web browser for the command line. It downloads files, sends API requests, inspects headers, and handles authentication.
# Download with original filename
curl -O https://example.com/file.zip
# Save with a custom name
curl -o output.txt https://example.com/data
# Show response headers only (don't download body)
curl -I https://api.github.com
# HTTP/2 200
# content-type: application/json; charset=utf-8
# POST JSON data to an API
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice","email":"alice@example.com"}'
# Follow redirects automatically
curl -L https://short.url/redirect
# Authenticated request
curl -u username:password https://api.example.com/private
# Silent mode — no progress bar
curl -s https://example.comWhy -f matters: Add curl -f to make curl return a non-zero exit code on HTTP errors (404/500). Without it, failed requests silently write error pages to your output.
wget — Dedicated Download Tool
While curl is a general HTTP toolkit, wget specializes in downloading files with resume, mirrors, and recursion.
# Simple download
wget https://example.com/file.zip
# Download to a specific directory
wget -P /tmp/ https://example.com/file.zip
# Resume interrupted download
wget -c https://example.com/large-file.zip
# Mirror an entire website
wget --mirror --convert-links https://example.com
# Download from a list of URLs
wget -i urls.txt
# Limit bandwidth
wget --limit-rate=200k https://example.com/large-file.zipcurl vs wget: Use curl for API work (POST, headers, JSON). Use wget for downloading (resume, mirrors, recursive).
SSH — Secure Remote Shell
SSH (Secure Shell) opens a secure encrypted terminal on a remote computer. Think of it as a secure tunnel between your machine and the server.
# Connect to a remote server
ssh user@server.com
# Non-standard port
ssh -p 2222 user@server.com
# Run a single command (no interactive shell)
ssh user@server.com 'ls -la /var/log'SSH Key-Based Authentication
Typing passwords every time is slow and insecure. SSH keys replace passwords with a cryptographic handshake.
# Step 1: Generate a key pair
ssh-keygen -t ed25519
# Creates: ~/.ssh/id_ed25519 (private — NEVER SHARE)
# ~/.ssh/id_ed25519.pub (public — goes on servers)
# Step 2: Copy the public key to your server
ssh-copy-id user@server.com
# Now SSH without a password
ssh user@server.comSSH Config File
Create ~/.ssh/config with shortcuts for frequent servers:
Host myserver
HostName 192.168.1.100
User admin
Port 22
IdentityFile ~/.ssh/server_keyNow ssh myserver uses all those settings automatically.
SCP — Secure Copy
scp copies files over SSH encryption. Like secure cp for remote machines.
# Local to remote
scp file.txt user@server.com:/home/user/
# Remote to local
scp user@server.com:/home/user/file.txt .
# Recursive directory copy
scp -r project/ user@server.com:/home/user/
# Custom port
scp -P 2222 file.txt user@server.com:~RSYNC — Remote Sync
rsync is like scp but smarter — it transfers only the differences between files. For repeated backups, it’s dramatically faster.
# Local to remote (archive + verbose + compress)
rsync -avz project/ user@server.com:/backup/project/
# Remote to local
rsync -avz user@server.com:/backup/project/ ./restore/
# Dry run — preview without copying
rsync -avz --dry-run project/ user@server.com:/backup/
# Delete files on destination not on source
rsync -avz --delete project/ user@server.com:/backup/
# Exclude patterns
rsync -avz --exclude='*.log' --exclude='node_modules/' project/ user@server.com:/backup/
# Custom SSH port
rsync -avz -e 'ssh -p 2222' project/ user@server.com:/backup/rsync Flags
| Flag | Meaning |
|---|---|
-a | Archive — preserve permissions, timestamps, owner |
-v | Verbose — show copied files |
-z | Compress during transfer |
--dry-run | Preview only |
--delete | Remove destination files not on source |
--progress | Show per-file progress |
Common Mistakes
1. Using curl without error checking
curl -s https://api.example.com/data > output.json
# If the request fails, output.json is an HTML error pageAdd -f and check the exit code.
2. Forgetting SSH keys
Typing passwords is slow and prevents automation. Generate a key with ssh-keygen and copy it with ssh-copy-id once.
3. Not verifying SSH host keys
The first connection shows the host key fingerprint. Verify it with the server admin to prevent man-in-the-middle attacks.
4. Using scp for repeated syncs
scp copies everything every time. For regular backups, use rsync — it transfers only changes.
5. Killing a download instead of resuming
Use wget -c to resume interrupted downloads instead of starting from zero.
6. Leaving idle SSH sessions open
Idle sessions time out or become security risks. Use tmux for long-running tasks, or add ServerAliveInterval 60 to ~/.ssh/config.
Practice Questions
What is the difference between
curlandwget?curlis better for API testing (POST, headers, many protocols).wgetis better for file downloads (recursive, resume, mirrors).How does SSH key authentication work? A public/private key pair replaces password login. The public key goes on the server; the private key stays on your machine.
Why is
rsyncfaster thanscpfor repeated transfers?rsynctransfers only the differences.scpcopies the entire file every time.What does
ping -c 4do? Sends exactly 4 ICMP requests and stops, instead of running indefinitely.How do you resume an interrupted download?
wget -c https://example.com/large-file.zipcontinues from where it stopped.
Challenge: Write a script that uses curl to check a website’s HTTP status. If it returns 200, print “Site OK”. If 5xx, print “Site down!” and exit with code 1. Test with a working URL and a broken one.
FAQ
Try It Yourself
Open your terminal and run these safe commands:
# Test connectivity
ping -c 4 8.8.8.8
# Fetch your public IP
curl -s https://api.ipify.org
# Download a test page
wget -O /tmp/test.html https://example.com
# Inspect HTTP headers
curl -I https://example.com
# Check HTTP status code
curl -s -o /dev/null -w "%{http_code}" https://google.comAll these work without any setup. For SSH practice, try connecting to a cloud VM or Raspberry Pi.
What’s Next
| Tutorial | What You’ll Learn |
|---|---|
| File Compression | Compress transferred files with gzip, tar, zip |
| Linux Server Administration | Manage remote servers, firewalls, services |
| curl Advanced Usage | API testing, authentication, scripting with curl |
What’s Next
Congratulations on completing this Bash Networking tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro