How to use SCP to transfer files in the macOS Terminal | AppleInsider (2024)

AppleInsider may earn an affiliate commission on purchases made through links on our site.

Secure Copy is a UNIX standard used to transfer files from one computer to another. He's how to use the function in macOS, all via the Terminal window.

Before personal computers, there were mainframe computers and timesharing terminals. Users would log in to an account from a terminal to a mainframe, and issue commands to the mainframe to process.

As the internet came of age in the 1990s the need arose to be able to use such terminal commands securely across networks and computers. In 1994 a Finnish programmer named Tatu Ylonen created the Secure Shell. For background on using Secure Shell, see our other SSH intro article.

As part of the Secure Shell, the SCP (Secure Copy Protocol) program was created. SCP is both a protocol and a UNIX program which can be run from the Terminal command line in macOS.

SCP enables file transfers to and from SSH servers in both directions. SCP is based on the RCP (Remote Copy) command (part of BSD's r-commands) which was originally used when BSD came to prominence in the mid 1980's.

The default TCP port used for SCP file transfer is 22 (the standard SSH port).

Unlike other internet standards, there is no RFC or formal standard for SCP - it's part of the open-source OpenSSH project. You can view all of OpenSSH's source code at its GitHub project.

Basic Usage

In order to use SCP to transfer files, you must first establish an SSH connection via login to the remote server you wish to transfer files with. This is done either by a username/password-based login in Terminal, or via the use of public key infrastructure (SSH PKI key pairs).

Once logged in to the remote server, you use the 'scp' command followed by options in Terminal to transfer files. There is no way to obtain directory listings using scp, nor does it provide a way to delete remote files, but you can use standard UNIX filesystem commands such as ls to obtain directory listings once logged in to the remote computer.

After an SSH connection is established, all commands in that macOS Terminal window tab go to the server instead of to your Mac.

For example, in the macOS Terminal to get a directory listing of files on either the local machine or the remote server, you can issue an ls command such as:

ls -l

The "-l" flag tells ls to list files vertically, in the Terminal window with each file/folder's details such as UNIX permissions, owner, group, size, and file creation date and time. If you omit the "-l" flag, the ls command lists only file names in several columns without each file's details.

For more details on the ls command, in Terminal type man ls and press Return.

To exit the man page system in Terminal for any man page, type Control-Z and press Return.

You can also use the 'cd' (change directory) command to change directories within a local or remote file system. Simply type 'cd' followed by a space, and the name or path of the directory you want to change to. All Terminal commands then operate on that directory, unless you cd again to another directory or specify a full path in a command.

To go up one directory level in a filesystem using cd in Terminal, you can type:

cd ../

and press Return.

To go to the very top (root) of a filesystem, type:

cd /

and press Return.

You can have Terminal print the current full path and directory name in any filesystem by typing:

pwd

and pressing Return.

'pwd' is the UNIX command to get the present working directory (i.e. - the current directory the Terminal shell is operating in). For the manual page on pwd in Terminal, type:

man pwd

and press Return.

See the scp man page for more details on flag usage with the command:

man scp

and press Return.

scp examples

SCP or 'scp' in the Terminal is easy to use. The basic command syntax is 'scp' followed by file name, user name, server name or IP address, and remote directory path on that server to access. For example:

scp example.txt [emailprotected]:/directoryName/

tells scp to copy a local file in the pwd named "example.txt" to the server at IP address 10.10.0.1 on that server's filesystem directory named "directoryName" as the user named "remote_user" with the remote file copy to be named "example.txt" also.

If you omit the remote file's name the same name as the source file will be used. If you want to change the remote file's name to something else, include a new file name after the remote directory path at the end of the command:

scp example.txt [emailprotected]:/directoryName/newExample.txt

Also note that the user indicated must have permissions in the remote directory specified in order to copy the file.

An opposite example - copying a file on the remote server to your Mac, looks similar. For example:

scp [emailprotected]:/directoryName/example.txt /Users/your_username/Desktop/

copies the file named "example.txt" in directory "directoryName" on the remote server to your Mac's Desktop.

You can also specify flags immediately after the scp portion using the a minus sign followed by the option.

Two flags after "scp " can be used to specify either version one two of the SSH protocol: -1' or -2'. For example:

scp -2 example.txt [emailprotected]:/directoryName/newExample.txt

forces use of version two of the protocol to copy the file example.txt in the pwd to the remote server at 10.10.0.1 into the directory named "directoryName" with a new file name of "newExample.txt".

You can copy entire directories by using the -r flag..

A few other flags you can use with scp to change the way it behaves are:

  1. -4 Use IPv4 addressing only
  2. -6 Use IPv6 addressing only
  3. -B Batch mode (suppresses additional requests for authentication)
  4. -C Enables compression on the connection
  5. -F Use an alternate ssh config file for connections
  6. -i Specifies an alternate private key file to use for connections
  7. -l (Limit) - Sets connection bandwidth limit in kb/s
  8. -O (Old) - Force older SCP protocol instead of newer SSH SFTP protocol during transfers
  9. -o Pass additional, non-command-line options to ssh
  10. -P Connect on an alternate port number other than 22
  11. -p Preserve all local file metadata on the remote file after copy, including dates and times
  12. -q (Quiet) - don't display file copy progress info in Terminal
  13. -R (Remote) - Force the use of the remote version of scp for copies instead of the local one
  14. -r Recursively copy entire directories instead of just single files
  15. -S Use an alternate SSH program to manage the SSH connection
  16. -v (Verbose) - Print additional info in Terminal for all scp operations

The -O option is provided for use in cases where you are connecting to older SSH servers which don't implement the newer SSH File Transfer Protocol (also part of SSH).

You can use the -o option to pass additional parameters to ssh, which aren't available as command-line options. See the scp man page for more details.

scp local copies

scp works perfectly fine on your local network between different kinds of computers and operating systems. You can connect to and transfer files between two LAN computers just as easily as remote internet computers, assuming both LAN computers are running SSH.

Microsoft inclues SSH in later releases of Windows 10 beginning in 2019. For use with earlier versions of Windows, you may have to install a third-party SSH server on the Windows computer.

But obviously there are easier, and more modern ways to copy files on your Mac such as using the Mac's "Connect to Server" window in the Finder.

For local-only file copies in Terminal, see Manage files in Terminal on Mac in the Mac Terminal User Guide.

Additional resources

You can learn more about SSH at the official SSH website.

Some interesting books on SSH you may want to check out include:

In future articles we'll explore transferring files in Terminal using two more modern networking protocols: SFTP and rsync.

How to use SCP to transfer files in the macOS Terminal | AppleInsider (2024)

FAQs

How do I transfer files using Terminal Mac? ›

In the Terminal app on your Mac, use the mv command to move files or folders from one location to another on the same computer. The mv command moves the file or folder from its old location and puts it in the new location.

Does scp work on Mac? ›

In the Terminal app on your Mac, use the scp command to copy a file or folder to or from a remote computer. scp uses the same underlying protocols as ssh . You're prompted for the user's password.

What is the easiest way to transfer files from Mac to Mac? ›

Open Migration Assistant, which is in the Utilities folder of your Applications folder. Then click Continue. When asked how you want to transfer your information, select the option to transfer to another Mac. Then click Continue.

What is scp command in Terminal? ›

The scp command copies files or directories between a local and a remote system or between two remote systems. You can use this command from a remote system (after logging in with the ssh command) or from the local system. The scp command uses ssh for data transfer.

How do you use scp commands? ›

The in-game console can be opened with the F3 key. Laptops with a Fn key may have to use the Fn + F3 keystroke. Alt + F3 is also a solution. Commands may be entered into the console in the format <command> <parameters> followed by the return or enter key, where multiple parameters are separated by a space.

How do I move a file from one file to another in Terminal? ›

To move a file in a terminal, you use the mv command to move a file from one location to another. In this example, you've moved example. txt from its current folder into the Documents folder.

How do I enable file transfer on Mac? ›

On your Mac, choose Apple menu > System Settings, click General in the sidebar, then click Sharing on the right. (You may need to scroll down.) Turn on File Sharing, then click the Info button on the right.

What is better than scp? ›

SCP provides little functionality other than exactly what its name implies: securely copying files. If you or your users will be managing files, including view/searching directories, creating folders and organizing files, deleting or renaming files, etc., SFTP is the superior protocol.

How do I copy files from local to server on Mac? ›

The general syntax of the scp command is the following.
  1. To copy a file from the local server to the remote one: scp FILENAME user@remote_server:/remote/path/FILENAME.
  2. To copy a file from the remote server to the local one: scp user@remote_server:/remote/path/FILENAME /local/path/FILENAME.

Does scp work in command prompt? ›

It is a secure file transfer protocol that copies files to and from hosts. It uses Secure Shell (SSH) to keep the files protected while in transit. scp is a command line utility, meaning you will have to use Terminal (Mac) or Command Prompt (Windows).

What is the fastest way to transfer files between Mac and PC? ›

Share Mac files with Windows users
  1. On your Mac, choose Apple menu > System Settings, click General in the sidebar, then click Sharing on the right. ...
  2. Turn on File Sharing, then click the Info button on the right.
  3. Click Options.
  4. Select “Share files and folders using SMB.”

How do you transfer all data from a Mac? ›

Open a Finder window, go to Applications, open the Utilities folder, then double-click Migration Assistant and follow the onscreen instructions. Make sure both computers are connected to the same network, and keep the computers near each other throughout the migration process.

How to transfer files from Mac to Mac without Migration Assistant? ›

To use Apple's iCloud Drive service, open a 'Finder' window on your old Mac and select 'Go > iCloud Drive' from the menu bar. You can then drag your files into the window that appears. On your new Mac, make sure you're logged into the same iCloud account, then open the Finder and select 'Go > iCloud Drive.

What is scp example? ›

Common microbes as SCP producers

Bacteria- Methylophilus methylotrophus, Brevibacterium sp., etc. Yeasts- Saccharomyces cerevisiae, Candida utilis etc. Filamentous fungi- Fusarium graminearum, Chaetomium cellulolyticum, etc. Algae- Chlorella, Scenedesmus, etc.

How to use the scp command to copy a file from remote to local? ›

To copy the files you will need to first invoke the SCP, followed by the remote username@IP address, path to file. If you do not specify the path, it is assumed as default in this case which will be the user's home directory, this will be followed the path where the file will be stored locally.

How do I upload files to scp? ›

Upload a file using SFTP or SCP commands
  1. Using your institution's assigned username, enter the following command: sftp [username]@[data center]
  2. Enter your institution's assigned password.
  3. Choose directory (see directory folders): Enter cd [directory name or path]
Oct 28, 2022

How do I copy all files in SCP? ›

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. You'll be prompted for your password on the source system ( deathstar.com ). The command won't work unless you enter the correct password.

What is the access code for SCP? ›

The door to this office will automatically open once the player passes by it unless the door control has been disabled, but it can also be opened with the passcode 1234 .

Which port does SCP use? ›

SCP port runs over TCP port 22 by default, which is also the same default port for SSH. Some system administrators choose to change this port, mainly for security reasons. To choose a different port when using the SCP command, it is necessary to use -P switch followed by the port number selected.

Why can't I transfer files on my Mac? ›

If you can't move or copy a file or folder, you might need to change its permissions settings. You might also need to change permissions settings for the disk, server, or folder where you want to move the item. On your Mac, select the item, then choose File > Get Info, or press Command-I.

How do I move files on Mac without copying or dragging? ›

Move Finder items without dragging

Use the Option key to change the Finder's Paste Item command to Move to Here. (Its keyboard shortcut, Command-Option-V, adds Option to the standard Paste shortcut.)

How do I move files on a Mac without copying? ›

Use a fast keyboard command to move files in Mac OS X

2. Use Option-Command-V to paste it. 3. This will move the file to its new location rather than copying it.

How do I move all files from one folder to another using the command line? ›

To move a file or directory from one location to another, use the command mv. Common useful options for mv include: -i (interactive) — Prompts you if the file you have selected overwrites an existing file in the destination directory.

How do I copy a file from one command line to another? ›

Copying files (cp command)
  1. To make a copy of a file in the current directory, type the following: cp prog.c prog.bak. ...
  2. To copy a file in your current directory into another directory, type the following: cp jones /home/nick/clients.

How do I move a file from one directory to another directly? ›

Locate the file you want to move and right-click said file. From the pop-up menu (Figure 1) select the “Move To” option. When the Select Destination window opens, navigate to the new location for the file. Once you've located the destination folder, click Select.

Why is my file transfer not working? ›

Possible Reasons

File Transfer is disabled on your Android phone or tablet. The USB cable you're using to connect both devices is damaged or malfunctioning. Similarly, it can be an issue with the USB port on your Mac. So, try using another port or change the cable to confirm.

How do I enable file transfer mode? ›

With a USB cable, connect your phone to your computer. On your phone, tap the "Charging this device via USB" notification. Under "Use USB for," select File Transfer. A file transfer window will open on your computer.

How do I transfer files from a Mac to a PC directly? ›

Use Finder to drag-and-drop files and data from your Mac to the external drive. Connect the drive to your PC and launch File Explorer to access the drive. You can now drag or copy your files from the external drive to your PC.

Is SCP still used? ›

The scp protocol is outdated, inflexible and not readily fixed. We recommend the use of more modern protocols like sftp and rsync for file transfer instead.

What is the maximum file size for SCP? ›

Short description. The maximum size for SCPs policy documents is 5,120 bytes. The maximum number of SCPs that can be attached to organizational units (OUs), root, or account is five.

Should I use SCP or SFTP? ›

When comparing SCP vs SFTP in terms of speed, i.e., in transferring files, SCP is generally much faster. This is due to the way it confirms received packets. Traditionally, SFTP has to ACK (acknowledge) every tiny packet, while SCP does not. That's why the disparity becomes more evident in high latency networks.

How to copy files to remote desktop using command line? ›

How to Copy a File from/to a Remote Server
  1. scp username@example.com:/remote/path/to/file /local/path.
  2. scp -r username@example.com:/remote/path/to/directory /local/path.
  3. scp /local/file/path username@example:/remote/path.
  4. scp -r /local/directory/path username@example:/remote/directory/path.

What is the difference between scp and SFTP? ›

Secure File Transfer Protocol (SFTP) uses SSH security components to transfer data recovery files and other sensitive data. It also allows users to choose the mode of authentication as per the need. Secure Copy Protocol (SCP), on the other hand, helps in securely transferring files from localhost to remote hosts.

How do I know if scp is running? ›

Use the command which scp . It lets you know whether the command is available and it's path as well. If scp is not available, nothing is returned. Save this answer.

What does '- J do in Command Prompt? ›

I found the explanation as following: -j Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current path).

