A very useful TRAMP.

The TRAMP that I am refer­ring to is the Trans­par­ent Remote Access Mul­ti­ple Pro­to­col mod­ule for emacs, my favorite edi­tor. Using TRAMP I can edit files remotely from within emacs using either smb, ftp, rsync, sftp, scp, rsh, rcp or ssh as trans­port protocols.

Now, the abil­ity to edit files remotely is noth­ing new or rev­o­lu­tion­ary but TRAMP has some very neat tricks up it’s sleeve. Besides the abil­ity to use ssh to securely con­nect to remote servers, it also sup­ports the use of su and sudo. Imag­ine that you would like to edit some file in /etc/ that was owned by root but root login was dis­abled in your ssh con­fig­u­ra­tion. Log­ging in using your nor­mal user wouldn’t help you much and you would have to either allow root logins via ssh or log on to the server in ques­tion, su to root and then edit the file. Or you could use TRAMP :)

TRAMP has the abil­ity to use mul­ti­ple hops to achieve a con­nec­tion — that means that it’s pos­si­ble to log on to a server as your nor­mal user and then have TRAMP exe­cute su or sudo on the remote machine for you. It’s actu­ally pretty sim­ple — here is the rel­e­vant sec­tion from my .emacs file :

;; TRAMP stuff
(require ‘tramp )
(setq tramp-default-method “ssh”)
(add-to-list ‘tramp-default-proxies-alist ‘(“\.myunix\.dk\’” “\‘root\’” “/ssh:%h:”))
(add-to-list ‘tramp-default-proxies-alist ‘(“\.example\.com\’” “\‘root\’” “/ssh:%h:”))
(setq tramp-auto-save-directory “~/.emacs.d/tramp-autosave”)

Now if I try to open the file /su:example@example.com:/etc/hosts emacs would first prompt me for the pass­word for user “exam­ple” and upon a suc­cess­ful con­nec­tion prompt me for the root pass­word of the machine in ques­tion. If all goes well then emacs reads the con­tent of /etc/hosts into the buffer.

TRAMP also sup­port the chain­ing of hosts in the same man­ner. Very use­ful for access­ing hosts that are only reach­able from cer­tain machines, such as gate­ways or bas­tion hosts.

Since the remote file resides in a nor­mal emacs buffer you can work on it like any other local file.

I really like the fact that I can edit files securely on remote machines with­out ever leav­ing the com­fort of trusty old emacs.

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *