Lesson  in  Test Linux for DevOps Engineers

Remote Access and File Transfer

Learn how to securely log in to remote Linux servers using SSH and transfer files between systems using SCP.

🎯 Learning Objective

By the end of this unit, you'll master secure remote server access using SSH and efficient file transfers with SCP, essential skills for managing distributed infrastructure, deploying applications, and troubleshooting production systems in DevOps environments.

📚 Concept Introduction

Remote server management is fundamental to DevOps operations. Modern infrastructure spans multiple servers, cloud instances, and containerized environments that require secure, reliable remote access.

Production scenarios requiring SSH expertise include managing web servers, deploying applications to staging and production environments, troubleshooting service outages, configuring CI/CD runners, collecting logs and diagnostics, and executing maintenance scripts across server fleets. These skills form the backbone of effective infrastructure management.

📁 Pre-created:

  • Two-node environment (node-01 and node-02) with passwordless SSH configured
  • data.txt - File for SCP transfer task
  • example-config.txt - Sample configuration file for demonstrations
  • deploy-script.sh - Executable script for deployment examples
  • nginx-backup.conf - Configuration backup file for examples
  • example-app/ - Directory with sample application files
  • SSH keys pre-configured for seamless authentication

🔐 Secure Shell (SSH) for Production Server Management

◆ Understanding SSH in DevOps Context

SSH (Secure Shell) provides encrypted, authenticated connections to remote Linux systems, enabling secure command execution and file transfers over untrusted networks. In production environments, SSH is the primary method for server administration, deployment automation, and emergency response.

SSH security benefits critical for production:

  • Encryption - All communication is encrypted, protecting against network eavesdropping
  • Authentication - Cryptographic keys prevent unauthorized access
  • Integrity - Data tampering is detected and prevented
  • Auditing - Connection attempts and commands can be logged for compliance

Basic SSH connection syntax:

ssh [username]@[hostname_or_ip]

Basic remote connection:

ssh laborant@node-02

◆ First-Time Connection Process

When you run the SSH command for the first time, you'll see a security prompt:

The authenticity of host 'node-02 (IP_ADDRESS)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type yes and press Enter to accept the host key. This fingerprint will be saved to ~/.ssh/known_hosts for future connections.

After accepting the host key, you'll be connected to node-02. Your command prompt will change to show you're now on the remote server.

Returning to your original system:

exit

This closes the SSH connection and returns you to node-01.

◆ Production SSH Authentication Methods

While our lab uses passwordless SSH for convenience, production environments typically use more secure authentication:

SSH Key Authentication (Production Standard):

ssh -i ~/.ssh/id_ed25519 laborant@node-02

Production SSH key management:

  • Key rotation - Regular key updates for security compliance
  • Role-based access - Different keys for different server access levels

The -i option specifies which private key to use when you have multiple keys for different environments or access levels.

📂 Secure File Transfer with SCP

◆ Understanding SCP in DevOps Context

SCP (Secure Copy Protocol) transfers files securely between systems using SSH encryption and authentication. In production environments, SCP is essential for deploying configuration files, transferring application artifacts, collecting log files, and distributing scripts across server infrastructure.

Critical DevOps use cases:

  • Application deployment - Transfer compiled applications and configuration files to production servers
  • Log collection - Retrieve log files from remote servers for analysis and troubleshooting
  • Configuration management - Deploy updated configuration files across multiple environments
  • Backup operations - Transfer backup files to remote storage systems
  • Script distribution - Deploy automation scripts to CI/CD runners and production systems

◆ How SCP Builds on SSH

Since you have SSH access to node-02, SCP automatically uses the same authentication and security. Think of SCP as "SSH for files" - same connection, same security, but for file transfers instead of interactive access.

If you can ssh laborant@node-02, you can also use scp to transfer files to that server.

◆ Basic File Transfer Syntax

Local to remote:

scp /local/file user@remote:/remote/path/

Remote to local:

scp user@remote:/remote/file /local/path/

Example:

scp /home/laborant/example-config.txt laborant@node-02:/tmp/deployed-config.txt

Transfer direction: sourcedestination. Always identify where the file is now (source) and where you want it (destination).

◆ Directory Transfer with -r

For entire application deployments, you need to transfer directories containing multiple files and subdirectories.

Directory transfer syntax:

scp -r /local/directory/ user@remote:/remote/path/

Example:

scp -r /home/laborant/example-app/ laborant@node-02:/tmp/deployed-app/

The -r flag: Transfers the directory and all its contents while maintaining file structure and permissions.

◆ Using Specific SSH Keys

Production environments use specific SSH keys for different servers or roles for security isolation.

SSH key syntax:

scp -i /path/to/key /local/file user@remote:/remote/path/

Example:

scp -i ~/.ssh/id_rsa /home/laborant/example-config.txt laborant@node-02:/tmp/secure-config.txt

Purpose: Enables role-based access control and environment separation.

◆ Remote Command Execution

Run single commands on remote servers without maintaining persistent connections - essential for automation and monitoring.

Remote command syntax:

ssh user@remote "command"

Example:

ssh laborant@node-02 "uptime"

Process: SSH connects, executes the command, returns output, and automatically closes the connection.

📋 Essential Command Reference

CommandPurposeDevOps Use Case
ssh user@hostInteractive remote loginServer maintenance, troubleshooting
ssh user@host "command"Execute remote commandAutomation, monitoring, quick checks
scp file user@host:/path/Upload file to remote serverDeploy configurations, transfer artifacts
scp -r dir/ user@host:/path/Upload directory recursivelyDeploy applications, transfer bulk files
scp -i keyfile file user@host:/path/Use specific SSH keyRole-based access, environment separation
exitClose SSH sessionReturn to local system safely

💡 Key Takeaways

  • SSH and SCP use the same security model - if you can SSH to a server, you can transfer files to it
  • Always understand transfer direction: identify source → destination before running commands
  • Use -r for directory transfers to maintain file structure and permissions
  • Remote command execution provides quick information without interactive sessions
  • Production environments use specific SSH keys (-i) for role-based access and security isolation
  • These tools form the foundation for secure DevOps file management and remote operations

Understanding these concepts enables systematic file transfers and remote operations rather than memorizing commands.