Use scp to securely copy files remotely over SSH

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 4 years ago

Learn how to copy files to and from remote server hosts with the scp command. You will also learn how to specify a different port and identity file when secure copying files.

Instructor: [00:01] The scp or secure copy command is very similar to the cp or copy command. It allows you to copy files to and from a remote host.

[00:11] Start by echoing foo to a file named bar.txt. To use the secure copy command to copy the file to the remote host, type scp followed by the file you wish to copy, in this case bar.txt. Then specify your username @remotehost connection string, and suffix it with a colon.

[00:32] After the colon is where to tell scp where to copy the file to on the remote host. In this case, copy it to the home directory. By default, scp will use your default SSH key to connect to the remote host. To specify a different SSH key or identity, use the -i flag followed by the location of your SSH private key.

[00:56] If the remote SSH server is bound to a port other than the default port 22, you can specify a -P flag, followed by the port number, in this case 2022. You can also copy entire folders recursively with the -r flag.

[01:13] Let's make a foo folder, then create a bar.txt file within the foo folder. We can then recursively copy the entire foo folder with the -r command. To copy a file or a folder from a remote host back to the local host machine, specify the remote connection string first followed by a colon, and then the location of the file or folder on the remote host you wish to copy.

[01:40] The second parameter is where on our local host machine you wish to copy the file to, with ./ being the current directory and a new file name if you wish.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today