The diff command line utility compares contents of two files (or directories), and shows how they differ line by line. It's straightforward to use diff if both input files are located on local host. But what if input files located on two different hosts? You can actually diff remote files over ssh. Here is how.
The diff utility can take one operand in the form of stdin (represented by "-"), and you can leverage this feature to diff over ssh.
The above command line will prompt you for a ssh password to the remote host. Once you enter the password correctly, the command will read the content of a remote file via ssh, and then pipe it into diff utility for comparison with a local file.
Another method for doing diff over ssh is to use input redirection explicitly. In order to use this second method, you need to first enable password-less ssh login to remote host(s). Assuming that is the case, you can do the following.
To diff a local file and a remote file:
To diff two remote files:
These commands will fail if the remote hosts require you to enter ssh password for access.
Subscribe to Xmodulo
You can have daily Linux tutorials and FAQs delivered to your email inbox. Simply enter your email address below to subscribe to our mailing list. You will receive hands-on guides and carefully written tutorials related to Linux, everything for free.