A Few TRAMP tricks

Like many Emacs users, I’m a big fan of Dired and its cousin, TRAMP. For remote work like the one discussed here, there are two crucial tricks I want to share today.

When I was away on a vacation, I had the chance to test my new Synology setup. I should probably expand on the modification I’ve implemented in another post1, but for now, I’ll say I turned on access via SSH and creation of a home folder for users, which in turn allows SSH-keys usage.

First, you want to have Emac’s DWIM (do as I mean) turned on with dired-dwim-target t. With two windows open, one on your local machine and one on the remote (which you should use bookmarks with), DIRED will direct your copy and rename commands to the other window as a target. When I wanted to copy photos from my laptop to my Synology at home, I navigated to the Desktop on my local machine, marked the files, and then renamed them in TRAMP: R. The other window was open in my Synology’s photo’s folder, so the rename command automatically populated the remote path - ssh, user, IP address, and path - to reflect the other window. This is a big time save.

Second, speaking of time saves, don’t use SSH with DIRED. use SCP. Instead of connecting with /ssh:<username>@<IP>#<port>:/<[path>/, use /scp:<username>@<IP>#<port>:/<[path>/. TRAMP is smart enough to use ssh when connecting and when viewing a directory, but it will use scp to copy files instead of the built-in method which is much slower. You won’t get a progress bar as you do in shell running scp directly, but TRAMP is copying files this way is much faster. I was able to download a movie clip that was over a gig from home in seconds over WiFi. You won’t feel a difference otherwise in TRAMP’s functions.

Oh, and since I mentioned bookmarks above: these works great in TRAMP. Connect to your remote host once (using the scp command as described above), then navigate to the directory you want to connect to next time, and bookmark it with C-x r m. Next time, just bring the list up with C-x r l. It’s also easy to change or add another directory this way: Just hit R (that’s capital R) to rename the location; you can just modify the path or mark it, kill it (“copy” it), and then create a new bookmark, yank (“paste), and modify lightly. Sure beats typing the path with the port and user name in shell every time.

Footnotes


  1. A few more things I want to mention are mounting encrypted volumes through SSH and hardening the Synology overall. I find its default access via a URL registered Synology website cringe-worthy. When on, an attacker just needs to guess what I called my server and he has access to the interface. ↩︎


Comments