Skip to content

Linux Level 1, Task 12: Secure File Transfer Between Servers with scp

Today's task was a fundamental system administration duty that is performed countless times every day in a real-world environment: securely copying a file from one server to another. My objective was to move a sensitive file from the jump host to a specific directory on an application server.

I learned how to use the scp (Secure Copy) command, which leverages the security of SSH to transfer data. This document is my first-person guide to that simple but essential process.

The Task

My objective was to copy a file from the jump host to App Server 1. The specific requirements were: - The source file was /tmp/nautilus.txt.gpg on the jump host. - The destination was the /home/nfsshare directory on App Server 1.

My Step-by-Step Solution

  1. Identify Details: From the jump host, I first made sure I knew the connection details for the destination server (user: tony, host: stapp01).

  2. Execute the Copy Command: I used a single scp command to perform the transfer.

    scp /tmp/nautilus.txt.gpg tony@stapp01:/home/nfsshare
    
    I was prompted for the tony user's password, and after entering it, the file was transferred.

  3. Verification: The crucial final step was to confirm the file had arrived at its destination. I ran a remote command via SSH from the jump host to check.

    ssh tony@stapp01 "ls -l /home/nfsshare/nautilus.txt.gpg"
    
    The command successfully listed the file's details on the remote server, which was the definitive proof that my task was successful.

Key Concepts (The "What & Why")

  • scp (Secure Copy): This is the standard, secure way to transfer files between two Linux servers. It is part of the SSH suite of tools and uses the same authentication and encryption as a regular SSH login. This ensures that the data is protected while in transit.
  • Why scp? In any real infrastructure, servers have specialized roles (jump hosts for access, app servers for applications, etc.). scp is the essential utility for moving files between them. Common use cases include:
    • Deploying application code from a build server to an app server.
    • Copying configuration files from a central management server.
    • Retrieving log files from an app server for analysis.
    • Moving database backups from a DB server to a backup server.
  • The scp Syntax: The command structure is scp [SOURCE] [DESTINATION]. The key is that for a remote location, the syntax is user@host:/path/to/directory. The colon : is the critical separator between the host information and the file path on that host.

Commands I Used

  • scp /tmp/nautilus.txt.gpg tony@stapp01:/home/nfsshare: The main command for this task.
    • scp: The Secure Copy utility.
    • /tmp/nautilus.txt.gpg: The local source file path.
    • tony@stapp01:/home/nfsshare: The remote destination, specifying the user, host, and target directory.
  • ssh tony@stapp01 "ls -l /home/nfsshare/nautilus.txt.gpg": My verification command. This is a very efficient way to check a remote server without needing to open a full interactive session. It connects, runs the single command in quotes, prints the output, and disconnects.