How do I check if a config file differs between two servers?

Quick Linux Tip #49:

Try: diff <(ssh linuxteck@server1 cat /etc/nginx/nginx.conf) <(ssh linuxteck@server2 cat /etc/nginx/nginx.conf)

Info: Process substitution <() combined with SSH pipes file contents directly to diff. No temp files needed. Great for verifying config parity across servers.

Examples:

  • $ diff <(ssh s1 'rpm -qa | sort') <(ssh s2 'rpm -qa | sort')
  • $ diff <(ssh s1 'systemctl list-units --state=running') <(ssh s2 'systemctl list-units --state=running')
  • $ colordiff <(ssh s1 cat /etc/hosts) <(ssh s2 cat /etc/hosts)

Note: Requires SSH key authentication to avoid password prompts. Use with ControlMaster (Tip #16) for speed. colordiff makes the output much easier to read.




LinuxTeck.com
linuxteck@ubuntu:~$ diff <(ssh server1 cat /etc/nginx/nginx.conf) <(ssh server2 cat /etc/nginx/nginx.conf)
23c23
<   worker_processes auto;
---
>   worker_processes 4;
45c45
<   keepalive_timeout 65;
---
>   keepalive_timeout 120;
67a68,70
>
>   # Rate limiting added on server2
>   limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #48: How do I quickly share files across my network without setting up nginx?
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.