Sling Academy
Home/DevOps/How to Stream Files Between Two Ubuntu Machines

How to Stream Files Between Two Ubuntu Machines

Last updated: January 29, 2024

Introduction

Streaming files between two Ubuntu machines can be a crucial task for system administrators, developers, and even general users who want to share files without the need for physical storage devices or cloud services. This comprehensive guide will delve into seamless methods for streaming files directly between two Linux-based systems.

Prerequisites

Before getting started, make sure you have the following preparation:

  • Two Ubuntu machines connected to the same network
  • OpenSSH server installed on the host machine
  • Basic knowledge of the command line and networking concepts

Setting Up SSH

Secure Shell (SSH) is a network protocol that allows secure access to another computer over a network. It is the backbone of our file streaming setup.

Install OpenSSH:

sudo apt update && sudo apt install openssh-server

Once installed, verify the SSH server status:

sudo systemctl status ssh

If it is not running, start it with:

sudo systemctl start ssh

SSH Key Authentication

To streamline the authentication process, use SSH keys. Generate a new SSH key pair on the client machine:

ssh-keygen -t rsa -b 4096

Then, transfer the public key to the host, ensuring password-less login:

ssh-copy-id user@hostmachineIP

Streaming Files Using SCP

The secure copy protocol (SCP) allows files to be copied to, from, or between different machines.

Copy a file from the client to the host:

scp /path/to/source/file user@hostmachineIP:/path/to/destination

To copy a directory and its contents, use the recursive option:

scp -r /path/to/source/directory user@hostmachineIP:/path/to/destination

Streaming Using rsync

The rsync command is a more flexible tool for file streaming, allowing synchronization of files and directories.

Example of streaming files with rsync:

rsync -avz /path/to/source/ user@hostmachineIP:/path/to/destination

The -avz flags archive (preserves permissions), verbose (shows progress), and compress (compresses data during transfer) the files, respectively.

NFS Mounts

Network File System (NFS) is a distributed filesystem protocol that allows a user on a client machine to access files over a network.

On the host, install NFS kernel server:

sudo apt install nfs-kernel-server

Edit /etc/exports to share the directory:

/path/to/shared/directory clientmachineIP(rw,sync,no_subtree_check)

Apply the changes:

sudo exportfs -a

Using Netcat for Large Files

Netcat can be used to send any size of file over the network directly. On the receiving machine, use the following command to listen for the file:

nc -l -p 12345 > destination_file

On the sending machine:

nc hostmachineIP 12345 < source_file

Conclusion

This guide provided solutions to stream files between two Ubuntu machines using different tools. Each method has its use-case; whether confidentiality, transfer speed, or handiness is the priority. Make sure to choose the one that fits your needs closely.

Next Article: Ubuntu: How to add a new PATH entry

Previous Article: Ubuntu: How to add a DNS server (5 approaches)

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide