How To Use SCP

SCP is a command line program that allows to copy files between computers (hosts) in a very secure manner. This How To How To Use SCP describes how you can copy files securely between computers.

Index of How To How To Use SCP

Environment

This How To How To Use SCP takes as a basis two computers (hosts). I share the environment with you, as i believe it helps you to understand how you can leverage on this powerful SCP tool for your enviornement.

  • Host A – IP Address 192.168.2.45
  • Host B – IP Address 192.168.2.21
  • I move a number of backup files from Computer A to Computer B
  • Both, Computer A and Computer B are Raspberry computers
  • Between both computers (A and B) the SSH keys are exchanged (trusted)

By the way, the same works of course also on an Apple Mac, such as a cool Mac Book Air or an even cooler Mac Book Pro!

How to How To Use SCP

Your idea is to copy files form Computer A to Computer B (192.168.2.21) in a simple and secure manner. To be honest, nothing is easier than this. The execution of a simple command will get this done for you:

scp [OPTION] [user@]Computer_A:]file1 [user@]Computer_B:]file1

If you like to copy a whole directory, then you like to replace “file 1” by the directory name. In case of the directory name, please ensure the directory exists on the destination host:

scp [OPTION] [user@]Computer_A:]/directory1 [user@]Computer_B:]directory1

Now lets make a real life example matching my environment. I have a bunch of files stored on Computer A (192.168.2.45) in the source directory called “~/Backup_OpenHAB_DB/pi/maria-db-backups”. To ensure these files are additionally backed up on another Computer B, i copy them with the below scp command into the destination folder called “~/maria-db-backups-ARCHIVE/2023”. To do so is easy, you simply leverage on the below command:

scp /home/myuser/Backup_OpenHAB_DB/pi/maria-db-unserhaus-backups/maria-db-backups.sql.2023* pi@192.168.2.21:/home/pi/maria-db-backups-ARCHIVE/2023

Details:

  • scp – is reflecting the scp command
  • /home/myuser/Backup_OpenHAB_DB/pi/maria-db-unserhaus-backups/ – is reflecting the source directory on Host A (192.168.2.45)
  • maria-db-backups.sql.2023* – is reflecting the file names. In this case all files that start with “maria-db-backups.sql.2020”
  • pi@192.168.2.21: – is reflecting 2 things, 1. the user name on Host B (in this case “pi”) and the IP Address of Host B (192.168.2.21)
  • /home/pi/maria-db-backups-ARCHIVE/2023 – is reflecting the destination directory on Host B (192.168.2.21)

Very simple, isn’t it? Now you simply replace the computer names and directories by how it looks like in your computer environment and this How To Use SCP hopefully was a great help to you. 

There are various additional options that you can use for SCP. Including:

  • -P : – P specifies the remote host ssh port (e.g. the port on Host B if it is not 22 which is the standard SSH port
  • -C : -C forces scp to compresses data whilst sending to the destination host (e.g. in the above Host B)
  • -rThis option asks scp to copy directories recursively (e.g. if there would be additional subdirectories in /home/myuser/Backup_OpenHAB_DB/pi/maria-db-backups/)

As with all Linux programs, also SCP consists of a very good explaining man page that you like to consult for further great options. You can find this in your Linux installation itself by typing “man scp” or in the internet by clicking this link: SCP Man Pages.

Follow me

It would be amazing if you follow my myhowto.blog. To my blog is actually easy! You can leverage on

  • Click to follow me on Twitter
  • Bookmark this page and comeback from time to time

Help and Comments

I am really looking forward for you to contact me if for example you found a better option or other idea then in this how to. Also, please touch base if you found an error or anything not working or if you have something that you would love to be added to the myhowto.blog. Simply click this link to touch base with me.

Linking Or Recommending The How To Or The myhowto.blog

I would love to see you are recommending this how to or link it to your website. Also, I would love if you link or recommend the whole myhowto.blog. Please feel free to do so! In case you like to touch base regarding this topic with me, then simply click this link. I look forward!