Doing a sudo to a remote server in Emacs to open/save a file

When trying to open a file as root in emacs with tramp using

/sudo:myserver:...

I see the following error:

Debugger entered--Lisp error: (file-error "Host `myserver' looks like a remote host, `sudo' can only use the local host")

Well, there is a way to tell Emacs to get to that server and open the file with a sudo. Add this to the .emacs file:

(add-to-list 'tramp-default-proxies-alist '(".*" "\`root\'" "/ssh:%h:"))

Restart Emacs and /sudo will start working on remote sites.

This only seems to work in Cygwin Emacs. I tried in Ubuntu and got:

tramp-compute-multi-hops: Host `solomonson.com' looks like a remote host, `sudo' can only use the local host

After much experimentation, I found that this works on Ubuntu:

(set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:"))))
Your rating: None Average: 4 (1 vote)