Use SCP to securely transfer files between two Unix computers (2024)

In Unix, you can use SCP (the scp command) to securely copy files and directories between remote hosts without starting an FTP session or logging into the remote systems explicitly. The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication. Unlike rcp or FTP, scp encrypts both the file and any passwords exchanged so that anyone snooping on the network cannot view them.

Note:

Two-factor authentication using Two-Step Login (Duo) is required for access to the login nodes on IU research supercomputers, and for SCP and SFTP file transfers to those systems. SSH public key authentication remains an option for researchers who submit the "SSH public key authentication to HPS systems" agreement, in which you agree to set a passphrase on your private key when you generate your key pair. If you have questions about how two-factor authentication may impact your workflows, contact the UITS Research Applications and Deep Learning team. For help, see Get started with Two-Step Login (Duo) at IU and Help for Two-Step Login (Duo).

Syntax

The syntax for the scp command is:

scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2

The location of the source file is specified by username1@source_host:directory1/filename1, which includes the:

  • Name of the account on the host computer (username1)
  • Hostname of the computer on which the source file resides (source_host)
  • Name of the directory containing the source file (directory1)
  • Filename of the source file (filename1)

The location to which the source file will be copied is specified by username2@destination_host:directory2/filename2, which includes the:

  • Name of the account on the destination computer (username2)
  • Hostname of the computer to which the source file will be copied (destination_host)
  • Name of the directory to which the source file will be copied (directory2)
  • Filename of the copy (filename2)

Note:

Make sure to include a space between the source and destination paths. Also, be careful when copying files that share the same name on both hosts; you may accidentally overwrite data you intended to keep.

For more about scp, consult its manual page. At the Unix prompt, enter:

man scp

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

Examples

For the following examples, assume your username is dvader, and you are logged into your account on the computer empire.gov:

  • To copy a file called rebels.txt from your home directory on empire.gov to a directory called revenge in your account on the computer deathstar.com, enter:
    scp ~/rebels.txt [email protected]:~/revenge

    You'll be prompted for your password on the destination system (deathstar.com). The command won't work unless you enter the correct password.

  • To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents.

    To copy the entire revenge directory from your deathstar.com account to your empire.gov account, enter:

    scp -r [email protected]:~/revenge ~/revenge

    You'll be prompted for your password on the source system (deathstar.com). The command won't work unless you enter the correct password.

  • To copy multiple files within a directory, you can use wildcards (for example, * or ?). However, to use wildcards for copying multiple source files from a remote system, you need to place quotes ("") around the path to the source files. This is necessary because the Unix shell, not the scp command, expands unquoted wildcards.

    Therefore, to copy all the .txt files from the revenge directory on your deathstar.com account to your revenge directory on empire.gov, enter:

    scp [email protected]:"revenge/*.txt" ~/revenge/

    You'll be prompted for your password on the source system (deathstar.com). The command won't work unless you enter the correct password.

