Section 1 of 10

1 Before you start

Before you begin, take a few minutes to check what you already know and how confident you feel. You will see the same questions again at the end of the module — this helps both you and us measure what you have learned. Click an option for every question and confidence rating, then click Next to continue.

Pre-test

Which command copies local results.tsv into /tmp on the remote host cluster?

Pre-test

What is the main advantage of rsync over scp?

Pre-test

What does rsync --dry-run do?

Pre-test

What is the difference between rsync -av data dest/ and rsync -av data/ dest/?

Pre-test

How do you keep a long job running on a server after your SSH connection drops?

Pre-test

Which scp flag sets a non-standard port, and why avoid the lowercase one?

Pre-test

Which scp flag lets you copy an entire folder to the remote machine?

Pre-test

On a shared server like Bandit, why copy files into /tmp rather than your home directory?

Pre-confidence

I can copy files to and from a remote machine with scp.

Not at all confident
Fully confident
Pre-confidence

I can use rsync to sync a folder, and I understand the trailing-slash rule.

Not at all confident
Fully confident
Pre-confidence

I can run a long remote job inside tmux so it survives a dropped connection.

Not at all confident
Fully confident
Section 2 of 10

2 Introduction

Logging in is half the story. The other half is getting files to and from the remote machine, and keeping your work alive when the connection drops over a network.

Unlike the earlier lessons that practised over localhost, here you connect to a real public server on the internet: the OverTheWire Bandit game. It is the same set of skills you will use to reach the teaching cluster, just on a server that is safe to experiment on.

In this lesson, we will cover the following:

  • Logging in to our practice server withssh
  • scp - simple copies to and from a remote machine.
  • rsync - the efficient, resumable workhorse for real data.
  • The trailing-slash rule that trips everyone up.
  • ssh + tmux: jobs that survive a dropped connection.
Section 3 of 10

3 Logging in to practice server

  • Every command below talks to the same machine. Its details are:
  • Host (the address): bandit.labs.overthewire.org
  • Port: 2220
  • Username: bandit0
  • Password: bandit0

Open a terminal (Terminal on macOS or Linux; PowerShell or Command Prompt on Windows, both of which already include ssh and scp) and connect:

Try it out

Try this snippet in the Bash Scratchpad on the right.

Try this snippet
$ ssh bandit0@bandit.labs.overthewire.org -p 2220

Your prompt changes to bandit0@bandit:~$. That is your sign that you are now on the server.

To leave and return to your own machine, type exit (or press Ctrla+D).

Section 4 of 10

4 scp - Copy Files Over SSH

scp (secure copy) works exactly like the standard cp (copy) command, but it allows you to copy files across a network. One side of the command will carry a host: prefix to specify the remote machine.

You can copy files from your computer to the server, from the server back to your computer, and copy entire folders using the -r (recursive) flag:

# General syntax
$ scp [source] [destination]

# Copy a file to the server
$ scp -P 2220 results.tsv bandit0@bandit.labs.overthewire.org:/tmp/

# Copy a file from the server to your local machine
$ scp -P 2220 bandit0@bandit.labs.overthewire.org:/tmp/results.tsv ./pulled_back.tsv

# Copy an entire folder to the server
$ scp -P 2220 -r reports/ bandit0@bandit.labs.overthewire.org:/tmp/reports/
scp is just cp across a network, and the side of the command carrying the host: prefix is the remote machine, which is also what sets the direction of the copy (prefix on the destination = upload, prefix on the source = download).
scp is just cp across a network, and the side of the command carrying the host: prefix is the remote machine, which is also what sets the direction of the copy (prefix on the destination = upload, prefix on the source = download).

Anything before the colon is the local path; anything after the host: is the remote path. If you have an alias set up in your ~/.ssh/config, you can use that instead of the full address.

Section 5 of 10

5 rsync - The Workhorse

While scp is great for single files, rsync is the tool of choice for datasets. rsync only copies the differences between the source and destination. If you run it once, it copies everything; if you change two files and run it again, it transfers only those two files. This makes it fast, resumable, and ideal for syncing data.

