Study Notes on Secure Copy Protocol (SCP) and SFTP

Introduction to Secure Copy Protocol (SCP)

  • SCP is a command used for securely copying files over a network.

  • It is part of the SSH (Secure Shell) suite, which ensures secure data transfer.

  • SCP requires that SSH is enabled on the target server to operate.

Basic SCP Command Structure

  • The general syntax for using SCP is as follows:

    • scp [source file(s)] [user]@[remote server]:[destination path]

    • Example: scp file1 file2 student@remote_server:/home/student

    • This command copies file1 and file2 to the specified path on the remote server as the user student.

Recursive Copying with SCP

  • To copy entire directories, the -r option is used:

    • Syntax: scp -r [user]@[remote server]:[source directory] [destination path]

    • Example: scp -r root@remote_server:/tmp/files_to .

    • This command copies the entire contents of the directory TMP/files_to from the remote server as the user root.

Secure File Transfer using SFTP

  • SFTP (SSH File Transfer Protocol) can also be used for transferring files securely.

  • Example process for using SFTP to transfer a file:

    1. Initiate the SFTP session using:

    • sftp file3 student@192.168.29.143:/dmb/

    • This command attempts to connect to the remote server using SFTP to copy file3.

    1. Upon connection, a prompt will display requesting verification of the remote host's identity. Type yes to proceed.

    2. Enter the appropriate password for authentication.

    3. After successful login, the file transfer takes place.

Conclusion

  • SCP and SFTP are powerful tools in the SSH toolkit designed to facilitate secure file transfer over potentially insecure networks.

  • Ensure that SSH is enabled on the target server for functionality.

  • Use SCP for straightforward file copying and SFTP for a more interactive file transfer experience with directory support.