📖 Scenario: You work as a system administrator. You need to securely copy files from your local machine to a remote server. You will use scp and rsync commands to transfer files efficiently.
🎯 Goal: Learn how to use scp and rsync commands to transfer files from your local machine to a remote server securely and efficiently.
📋 What You'll Learn
Create a sample file to transfer
Set a variable with the remote server address
Use scp to copy the file to the remote server
Use rsync to copy the file to the remote server with progress shown
Display the final confirmation message
💡 Why This Matters
🌍 Real World
System administrators and developers often need to transfer files securely between computers. Using scp and rsync helps automate and speed up this process.
💼 Career
Knowing how to use scp and rsync is essential for roles involving server management, backups, deployment, and automation.
Progress0 / 4 steps
1
Create a sample file to transfer
Create a file called sample.txt with the exact content: Hello, this is a test file for transfer.
Linux CLI
Hint
Use the echo command with redirection > to create the file.
2
Set the remote server address variable
Create a variable called REMOTE_SERVER and set it to user@192.168.1.100:/home/user/
Linux CLI
Hint
Use = to assign the string to the variable without spaces.
3
Use scp to copy the file to the remote server
Use the scp command to copy sample.txt to the remote server using the REMOTE_SERVER variable.
Linux CLI
Hint
Use double quotes around $REMOTE_SERVER to expand the variable correctly.
4
Use rsync to copy the file with progress and print confirmation
Use the rsync command with -avh --progress options to copy sample.txt to the remote server using the REMOTE_SERVER variable. Then print Transfer complete! using echo.
Linux CLI
Hint
Use rsync -avh --progress sample.txt "$REMOTE_SERVER" and then echo "Transfer complete!".
Practice
(1/5)
1. What is the primary difference between scp and rsync when transferring files?
easy
A. scp requires no authentication, rsync always does.
B. scp is used only for local copies, rsync only for remote.
C. scp compresses files automatically, rsync does not.
D. scp copies files directly, while rsync syncs only changed parts.
Solution
Step 1: Understand scp behavior
scp copies entire files securely from one machine to another without checking differences.
Step 2: Understand rsync behavior
rsync compares source and destination and transfers only changed parts, making it efficient for syncing.
Final Answer:
scp copies files directly, while rsync syncs only changed parts. -> Option D
3. What will be the output of this command if the directory backup/ exists on both local and remote, but only one file data.txt changed locally? rsync -avz backup/ user@remote:/home/user/backup/
medium
A. Only the changed data.txt file will be transferred to remote.
B. All files in backup/ will be transferred again.
C. The command will fail due to missing -r option.
D. The remote directory will be deleted and replaced.
Solution
Step 1: Understand rsync -avz flags
-a is archive (recursive + preserve), -v verbose, -z compress during transfer.
Step 2: Behavior with existing directories
rsync compares files and transfers only changed files, so only data.txt will be sent.
Final Answer:
Only the changed data.txt file will be transferred to remote. -> Option A
Quick Check:
rsync syncs changed files only = D [OK]
Hint: rsync with -a syncs only changed files, not all [OK]
Common Mistakes:
Thinking rsync copies all files every time
Believing -r is needed separately with -a
Assuming remote directory is deleted
4. You run this command to copy a directory: scp -r myfolder user@remote:/home/user/ But you get an error: scp: command not found. What is the most likely cause?
medium
A. You forgot to add the -v verbose flag.
B. The scp command is not installed on the local machine.
C. The remote path is incorrect and missing a trailing slash.
D. You need to use rsync instead of scp for directories.
Solution
Step 1: Analyze the error message
scp: command not found means the local system cannot find the scp program.
Step 2: Check other options
Verbose flag or remote path errors cause different errors; scp supports directories with -r.
Final Answer:
The scp command is not installed on the local machine. -> Option B
Quick Check:
Command not found means missing program = A [OK]
Hint: Command not found means program missing locally [OK]
Common Mistakes:
Assuming -v fixes command not found
Thinking remote path syntax causes this error
Believing scp can't copy directories
5. You want to efficiently backup a large folder project/ from your local machine to a remote server daily. Which command best ensures only new or changed files transfer, compresses data, and preserves permissions?
hard
A. scp -r project/ user@remote:/backup/project/
B. scp project/* user@remote:/backup/project/
C. rsync -avz project/ user@remote:/backup/project/
D. rsync -r project/ user@remote:/backup/project/
Solution
Step 1: Identify requirements
Need to transfer only new/changed files, compress data, and preserve permissions.
Step 2: Match command options
rsync -avz means archive (preserves permissions, recursive), verbose, and compress during transfer, ideal for backups.
Step 3: Compare other options
scp -r copies all files every time without compression; rsync -r lacks archive and compression flags.
Final Answer:
rsync -avz project/ user@remote:/backup/project/ -> Option C
Quick Check:
Efficient backup with compression and permissions = B [OK]
Hint: Use rsync -avz for efficient, compressed, permission-preserving backups [OK]
Common Mistakes:
Using scp for large repeated backups
Omitting -a flag in rsync losing permissions
Not compressing data during transfer
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.