The most useful SSH archive pattern is a tar pipeline: make tar write an archive to standard output on one machine, send that byte stream through ssh, and redirect or extract it on the other machine. For example, this creates a compressed backup of a remote directory directly on your computer without leaving an archive file on the server:
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
ssh user@host 'tar czf - /var/www' > website-backup.tar.gz
The remote command creates a gzip-compressed tar stream, SSH carries it, and the local shell saves it. The same idea works in the opposite direction, for remote extraction, and for streaming a directory straight into a local restore directory.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
How the SSH and tar pieces fit together
GNU tar is used to create, list, and extract tar archives. Its three core operations are create (-c), list (-t), and extract (-x). The archive file argument can be an ordinary filename, or a single hyphen. A hyphen tells tar to read archive bytes from standard input or write them to standard output. That convention is what makes an SSH pipeline possible.
SSH runs a command on the remote host and transports its standard input and output over the encrypted connection. The local shell still controls redirections that appear outside the quoted remote command. This distinction matters: in ssh user@host 'tar czf - /var/www' > website-backup.tar.gz, tar runs remotely, while the > redirection creates the file locally.
#1 Best Overall
The three tar operations
| Purpose | Command | What it does |
|---|---|---|
| Create | tar cf backup.tar ./data |
Packages ./data into an uncompressed archive. |
| List | tar tf backup.tar |
Prints the archive members without extracting them. |
| Extract | tar xf backup.tar -C ./restore |
Extracts members into the explicitly selected destination. |
Compression flags
Compression is selected with a flag: -z for gzip, -j for bzip2, and -J for xz. GNU tar also supports lzip, lzma, lzop, zstd, and traditional compress. The -a option can select a compressor from the archive filename suffix when tar is creating an archive. When bytes arrive through standard input, there is no filename suffix for tar to inspect, so specify the matching compression flag explicitly.
| Format | Create | List | Extract |
|---|---|---|---|
| Uncompressed tar | tar cf archive.tar files |
tar tf archive.tar |
tar xf archive.tar |
| gzip | tar czf archive.tar.gz files |
tar tzf archive.tar.gz |
tar xzf archive.tar.gz |
| bzip2 | tar cjf archive.tar.bz2 files |
tar tjf archive.tar.bz2 |
tar xjf archive.tar.bz2 |
| xz | tar cJf archive.tar.xz files |
tar tJf archive.tar.xz |
tar xJf archive.tar.xz |
Prerequisites before you stream anything
- An SSH client on the machine where you start the command and an SSH server on the destination host.
- An account that can read every source file and directory. For extraction, it must also be able to write the destination.
taron every side where tar runs.- The compressor and decompressor required by your chosen mode. Gzip mode needs the gzip program, bzip2 mode needs bzip2, and xz mode needs xz support.
- Enough space at the receiving end for the archive file or the expanded contents, depending on the pipeline.
Test the connection and the remote tools before starting a long transfer. For example, ssh user@host 'command -v tar gzip' should return paths for the required programs. If the remote account cannot access a directory, changing the SSH command will not fix that permission problem; use an account or destination with the required rights.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Create an archive on a remote host and save it locally
This is the usual remote-backup pattern. Tar runs on the server, writes compressed bytes to standard output, and your local shell redirects those bytes to a file.
ssh user@host 'tar czf - /var/www' > website-backup.tar.gz
- Replace
user@hostwith the SSH account and host name. - Replace
/var/wwwwith the remote path you want to read. - Keep the entire remote tar command inside single quotes. This prevents the local shell from expanding remote paths, globs, or operators before SSH sends the command.
- Put the local output redirection outside those quotes. The resulting
website-backup.tar.gzis created on the computer where you run SSH.
The hyphen after czf is essential. It tells tar not to create a named file on the server and instead to emit the archive stream. The command therefore avoids a temporary archive on the remote disk. Tar may print diagnostic messages to the remote standard error stream; those messages are separate from the archive bytes written to standard output.
Choosing paths inside the archive
Tar records the path you provide. An absolute source such as /var/www can produce members rooted at that path, while a relative source such as ./project records a path relative to the directory from which tar runs. Decide which layout you want before restoring. If the archive will be moved between systems, a relative path often makes the extraction destination easier to control.
Create an archive locally and save it on the remote host
Reverse the pipeline when the source data is on your computer and the archive file belongs on the server:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →tar czf - ./project | ssh user@host 'cat > project.tar.gz'
Local tar reads ./project, compresses it with gzip, and writes to standard output. The pipe feeds that stream to SSH. On the remote side, cat > project.tar.gz writes the received bytes to a file. Because the redirection is inside the quoted remote command, the file is created on the remote host rather than locally.
This command does not extract the files on the server; it stores one archive there. To restore it later, inspect it with ssh user@host 'tar tzf project.tar.gz', then extract it into a deliberate directory.
Extract a local archive on a remote host
When an archive already exists locally, stream it into tar running remotely:
cat project.tar.gz | ssh user@host 'tar xzf - -C /srv/project'
catreads the local archive and sends its bytes into the pipe.- SSH forwards those bytes as standard input to the remote command.
- Remote tar uses
xto extract,zto decode gzip, andf -to read the archive from standard input. -C /srv/projectselects the remote extraction directory.
The destination must already exist or be creatable by the remote account. If it is a protected system location, use an appropriate account and confirm that writing there is intended. Do not omit the compression flag merely because the stream has a .gz filename on your computer; the remote tar process sees bytes from standard input, not that filename.
A direct redirection variant
You can use input redirection instead of cat:
ssh user@host 'tar xzf - -C /srv/project' < project.tar.gz
Here the local shell supplies the archive as SSH standard input, while the remote tar command still reads from its own standard input. Both forms transfer the same bytes; choose the one that is clearer in your scripts.
Extract a remote directory locally without creating a remote archive
This pipeline creates the archive stream remotely and extracts it immediately on your machine:
ssh user@host 'tar czf - /var/log/app' | tar xzf - -C ./app-log-copy
The first tar process runs on the remote host. The second tar process runs locally, decodes gzip, and writes members into ./app-log-copy. No .tar.gz file is stored on either side unless you add a redirection. This is useful when you need a one-time copy of a directory and have space for the expanded files but do not need an intermediate archive.
Create or select the local destination deliberately. If it does not exist, create it before extraction with your normal directory-creation command, then run the pipeline. A destination such as ./app-log-copy makes it clear where files will land and avoids accidentally unpacking into an unrelated current directory.
Inspect an archive before extracting it
Listing is a safety step, not just a convenience. For an uncompressed archive, run:
Rank #4
tar tf backup.tar
For gzip, use:
tar tzf backup.tar.gz
For a remote archive, list it over SSH without extracting:
ssh user@host 'tar tzf project.tar.gz'
Review the member names, top-level directories, and any unexpected absolute paths or parent-directory components. Archives from an untrusted source deserve particular care: extract only after you understand what each member name will do, and use a dedicated destination rather than a sensitive system directory. GNU tar documents untrusted extraction as a separate safety concern because archive names can affect locations outside the directory you intended.
Preserve or avoid permissions intentionally
By default, extraction is subject to the destination’s normal ownership and permission rules. Add tar’s -p option only when restoring permissions is intentional and the account is allowed to do so. On a game server or shared host, blindly restoring ownership or mode bits can make files inaccessible to the service account or expose them more broadly than expected. If ordinary content restoration is the goal, leave -p out and let the destination’s normal rules apply.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteQuote remote commands correctly
There are two shells to think about: your local shell and the shell started by SSH on the host. Single-quote the complete remote command whenever it contains paths, wildcards, pipes, or redirections that should be interpreted remotely.
ssh user@host 'tar czf - /srv/game-data' > game-data.tar.gz
In this example, the remote shell interprets the tar command, while the local shell interprets the final redirection. Moving the redirection inside the quotes changes the destination:
Best Value
ssh user@host 'tar czf - /srv/game-data > game-data.tar.gz'
Now the archive file is created on the remote host. This is often useful, but it is a different operation. Keep the placement of every pipe and redirection deliberate.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Choosing tar over SSH, scp, sftp, or rsync
| Tool or pattern | Best fit | Important trade-off |
|---|---|---|
| tar over SSH | Create or extract while transferring; stream a directory without an intermediate archive. | Requires tar and the selected compressor on the side where tar runs. A failed stream can leave a partial output file. |
scp |
Copy an archive or other file that already exists. | It transfers the existing file; it does not itself package a directory into tar format. |
sftp |
Interactive or scripted file transfer when you want a file-oriented session. | Like scp, it is a transfer mechanism rather than an archive creator. |
rsync over SSH |
Recurring synchronization, exclusions, and large directory trees where resending unchanged bytes is wasteful. | It synchronizes directory state rather than producing one portable tarball. |
OpenSSH supplies ssh, scp, and sftp. Rsync can use SSH as its remote shell. Use scp or sftp when an archive already exists and you simply need to copy it. Use tar over SSH when packaging and transport belong in one operation. Choose rsync for repeated updates to a directory tree, especially when sending a complete archive every time would be inefficient.
Recommended Free Tools
Practical backup patterns for game servers
Game-server worlds, configuration directories, and log trees are ordinary files from tar’s point of view. The important decisions are consistency, permissions, and destination. If the service is actively writing files, stop it or use the server’s own save procedure before archiving when consistent state matters; tar can only capture the filesystem state it encounters while reading.
Save a remote world locally
ssh admin@game-host 'tar czf - /srv/game/world' > world-backup.tar.gz
This keeps the compressed backup on the administrator’s machine. Use a filename that identifies the server and backup time according to your own retention scheme.
Restore a local world to a remote staging directory
cat world-backup.tar.gz | ssh admin@game-host 'tar xzf - -C /srv/game/staging'
List the archive first, confirm that the recorded top-level directory is what you expect, and restore into staging before replacing a live directory. Apply -p only if preserving the archive’s permission bits is part of the recovery plan.
Reliability checklist for long streams
- Confirm the source path is correct and readable by the SSH account.
- Confirm the receiving file system has enough space for the archive or extracted tree.
- Verify that tar and the required compressor exist on the machine where each tar process runs.
- Quote the remote command so expansion and redirection happen on the intended side.
- Use an explicit
-Cdestination when extracting. - Inspect members with
tar tfortar tzfbefore unpacking an archive you did not create yourself. - Do not add
-punless restoring permissions is intentional and permitted. - Check the command’s exit status after completion. A connection failure, read error, or write error means the resulting archive or extraction may be incomplete.
Troubleshooting common failures
| Symptom | Likely cause | Fix |
|---|---|---|
Archive is compressed. Use -z option |
Compressed bytes arrived through standard input, but tar was not told which compression format to decode. | Use the matching flag, such as tar tzf - for listing gzip data or tar xzf - for extracting it. |
| Permission denied while creating the stream | The SSH account cannot read one of the source paths. | Check the path and account permissions, or run with an account that is authorized to read the data. |
| Permission denied during extraction | The destination does not permit the remote account to write, or an existing member cannot be replaced. | Choose a writable destination, correct its permissions, or use an authorized account. Do not solve this by restoring permissions blindly. |
tar: command not found or a compressor is missing |
The required program is not installed or is not on the remote command’s path. | Install or enable the required tool, or select a compression mode supported on that host. |
| The output file is empty or unexpectedly small | The remote command did not write the archive to standard output, or a redirection was placed on the wrong side of SSH. | Use tar czf - for a stream and verify whether each > is intended to be local or remote. |
| Files appear in the wrong directory | The extraction ran in the current working directory or the archive contains an unexpected path prefix. | List the members first and extract with an explicit -C destination. |
| A pipeline stops partway through | The SSH connection, source read, compressor, or destination write failed. | Read the diagnostic output, check both ends’ permissions and available space, and rerun only after identifying the failing side. Treat the partial archive or tree as incomplete. |
A concise decision guide
- If you need a compressed file on your computer from a remote directory, run
ssh user@host 'tar czf - /remote/path' > local.tar.gz. - If you need to store a local directory as an archive on the server, run
tar czf - ./local/path | ssh user@host 'cat > remote.tar.gz'. - If you have a local gzip archive and want it extracted remotely, run
cat local.tar.gz | ssh user@host 'tar xzf - -C /remote/destination'. - If you want a one-time remote-to-local copy without an intermediate archive, run
ssh user@host 'tar czf - /remote/path' | tar xzf - -C ./local-destination. - If the archive already exists and only needs copying, use scp or sftp.
- If the directory will be synchronized repeatedly, use rsync over SSH instead of rebuilding and retransmitting a complete tarball.
Tar’s standard-input and standard-output behavior is the key: replace the archive filename with -, place SSH between the two tar processes when necessary, and keep every redirection on the side where the file should actually be created. With an explicit compression flag, a deliberate extraction directory, and a member listing before untrusted restores, the same small set of commands covers remote backups, migrations, staging restores, and routine server maintenance.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