$ rsync -av reports/ localhost:/tmp/reports/
sending incremental file list
report_001.txt
report_002.txt
report_003.txt
rsync compares source and destination and transfers only the files that differ, so re-syncing a dataset after small edits moves just those few changes instead of recopying everything.
rsync compares source and destination and transfers only the files that differ, so re-syncing a dataset after small edits moves just those few changes instead of recopying everything.

Here are some of the common flags that you can pair with rsync

  • -a - archive mode: recurse and preserve permissions, timestamps, and structure.
  • -v - verbose: list what is transferred.
  • -z - compress in transit, worth it on a slow network.
  • --progress - show a live progress bar for big files.
  • --dry-run - show what WOULD transfer without touching anything.
  • Always run a --dry-run first when using an unfamiliar rsync command to prevent accidental overwrites.
$ rsync -avz --dry-run cohort/ localhost:/tmp/backup/cohort/
# lists the files that would transfer
changes nothing
Common rsync flags do not change that it copies a source to a destination, they change how it copies
Common rsync flags do not change that it copies a source to a destination, they change how it copies
Section 6 of 10

6 The Trailing Slash Rule

The most common mistake with rsync involves the trailing slash on the source directory. It determines whether you copy the folder itself, or the contents inside the folder.

  • No Slash (cohort): Copies the folder. The result is dest/cohort/...
  • With Slash (cohort/): Copies the contents. The result is dest/... directly.

If you get this wrong, you may accidentally nest folders (dest/cohort/cohort) or dump files one level too high. When in doubt, use --dry-run.

A trailing slash on an rsync source copies the folder's contents into the destination, while no slash copies the folder itself, so the same command lands files one directory level apart.
A trailing slash on an rsync source copies the folder's contents into the destination, while no slash copies the folder itself, so the same command lands files one directory level apart.

Note: rsync is native to macOS and Linux. Windows users will need to run it inside WSL or directly on the remote server

Section 7 of 10

7 Staying Connected - ssh + tmux

Here is a scenario every computational researcher faces: you SSH into a server, start a long script, and your Wi-Fi briefly disconnects. The SSH session dies, the script is killed, and your work vanishes.

The solution is combining ssh with tmux. While you won't run long jobs on Bandit, this is the exact workflow you will use on real research clusters

Step 1. Log in, start a tmux session on the remote machine, and launch the job inside it:

$ ssh cluster
$ tmux new -s run
$ ./cohort_summary.sh big_cohort.csv out.tsv
# press the tmux prefix, then d, to detach, after which you can safely disconnect

Step 2. Detach and disconnect.

Press your tmux prefix (Ctrl + b), release, then press d to detach. You can now safely type exit to drop the SSH connection and close your laptop. The job continues running on the server.

Step 3. Reconnect later.

From anywhere, SSH back in and reattach to the session to pick up exactly where you left off.

$ ssh cluster
$ tmux attach -t run
# the job ran the whole time
the full scrollback is here
A job launched inside tmux lives on the server rather than on your SSH connection, so when your link drops the job keeps running and you lose nothing by detaching, disconnecting, and reattaching later.
A job launched inside tmux lives on the server rather than on your SSH connection, so when your link drops the job keeps running and you lose nothing by detaching, disconnecting, and reattaching later.

Never run a long job directly in a bare SSH session. Start tmux first. If your connection drops, your job neither knows nor cares.

Section 8 of 10

8 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

Which command copies local results.tsv into /tmp on the remote host cluster?

Post-test

What is the main advantage of rsync over scp?

Post-test

What does rsync --dry-run do?

Post-test

What is the difference between rsync -av data dest/ and rsync -av data/ dest/?

Post-test

How do you keep a long job running on a server after your SSH connection drops?

Post-test

Which scp flag sets a non-standard port, and why avoid the lowercase one?

Post-test

Which scp flag lets you copy an entire folder to the remote machine?

Post-test

On a shared server like Bandit, why copy files into /tmp rather than your home directory?

Post-confidence

I can copy files to and from a remote machine with scp.

Not at all confident
Fully confident
Post-confidence

I can use rsync to sync a folder, and I understand the trailing-slash rule.

Not at all confident
Fully confident
Post-confidence

I can run a long remote job inside tmux so it survives a dropped connection.

Not at all confident
Fully confident
Section 9 of 10

9 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)