How to Use the croc Command in Linux for Secure Peer-to-Peer File Transfers

Sending files between two computers across different networks or firewalls often involves uploading to cloud storage, configuring temporary FTP servers, or opening port forwarding on home routers. These workarounds are cumbersome and expose private data to third-party servers. croc is a lightweight command-line tool written in Go that enables direct, encrypted peer-to-peer file transfers between any two machines using a simple, human-readable codephrase.

Key Advantages of croc

Unlike standard file transfer tools like scp, rsync, or web uploaders, croc solves common networking bottlenecks:

  • End-to-End Encryption: Implements Password Authenticated Key Exchange (PAKE) with P-256 elliptic curve encryption, ensuring that even intermediate relay servers cannot read file contents.
  • NAT and Firewall Traversal: Uses relay servers to negotiate direct TCP hole-punching, enabling transfers between two machines behind strict domestic or corporate NAT firewalls.
  • Resume Interrupted Transfers: Automatically resumes failed or interrupted downloads without restarting from zero bytes.
  • Cross-Platform Compatibility: Seamlessly transfers files, folders, and text clips between Linux, macOS, Windows, and FreeBSD systems.

Installing croc on Linux

The croc binary can be installed via package managers or automated install scripts:

  • Universal Install Script:
    curl https://getcroc.schollz.com | bash
  • Ubuntu and Debian (via Apt):
    sudo apt install croc
  • Arch Linux and Manjaro:
    sudo pacman -S croc
  • Homebrew on Linux:
    brew install croc
  • Go Package Manager:
    go install github.com/schollz/croc/v9@latest

Sending and Receiving Files with croc

Transferring files requires just one command on each computer:

Step 1: Sending a File or Folder

On the sending machine, specify the file or directory you wish to transmit:

croc send archive.tar.gz

To send multiple files or an entire folder, pass them in the same command:

croc send document.pdf photos_folder/

croc generates a random, human-memorable codephrase (for example, 7429-bravo-whiskey-echo) and displays instructions for the receiver.

Step 2: Receiving the File

On the receiving computer, run croc followed by the generated codephrase:

croc 7429-bravo-whiskey-echo

The receiver’s terminal displays the file name, size, and sender details, prompting for confirmation: “Receive ‘archive.tar.gz’ (420 MB)? (y/n)”. Press y and press Enter. The transfer completes with a real-time progress bar and hash verification.

Advanced Usage: Custom Codephrases and Local Only Transfers

You can customise croc for automated scripts and faster local networking:

  • Custom Passphrases: To define your own codephrase instead of generating a random one, use the --code flag:
    croc send --code secret-backup-key dataset.csv
  • Local Network Transfer (Bypass Relays): If both computers are connected to the same local Wi-Fi or LAN, add the --local flag to transfer directly across the subnet at maximum network speeds:
    croc --local send virtual_disk.iso
  • Sending Text Messages or API Tokens: To send an encrypted string or password directly to someone’s clipboard without creating a text file:
    croc send --text "super-secret-production-token"

Hosting a Private Relay for Maximum Security

While the default public relay operated by the developer is encrypted via PAKE, enterprise environments or privacy-conscious administrators can host their own private relay container:

croc relay

Clients can then route all encrypted traffic through the self-hosted server using the --relay flag, guaranteeing full control over transfer infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.