Why is transferring files so slow Mac? ›

The slow transfer to USB Mac could be due to the file system. If your drive is FAT/exFAT, then macOS will take more time to read it. You can convert it to APFS, a Mac-exclusive file system that will make your USB drive or external hard disk play maximum performance.

What is the easiest way to transfer all files from one computer to another? ›

5 ways to transfer files from one computer to another
  1. Use external storage media. This is the way most people do it. ...
  2. Share via LAN or Wi-Fi. For computers that are close to each other, there are two main ways to share files and folders. ...
  3. Use a transmission cable. ...
  4. Manually connect HDD or SSD. ...
  5. Use cloud storage or web transfer.
Jun 17, 2022

How do I transfer files from my PC to my Mac via USB? ›

6.1 Via USB Stick

Connect the USB device to any one of the ports of Windows and copy the files into this external storage. Then, unplug it from the PC and plug it in with the macOS. Next, copy the files from the USB to the Mac system.

How do I transfer all files at once? ›

How to send large files
  1. Upload your files to cloud storage. Uploading files to cloud storage is a great way to transfer large files such as photos and video. ...
  2. Compress the Files. Another tried and tested method of transferring files is to compress them. ...
  3. Use a VPN. ...
  4. USB flash drive. ...
  5. FTP. ...
  6. SFTP. ...
  7. FTPS. ...
  8. Jumpshare.
Jan 9, 2023

How do you completely transfer data? ›

  1. Turn on your new device.
  2. Tap Start.
  3. When asked, make sure you connect to a Wi-Fi network.
  4. Choose to copy apps and data from your old device. Recommended: If you have a cable to connect your devices, follow the on-screen instructions to copy your data. ...
  5. Check your texts, photos, and videos.

How do I transfer large files between Macs? ›

9 ways to share files between Macs
  1. File Sharing. The basic way to share files between Macs is to use File Sharing. ...
  2. AirDrop. In the Finder, choose Go > AirDrop on both Macs; the one you want to send files to, and the one you're sending from. ...
  3. Email. ...
  4. Dropbox. ...
  5. iCloud Drive. ...
  6. Other cloud services. ...
  7. BitTorrent Sync. ...
  8. FTP.
Apr 5, 2016

What is the best way to transfer files to new Mac? ›

When you want to move data from an old Mac to a new one, the most reliable method is to use Apple's Migration Assistant. Found in the Utilities folder of your Applications folder, Migration Assistant copies all of your files from your old Mac to your new Mac, so you don't have to transfer them manually.

How do I clone a Mac hard drive? ›

If you do not see the new hard drive, you will need to do the cloning process again. If you do see the new hard drive, click on it.
...
  1. Select your Source Disk (your old hard drive).
  2. Select your Target Disk (your new hard drive).
  3. Under cloning options, select Backup everything.
  4. Just click Clone, and you're done.

