I found this website with a bunch of ssh
tricks. Some highlights:
Compare a Remote File with a Local File
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -Useful for checking if there are differences between local and remote files.
opendiff
((Part of the Developer Tools installed with Xcode)) and bbdiff
((One of the tools installed by BBEdit)) do not use stdin
for their input, but you can work around that by copying the file to /tmp
first:
scp user@host:/path/to/remotefile /tmp/remotefile && opendiff /path/to/localfile /tmp/remotefile
SSH Connection through host in the middle
ssh -t reachable_host ssh unreachable_hostUnreachable_host is unavailable from local network, but it’s available from reachable_host’s network. This command creates a connection to unreachable_host through “hidden” connection to reachable_host.
Using the -t
option uses less overhead on the intermediate host. Same trick is used later in the article where you directly attach to a remote screen
session:
ssh -t remote_host screen -r
Though I prefer using screen -DR
. Read the man page for details.
The next one however didn’t do anything for me, I suspect there is a piece missing in the command somewhere:
Remove a line in a text File
sed -i 8d ~/.ssh/known_hosts
However there is a dedicated tool for this: use
ssh-keygen -R host
instead. I re-image some machines over and over again and then run into the ssh host key errors. This is very useful.