Skip to content

Both.org

News, Opinion, Tutorials, and Community for Linux Users and SysAdmins

Primary Menu
  • About Us
  • Computers 101
    • Hardware 101
    • Operating Systems 101
  • End of 10 Events
    • Wake Forest, NC, — 2025-09-20
  • Linux
    • Why I use Linux
    • The real reason we use Linux
  • My Linux Books
    • systemd for Linux SysAdmins
    • Using and Administering Linux – Zero to SysAdmin: 2nd Edition
    • The Linux Philosophy for SysAdmins
    • Linux for Small Business Owners
    • Errata
      • Errata for The Linux Philosophy for SysAdmins
      • Errata for Using and Administering Linux — 1st Edition
      • Errata for Using and Administering Linux — 2nd Edition
  • Open Source Resources
    • What is Open Source?
    • What is Linux?
    • What is Open Source Software?
    • The Open Source Way
  • Write for us
    • Submission and Style guide
    • Advertising statement
  • Downloads
  • Home
  • Using tar and ssh for backups
  • Backups
  • Command Line
  • Linux

Using tar and ssh for backups

Couples complement each other and each member of the couple contributes unique and irreplaceable parts to the whole. But some couples are very odd. Such is the case with this couple of commands – the tar and ssh commands.
David Both April 4, 2024 5 minutes read
Network components

Last Updated on September 14, 2025 by David Both

Couples complement each other and each member of the couple contributes unique and irreplaceable parts to the whole. But some couples are very odd. Such is the case with this couple of commands – the tar and ssh commands.

Wait – what?!

Yup, that’s right, the tar and ssh commands work together in some very interesting ways – especially when used with full consideration of the capabilities of Standard I/O (STDIO), which is also known as standard streams.

ssh

Most everyone knows that the ssh command is a secure and sophisticated form of terminal emulator allows one to login to a remote computer to access a shell session and run commands. So I could login to a remote computer and run the ls command on the remote computer. The results are displayed in the ssh terminal emulator window on my local host. The Standard Output (STDOUT) of the command is displayed on my terminal window but it remains on the remote host and cannot be used by the local host.

That is trivial and everyone does that. But the next step is a bit more interesting. Rather than maintain a terminal session on the remote computer and issuing multiple commands, I can simply use a command like the following to run a single command on the remote computer with the results being displayed on the local host. This assumes that SSH public/private keypairs (PPKP) are in use and I do not have to enter a password each time I issue a command to the remote host.

# ssh remotehost ls

So now I can use the results of that command on my local host because the standard output data stream is sent through the SSH tunnel to the local host. OK, that is good, but what does it mean?

Let’s look at the tar command before we answer that question.

tar

The tar command is used to make backups. The name “tar” stands for Tape ARchive, but it can be used with any type of recording media such as tape, hard drives, thumb drives and more. A command like the following can be used to create a backup of a home directory on the local host.

# tar -cvf /tmp/home.tar /home

This command created a tar file – also called a tarball – named home.tar in the /tmp directory. That file is a backup of everything in the home directory. Well, that’s nice, but also not very interesting because it is very common. What can be very interesting about this is that, although many people do not realize it, if the target output file is not specified using the -f option, the output of the tar command is sent directly to STDOUT as in the sample below; try it.

# tar -cv /home

That means that the complete output of the tar command — the files being backed up — is sent to the terminal, which opens up some very interesting possibilities such as redirecting the STDOUT data stream to a backup file. That looks like the following command.

# tar -cv /home > /tmp/home.tar

This command performs the same function as the first tar command in this section, just in a somewhat different and more interesting manner.

The Odd Couple

We can use a command similar to the following to back up the home directory of the remote host to the /tmp directory of that remote host.

# ssh remotehost “tar -cvf /tmp/home.tar /home”

Note that the command to be executed on the remote host is enclosed in quotes to ensure that the correct command is executed remotely; this is a bit of clarification for both the shell and for us humans. A slight change to this command gives us one in which we simply redirect the output of the tar command to the /tmp directory on the remote host.

# ssh remotehost “tar -cv /home > /tmp/home.tar”

This command produces exactly the same result as the previous one. In this case the STDOUT data stream of the tar command is maintained entirely on the remote host and is redirected to the backup file.

However the next command is the one that opens up many new possibilities. Can you see what it does?

# ssh remotehost “tar -cv /home” > /tmp/home.tar

In this case the STDOUT data stream from the tar command is sent through the SSH connection to the local host. This stream of data is then redirected to the backup file /tmp/home.tar on the local host. Simply by moving the trailing quote to the left, the command is changed so that we now have a command that can do backups of remote hosts to a local host.

Final Thoughts

I used tar and ssh every day to perform backups. I used a script that uses ssh and tar, along with SSH public key encryption, to perform backups of several remote hosts to an external USB hard drive on a local host. These two commands make very simple a necessary task and the best part is that they are Free Open Source Software; free as in beer as well as free as in speech.

I now use rsync for backups, but that’s another article.

Tags: Backups ssh tar

Post navigation

Previous: Getting started with the Linux cat command
Next: How to update a Linux symlink

Related Stories

connections_wires_sysadmin_cable
  • Linux
  • Networking
  • Router

How to Make your Linux Box Into a Router

David Both April 29, 2026
f44-01-day-cropped
  • Fedora
  • Linux
  • Upgrades

Fedora 44 Released

David Both April 28, 2026
command_line_prompt
  • Command Line
  • Linux
  • Programming

Writing a replacement seq command

Jim Hall April 27, 2026

System upgrades this Sunday, May 3

Tools illustrationFedora 44 was released this week and I’ve upgraded all my systems except for the two that directly affect Both.org. I’ll be upgrading the hosts for my server and firewall to Fedora 44 this Sunday afternoon, May 3.

Both.org will be down for most of the afternoon for these upgrades.

Thanks for your patience.

Random Quote

I do not fear computers. I fear the lack of them.

— Isaac Asimov

Why I’ve Never Used Windows

On February 12 I gave a presentation at the Triangle Linux Users Group (TriLUG) about why I use Linux and why I’ve never used Windows.

Here’s the link to the video: https://www.youtube.com/live/uCK_haOXPFM 

Why there’s no such thing as AI

Last October at All Things Open (ATO) I was interviewed by Jason Hibbits of We Love Open Source. It’s posted in the article “Why today’s AI isn’t intelligent (yet)“.

Technically We Write — Our Partner Site

Our partner site, Technically We Write, has published a number of articles from several contributors to Both.org. Check them out.

Technically We Write is a community of technical writers, technical editors, copyeditors, web content writers, and all other roles in technical communication.

Subscribe to Both.org

To comment on articles, you must have an account.

Send your desired user ID, first and last name, and an email address for login (this must be the same email address used to register) to subscribe@both.org with “Subscribe” as the subject line.

You’ll receive a confirmation of your subscription with your initial password as soon as we are able to process it.

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

License and AI Statements

Both.org aims to publish everything under a Creative Commons Attribution ShareAlike license. Some items may be published under a different license. You are responsible to verify permissions before reusing content from this website.

The opinions expressed are those of the individual authors, not Both.org.

You may not use this content to train AI.

 

Advertising Statement

Both.org does not sell advertising on this website.


Advertising may keep most websites running—but at Both.org, we’re committed to keeping our corner of the web ad-free. Both.org does not sell advertising on the website. Nor do we offer sponsored articles at this time. We’ll update this page if our position on sponsorships changes.

We want to be open about how the website is funded. Both.org is supported entirely by David Both and a few other dedicated individuals.

 

 

Copyright © All rights reserved. | MoreNews by AF themes.