How do I use SSH commands on Mac? ›

Log in to your Mac from another computer
  1. On the other computer, open the Terminal app (if it's a Mac) or an SSH client.
  2. Type the ssh command, then press Return. The basic ssh command format is: ssh username@hostname. The hostname can be an IP address or a domain name. ...
  3. Enter your password, then press Return.

How do you use the Inspector tool on a Mac? ›

Use the Inspector in Terminal on Mac
  1. In the Terminal app on your Mac, select a window or tab.
  2. Choose Shell > Show Inspector.
  3. Select a process in the Running Processes list.
  4. Click the Action pop-up menu , then choose a command from Signal Process Group.

How to use SFTP in Mac Terminal? ›

How do I use SSH and SFTP on Mac OS X/macOS?
  1. Select Shell then New Remote Connection... from the top menu.
  2. Under the Server column, click on the + icon to add a new connection.
  3. Enter the hostname when prompted by the dialog.
  4. Enter your username (usually UIC NetID) in the User field and click Connect.
Jan 15, 2021

How do I use putty in Mac Terminal? ›

With MacPorts installed:
  1. Open Terminal on your Mac.
  2. Run this command: sudo port install putty.
  3. This should download and install three programs into /opt/local/bin: putty, puttygen, and puttytel.
  4. /opt/local/bin should be in your PATH, so you should be able to run PuTTY from the command line by typing simply: putty.
Apr 18, 2022

Does Mac Terminal have SSH? ›

MacOS features a built-in SSH client called Terminal which allows you to quickly and easily connect to a server.

How do I copy files from local to remote using scp? ›

To copy the files you will need to first invoke the SCP, followed by the remote username@IP address, path to file. If you do not specify the path, it is assumed as default in this case which will be the user's home directory, this will be followed the path where the file will be stored locally.

How copy file from local to server in terminal? ›

To copy files from a local system to a remote server or remote server to a local system, we can use the command 'scp' . 'scp' stands for 'secure copy' and it is a command used for copying files through the terminal. We can use 'scp' in Linux, Windows, and Mac.

How do I scp an entire directory? ›

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. You'll be prompted for your password on the source system ( deathstar.com ).

How do you make an interrogation mark on a Mac? ›

Basically all you need to do remember is to hold down the OPTION/ALT key when typing the question mark as usual. You can also hold down the Shift key, then press Option/Alt, then hit the / key to type ¿ on the Mac.

How do you reveal answers using inspect? ›

The only way to find answers using the Inspect Element feature is if the website instantly reveals it after submission. In this instance, answers are present in the coding. Otherwise, you're simply viewing the coding for the quiz or test when you use the Inspect Element feature, as well as any answers you submit.

What can I use instead of scp? ›

SFTP is widely considered the successor of SCP. It still runs on top of SSH for transport-layer security and doesn't require setting up access separately. It can give you a custom interactive prompt for exploring the remote filesystem or you can script with a pre-written series of commands.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Neely Ledner

Last Updated:

Views: 5812

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.