For the following example, assume you (dvader) are logged into another computer (that is, some other computer that's not empire.gov or deathstar.com). To copy luke.txt from your home directory on empire.gov to your revenge directory on deathstar.com, enter:

scp [email protected]:~/luke.txt [email protected]:~/revenge

You'll be prompted to enter two passwords: one for the source system (empire.gov) and one for the destination system (deathstar.com). The command won't work unless you correctly enter both passwords.

Related documents

Set up SSH public key authentication to connect to a remote systemAbout ssh-agent and ssh-add in Unix

This is document agye in the Knowledge Base.
Last modified on 2023-08-21 11:18:44.

Use SCP to securely transfer files between two Unix computers (2024)

FAQs

How do I transfer files between two Unix servers? ›

In Unix, you can use SCP (the scp command) to securely copy files and directories between remote hosts without starting an FTP session or logging into the remote systems explicitly. The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication.

How to securely copy files in between machines by using SCP command? ›

The most common scp options are as follows:
  1. -C: Compress the file data.
  2. -i: Use the specified private key for the remote system.
  3. -l: Set a bandwidth limit for the file transfer.
  4. -P: Use the specified port for SSH.
  5. -p: Copy over the file modification and access time.
  6. -q: Use quiet mode. ...
  7. -r: Copy directories recursively.
Mar 14, 2023

Is SCP file transfer secure? ›

The Secure Copy Protocol, or SCP, is a file transfer network protocol used to move files onto servers, and it fully supports encryption and authentication.

How do you secure file transfer in Unix? ›

Use sftp to transfer files securely between the local computer and a remote host. You can also perform other file management commands, such as creating directories and changing file permissions.

Why is Rsync better than SCP? ›

In terms of performance, Rsync is comparatively more optimized and fast(speed-wise). Scp is relatively less optimized and slower. Allows us to synchronize remote folders.

What is the difference between SCP and SFTP? ›

SCP vs SFTP

Unlike SFTP, SCP has fewer commands and is used primarily to copy files between a local host and a remote host or between two remote hosts. SCP is unable to create or list directories or delete files like SFTP.

What is the alternative to SCP to transfer files? ›

SFTP, or Secure File Transfer Protocol, also operates over SSH. But, unlike SCP, it's not just for file transfer—it's more of a full-fledged remote file management protocol. SFTP allows you to perform various operations on remote files, like viewing directories, deleting files, and more.

What is the SCP file transfer method? ›

The Secure Copy Protocol (SCP) is a network protocol that enables secure file transfers between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. SCP is known for its simplicity, security, and pre-installed availability.

How do I SCP a file between servers? ›

The basic syntax is:
  1. scp username@source:/location/to/file username@destination:/where/to/put. ...
  2. scp /file/to/send username@remote:/where/to/put. ...
  3. scp ~/image.jpg [email protected]:/root/images. ...
  4. scp ~/image.jpg serverName:/root/images. ...
  5. scp -P 22022 ~/.db root@remote:/.db.

Is SCP outdated? ›

It is based on the Secure Shell (SSH) protocol. "SCP" commonly refers to both the Secure Copy Protocol and the program itself. According to OpenSSH developers in April 2019, SCP is outdated, inflexible and not readily fixed; they recommend the use of more modern protocols like SFTP and rsync for file transfer.

Is SCP better than FTP? ›

SCP transfers files over an encrypted channel, preventing the data from being intercepted or tampered with during transit. This makes SCP a preferred choice when transferring sensitive or confidential data.

Why is SCP deprecated? ›

We're making this change because the SCP protocol is decades old, and carries multiple security risks and issues that have no straightforward solutions.

How do I securely transfer files between computers? ›

2. External hard drives or USB flash drives
  1. Connect the external drive to your old PC.
  2. Copy the files you want to transfer.
  3. Safely eject the drive.
  4. Connect it to your new PC.
  5. Copy the files to your new computer.
Jul 31, 2024

How do I transfer files between Unix servers? ›

To transfer files back and forth to CS unix servers from a unix system, use either the scp(non-interactive) or sftp(interactive) commands. Both of these commands will do file transfers between unix/linux 'ssh' hosts, with each one working differently.

How do I securely transfer files in Linux? ›

SCP (Secure Copy Protocol) is a network protocol that securely copies files/folders between Linux (Unix) systems on a network. To transmit, use the scp command line utility, a safer variant of the cp (copy) command.

How to move files from one server to another in Linux? ›

How to Transfer Files via FTP
  1. Step 1 – Connect to FTP. In the example below, hostA is the remote host. ...
  2. Step 2 – Choose file transfer mode. You can choose the mode (binary or ASCII) depending on your file type. ...
  3. Step 3 – Transfer files. We use the get command to transfer the file sample. ...
  4. End the session.
Dec 20, 2021

How do I copy from one Unix server to another? ›

SCP (Secure Copy Protocol) is a network protocol that securely copies files/folders between Linux (Unix) systems on a network. To transmit, use the scp command line utility, a safer variant of the cp (copy) command.

How do I connect to a Unix server from another Unix server? ›

You can use two different programs to connect to another shared Unix computer: telnet and SSH. Since telnet transfers all data unencrypted over the network (including passwords), UITS recommends that you use SSH if it is supported by the host to which you are connecting.

How do I copy multiple files from one server to another in Linux? ›

You use the cp command for copying files from one location to another. This command can also copy directories (folders). [file/directory-sources] specifies the sources of the files or directories you want to copy. And the [destination] argument specifies the location you want to copy the file to.

Top Articles
Should I Buy a House in Las Vegas? I IS Luxury
Apple Pay use in France 2024 | Statista
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 6130

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.